def docx_table_is_converted_to_table_in_html():
    table = documents.table(
        [
            documents.table_row(
                [
                    documents.table_cell([_paragraph_with_text("Top left")]),
                    documents.table_cell([_paragraph_with_text("Top right")]),
                ]
            ),
            documents.table_row(
                [
                    documents.table_cell([_paragraph_with_text("Bottom left")]),
                    documents.table_cell([_paragraph_with_text("Bottom right")]),
                ]
            ),
        ]
    )
    result = convert_document_element_to_html(table)
    expected_html = (
        "<table>"
        + "<tr><td><p>Top left</p></td><td><p>Top right</p></td></tr>"
        + "<tr><td><p>Bottom left</p></td><td><p>Bottom right</p></td></tr>"
        + "</table>"
    )
    assert_equal(expected_html, result.value)
Beispiel #2
0
 def vmerge_accounts_for_cells_spanning_columns(self):
     element = xml_element("w:tbl", {}, [
         w_tr(w_tc(), w_tc(), w_tc(properties=[w_vmerge("restart")])),
         w_tr(w_tc(properties=[w_gridspan("2")]),
              w_tc(properties=[w_vmerge("continue")])),
         w_tr(w_tc(), w_tc(), w_tc(properties=[w_vmerge("continue")])),
         w_tr(w_tc(), w_tc(), w_tc()),
     ])
     result = _read_and_get_document_xml_element(element)
     expected_result = documents.table([
         documents.table_row([
             documents.table_cell([]),
             documents.table_cell([]),
             documents.table_cell([], rowspan=3)
         ]),
         documents.table_row([documents.table_cell([], colspan=2)]),
         documents.table_row(
             [documents.table_cell([]),
              documents.table_cell([])]),
         documents.table_row([
             documents.table_cell([]),
             documents.table_cell([]),
             documents.table_cell([])
         ]),
     ])
     assert_equal(expected_result, result)
 def no_vertical_cell_merging_if_merged_cells_do_not_line_up(self):
     element = xml_element("w:tbl", {}, [
         w_tr(w_tc(properties=[w_gridspan("2")]), w_tc(properties=[w_vmerge("restart")])),
         w_tr(w_tc(), w_tc(properties=[w_vmerge("continue")])),
     ])
     result = _read_and_get_document_xml_element(element)
     expected_result = documents.table([
         documents.table_row([documents.table_cell([], colspan=2), documents.table_cell([])]),
         documents.table_row([documents.table_cell([]), documents.table_cell([])]),
     ])
     assert_equal(expected_result, result)
def header_rows_are_wrapped_in_thead():
    table = documents.table([
        documents.table_row([documents.table_cell([])], is_header=True),
        documents.table_row([documents.table_cell([])], is_header=True),
        documents.table_row([documents.table_cell([])], is_header=False),
    ])
    result = convert_document_element_to_html(table)
    expected_html = ("<table>" +
                     "<thead><tr><th></th></tr><tr><th></th></tr></thead>" +
                     "<tbody><tr><td></td></tr></tbody>" + "</table>")
    assert_equal(expected_html, result.value)
Beispiel #5
0
 def no_vertical_cell_merging_if_merged_cells_do_not_line_up(self):
     element = xml_element("w:tbl", {}, [
         w_tr(w_tc(properties=[w_gridspan("2")]), w_tc(properties=[w_vmerge("restart")])),
         w_tr(w_tc(), w_tc(properties=[w_vmerge("continue")])),
     ])
     result = _read_and_get_document_xml_element(element)
     expected_result = documents.table([
         documents.table_row([documents.table_cell([], colspan=2), documents.table_cell([])]),
         documents.table_row([documents.table_cell([]), documents.table_cell([])]),
     ])
     assert_equal(expected_result, result)
def empty_cells_are_preserved_in_table():
    table = documents.table([
        documents.table_row([
            documents.table_cell([_paragraph_with_text("")]),
            documents.table_cell([_paragraph_with_text("Top right")]),
        ]),
    ])
    result = convert_document_element_to_html(table)
    expected_html = ("<table>" +
                     "<tr><td></td><td><p>Top right</p></td></tr>" +
                     "</table>")
    assert_equal(expected_html, result.value)
def header_rows_are_wrapped_in_thead():
    table = documents.table([
        documents.table_row([documents.table_cell([])], is_header=True),
        documents.table_row([documents.table_cell([])], is_header=True),
        documents.table_row([documents.table_cell([])], is_header=False),
    ])
    result = convert_document_element_to_html(table)
    expected_html = (
        "<table>" +
        "<thead><tr><th></th></tr><tr><th></th></tr></thead>" +
        "<tbody><tr><td></td></tr></tbody>" +
        "</table>")
    assert_equal(expected_html, result.value)
