def multiple_p_elements_are_read_as_multiple_paragraphs(): document_xml = _create_document_xml( "<w:p><w:r><w:t>Hello</w:t></w:r></w:p>" + "<w:p><w:r><w:t>there</w:t></w:r></w:p>" ) result = read_document(document_xml) expected_document = openxml.document([ openxml.paragraph([ openxml.run([ openxml.text("Hello") ]) ]), openxml.paragraph([ openxml.run([ openxml.text("there") ]) ]) ]) assert_equal(expected_document, result)
def word_document_containing_one_paragraph_is_read(): document_xml = _create_document_xml("<w:p><w:r><w:t>Hello.</w:t></w:r></w:p>") result = read_document(document_xml) expected_document = openxml.document([ openxml.paragraph([ openxml.run([ openxml.text("Hello.") ]) ]) ]) assert_equal(expected_document, result)
def paragraph_style_is_read_from_paragraph_properties_element(): document_xml = _create_document_xml( "<w:p>" + """<w:pPr><w:pStyle w:val="Heading1"/></w:pPr>""" + "<w:r><w:t>Hello.</w:t></w:r>" + "</w:p>" ) result = read_document(document_xml) expected_document = openxml.document([ openxml.paragraph([ openxml.run([ openxml.text("Hello.") ]) ], style="Heading1") ]) assert_equal(expected_document, result)
def paragraph_style_is_read_from_paragraph_properties_element(): document_xml = _create_document_xml(""" <w:p> <w:pPr> <w:pStyle w:val="ListParagraph"/> <w:numPr> <w:ilvl w:val="0"/> <w:numId w:val="1"/> </w:numPr> </w:pPr> <w:r><w:t>Hello.</w:t></w:r> </w:p>""" ) result = read_document(document_xml) expected_document = openxml.document([ openxml.paragraph([ openxml.run([ openxml.text("Hello.") ]) ], style="ListParagraph", numbering_level=0) ]) assert_equal(expected_document, result)
def _run_of_text(text): return openxml.run([openxml.text(text)])