Example #1
0
def paragraphs_are_terminated_with_newlines():
    element = documents.paragraph(children=[
        documents.Text("Hello "),
        documents.Text("world."),
    ], )

    result = extract_raw_text_from_element(element)

    assert_equal("Hello world.\n\n", result)
def docx_hyperlinks_can_be_collapsed():
    result = convert_document_element_to_html(
        documents.document(children=[
            documents.hyperlink(href="http://example.com",
                                children=[documents.Text("Hello ")]),
            documents.hyperlink(href="http://example.com",
                                children=[documents.Text("world")]),
        ]))
    assert_equal('<a href="http://example.com">Hello world</a>', result.value)
def docx_hyperlink_with_internal_anchor_reference_is_converted_to_anchor_tag():
    result = convert_document_element_to_html(
        documents.hyperlink(anchor="start",
                            children=[documents.Text("Hello")]),
        id_prefix="doc-42-",
    )
    assert_equal('<a href="#doc-42-start">Hello</a>', result.value)
 def can_read_text_within_document(self):
     element = _document_element_with_text("Hello!")
     assert_equal(
         documents.document([
             documents.paragraph(
                 [documents.run([documents.Text("Hello!")])])
         ]), _read_and_get_document_xml_element(element))
def hyperlink_target_frame_is_used_as_anchor_target():
    result = convert_document_element_to_html(
        documents.hyperlink(
            anchor="start",
            target_frame="_blank",
            children=[documents.Text("Hello")],
        ), )
    assert_equal('<a href="#start" target="_blank">Hello</a>', result.value)
def runs_are_converted_by_satisfying_matching_paths():
    result = convert_document_element_to_html(
        documents.run(style_id="TipsRun", children=[documents.Text("Tip")]),
        style_map=[
            style_reader.read_style("r.TipsRun => span.tip")
        ]
    )
    assert_equal('<span class="tip">Tip</span>', result.value)
def docx_hyperlink_is_converted_to_anchor_tag():
    result = convert_document_element_to_html(
        documents.hyperlink(href="http://example.com",
                            children=[documents.Text("Hello")]), )
    assert_equal('<a href="http://example.com">Hello</a>', result.value)
Example #8
0
def can_read_text_within_run():
    element = _run_element_with_text("Hello!")
    assert_equal(
        documents.run([documents.Text("Hello!")]),
        _read_and_get_document_xml_element(element)
    )
Example #9
0
def text_from_text_element_is_read():
    element = _text_element("Hello!")
    assert_equal(documents.Text("Hello!"), _read_and_get_document_xml_element(element))
Example #10
0
def unrecognised_children_are_ignored():
    element = xml_element("w:r", {}, [_text_element("Hello!"), xml_element("w:huh", {}, [])])
    assert_equal(
        documents.run([documents.Text("Hello!")]),
        _read_document_xml_element(element).value
    )
Example #11
0
def raw_text_of_text_element_is_value():
    assert_equal("Hello",
                 extract_raw_text_from_element(documents.Text("Hello")))
Example #12
0
def raw_text_of_paragraph_is_terminated_with_newlines():
    paragraph = documents.paragraph(children=[documents.Text("Hello")])
    assert_equal("Hello\n\n", extract_raw_text_from_element(paragraph))
Example #13
0
def text_element_is_converted_to_text_content():
    element = documents.Text("Hello.")

    result = extract_raw_text_from_element(element)

    assert_equal("Hello.", result)