def empty_cells_are_preserved_in_table():
    table = documents.table([
        documents.table_row([
            documents.table_cell([_paragraph_with_text("")]),
            documents.table_cell([_paragraph_with_text("Top right")]),
        ]),
    ])
    result = convert_document_element_to_html(table)
    expected_html = (
        "<table>" +
        "<tr><td></td><td><p>Top right</p></td></tr>" +
        "</table>")
    assert_equal(expected_html, result.value)
def table_cells_are_written_with_colspan_if_not_equal_to_one():
    table = documents.table([
        documents.table_row([
            documents.table_cell([_paragraph_with_text("Top left")], colspan=2),
            documents.table_cell([_paragraph_with_text("Top right")]),
        ]),
    ])
    result = convert_document_element_to_html(table)
    expected_html = (
        "<table>" +
        "<tr><td colspan=\"2\"><p>Top left</p></td><td><p>Top right</p></td></tr>" +
        "</table>")
    assert_equal(expected_html, result.value)
def table_cells_are_written_with_colspan_if_not_equal_to_one():
    table = documents.table([
        documents.table_row([
            documents.table_cell([_paragraph_with_text("Top left")], colspan=2),
            documents.table_cell([_paragraph_with_text("Top right")]),
        ]),
    ])
    result = convert_document_element_to_html(table)
    expected_html = (
        "<table>" +
        "<tr><td colspan=\"2\"><p>Top left</p></td><td><p>Top right</p></td></tr>" +
        "</table>")
    assert_equal(expected_html, result.value)
 def word_table_is_read_as_document_table_element(self):
     element = xml_element(
         "w:tbl", {}, [xml_element("w:tr", {}, [xml_element("w:tc", {}, [xml_element("w:p", {}, [])])])]
     )
     table = _read_and_get_document_xml_element(element)
     expected_result = documents.table([documents.table_row([documents.table_cell([documents.paragraph([])])])])
     assert_equal(expected_result, table)
Beispiel #12
0
 def vmerge_is_read_as_rowspan_for_table_cell(self):
     element = xml_element("w:tbl", {}, [
         w_tr(w_tc()),
         w_tr(w_tc(properties=[w_vmerge("restart")])),
         w_tr(w_tc(properties=[w_vmerge("continue")])),
         w_tr(w_tc(properties=[w_vmerge("continue")])),
         w_tr(w_tc())
     ])
     result = _read_and_get_document_xml_element(element)
     expected_result = documents.table([
         documents.table_row([documents.table_cell([])]),
         documents.table_row([documents.table_cell([], rowspan=3)]),
         documents.table_row([]),
         documents.table_row([]),
         documents.table_row([documents.table_cell([])]),
     ])
     assert_equal(expected_result, result)
 def vmerge_is_read_as_rowspan_for_table_cell(self):
     element = xml_element("w:tbl", {}, [
         w_tr(w_tc()),
         w_tr(w_tc(properties=[w_vmerge("restart")])),
         w_tr(w_tc(properties=[w_vmerge("continue")])),
         w_tr(w_tc(properties=[w_vmerge("continue")])),
         w_tr(w_tc())
     ])
     result = _read_and_get_document_xml_element(element)
     expected_result = documents.table([
         documents.table_row([documents.table_cell([])]),
         documents.table_row([documents.table_cell([], rowspan=3)]),
         documents.table_row([]),
         documents.table_row([]),
         documents.table_row([documents.table_cell([])]),
     ])
     assert_equal(expected_result, result)
def tbody_is_omitted_if_all_rows_are_headers():
    table = documents.table([
        documents.table_row([documents.table_cell([])], is_header=True),
    ])
    result = convert_document_element_to_html(table)
    expected_html = ("<table>" + "<thead><tr><th></th></tr></thead>" +
                     "</table>")
    assert_equal(expected_html, result.value)
def docx_table_is_converted_to_table_in_html():
    table = documents.table([
        documents.table_row([
            documents.table_cell([_paragraph_with_text("Top left")]),
            documents.table_cell([_paragraph_with_text("Top right")]),
        ]),
        documents.table_row([
            documents.table_cell([_paragraph_with_text("Bottom left")]),
            documents.table_cell([_paragraph_with_text("Bottom right")]),
        ]),
    ])
    result = convert_document_element_to_html(table)
    expected_html = (
        "<table>" +
        "<tr><td><p>Top left</p></td><td><p>Top right</p></td></tr>" +
        "<tr><td><p>Bottom left</p></td><td><p>Bottom right</p></td></tr>" +
        "</table>")
    assert_equal(expected_html, result.value)
 def vmerge_accounts_for_cells_spanning_columns(self):
     element = xml_element("w:tbl", {}, [
         w_tr(w_tc(), w_tc(), w_tc(properties=[w_vmerge("restart")])),
         w_tr(w_tc(properties=[w_gridspan("2")]), w_tc(properties=[w_vmerge("continue")])),
         w_tr(w_tc(), w_tc(), w_tc(properties=[w_vmerge("continue")])),
         w_tr(w_tc(), w_tc(), w_tc()),
     ])
     result = _read_and_get_document_xml_element(element)
     expected_result = documents.table([
         documents.table_row([documents.table_cell([]), documents.table_cell([]), documents.table_cell([], rowspan=3)]),
         documents.table_row([documents.table_cell([], colspan=2)]),
         documents.table_row([documents.table_cell([]), documents.table_cell([])]),
         documents.table_row([documents.table_cell([]), documents.table_cell([]), documents.table_cell([])]),
     ])
     assert_equal(expected_result, result)
def table_cells_are_written_with_rowspan_if_not_equal_to_one():
    table = documents.table([
        documents.table_row([
            documents.table_cell([], rowspan=2),
        ]),
    ])
    result = convert_document_element_to_html(table)
    expected_html = ("<table>" + "<tr><td rowspan=\"2\"></td></tr>" +
                     "</table>")
    assert_equal(expected_html, result.value)
def tbody_is_omitted_if_all_rows_are_headers():
    table = documents.table([
        documents.table_row([documents.table_cell([])], is_header=True),
    ])
    result = convert_document_element_to_html(table)
    expected_html = (
        "<table>" +
        "<thead><tr><th></th></tr></thead>" +
        "</table>")
    assert_equal(expected_html, result.value)
 def vmerge_without_val_is_treated_as_continue(self):
     element = xml_element("w:tbl", {}, [
         w_tr(w_tc(properties=[w_vmerge("restart")])),
         w_tr(w_tc(properties=[w_vmerge(None)])),
     ])
     result = _read_and_get_document_xml_element(element)
     expected_result = documents.table([
         documents.table_row([documents.table_cell([], rowspan=2)]),
         documents.table_row([]),
     ])
     assert_equal(expected_result, result)
Beispiel #20
0
 def vmerge_without_val_is_treated_as_continue(self):
     element = xml_element("w:tbl", {}, [
         w_tr(w_tc(properties=[w_vmerge("restart")])),
         w_tr(w_tc(properties=[w_vmerge(None)])),
     ])
     result = _read_and_get_document_xml_element(element)
     expected_result = documents.table([
         documents.table_row([documents.table_cell([], rowspan=2)]),
         documents.table_row([]),
     ])
     assert_equal(expected_result, result)
def table_cells_are_written_with_rowspan_if_not_equal_to_one():
    table = documents.table([
        documents.table_row([
            documents.table_cell([], rowspan=2),
        ]),
    ])
    result = convert_document_element_to_html(table)
    expected_html = (
        "<table>" +
        "<tr><td rowspan=\"2\"></td></tr>" +
        "</table>")
    assert_equal(expected_html, result.value)
 def word_table_is_read_as_document_table_element(self):
     element = xml_element("w:tbl", {}, [
         xml_element("w:tr", {}, [
             xml_element("w:tc", {}, [xml_element("w:p", {}, [])]),
         ]),
     ])
     table = _read_and_get_document_xml_element(element)
     expected_result = documents.table([
         documents.table_row(
             [documents.table_cell([documents.paragraph([])])])
     ])
     assert_equal(expected_result, table)
Beispiel #23
0
 def gridspan_is_read_as_colspan_for_table_cell(self):
     element = xml_element("w:tbl", {}, [
         xml_element("w:tr", {}, [
             xml_element("w:tc", {}, [
                 xml_element("w:tcPr", {},
                             [xml_element("w:gridSpan", {"w:val": "2"})]),
                 xml_element("w:p", {}, [])
             ]),
         ]),
     ])
     table = _read_and_get_document_xml_element(element)
     expected_result = documents.table([
         documents.table_row(
             [documents.table_cell([documents.paragraph([])], colspan=2)])
     ])
     assert_equal(expected_result, table)
 def gridspan_is_read_as_colspan_for_table_cell(self):
     element = xml_element("w:tbl", {}, [
         xml_element("w:tr", {}, [
             xml_element("w:tc", {}, [
                 xml_element("w:tcPr", {}, [
                     xml_element("w:gridSpan", {"w:val": "2"})
                 ]),
                 xml_element("w:p", {}, [])
             ]),
         ]),
     ])
     table = _read_and_get_document_xml_element(element)
     expected_result = documents.table([
         documents.table_row([
             documents.table_cell([
                 documents.paragraph([])
             ], colspan=2)
         ])
     ])
     assert_equal(expected_result, table)