Ejemplo n.º 1
0
def bulleted_styles_dont_match_plain_paragraph():
    result = convert_document_element_to_html(
        documents.paragraph(children=[_run_with_text("Hello")]),
        style_map=[
            style_reader.read_style("p:unordered-list(1) => ul > li:fresh")
        ])
    assert_equal('<p>Hello</p>', result.value)
Ejemplo n.º 2
0
def custom_style_mappings_are_prepended_to_default_style_mappings():
    style_map = read_options({
        "style_map": "p.SectionTitle => h2"
    }).value["style_map"]
    assert_equal(
        style_reader.read_style("p.SectionTitle => h2").value, style_map[0])
    assert_equal(_default_style_map, style_map[1:])
Ejemplo n.º 3
0
def default_style_mappings_are_ignored_if_include_default_style_map_is_false():
    style_map = read_options({
        "style_map": "p.SectionTitle => h2",
        "include_default_style_map": False
    }).value["style_map"]
    assert_equal([style_reader.read_style("p.SectionTitle => h2").value],
                 style_map)
def document_matcher_is_mapped_to_html_path_using_fat_arrow():
    style_result = read_style("p => h1")
    assert_equal(
        styles.style(document_matchers.paragraph(), html_paths.path([html_paths.element(["h1"])])),
        style_result.value
    )
    assert_equal([], style_result.messages)
Ejemplo n.º 5
0
def document_matcher_is_mapped_to_html_path_using_fat_arrow():
    style_result = read_style("p => h1")
    assert_equal(
        styles.style(document_matchers.paragraph(), html_paths.path([html_paths.element(["h1"])])),
        style_result.value
    )
    assert_equal([], style_result.messages)
Ejemplo n.º 6
0
def lines_starting_with_hash_in_custom_style_map_are_ignored():
    style_map = read_options({
        "style_map": "#p.SectionTitle => h3\np.SectionTitle => h2",
        "include_default_style_map": False
    }).value["style_map"]
    assert_equal([style_reader.read_style("p.SectionTitle => h2").value],
                 style_map)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
def bulleted_paragraphs_are_converted_using_matching_styles():
    result = convert_document_element_to_html(
        documents.paragraph(
            children=[_run_with_text("Hello")], numbering=documents.numbering_level(level_index=0, is_ordered=False)
        ),
        style_map=[style_reader.read_style("p:unordered-list(1) => ul > li:fresh")],
    )
    assert_equal("<ul><li>Hello</li></ul>", result.value)
Ejemplo n.º 9
0
def runs_are_converted_by_satisfying_matching_paths():
    result = convert_document_element_to_html(
        documents.run(style_name="TipsRun", children=[documents.Text("Tip")]),
        style_map=[
            style_reader.read_style("r.TipsRun => span.tip")
        ]
    )
    assert_equal('<span class="tip">Tip</span>', result.value)
Ejemplo n.º 10
0
def style_mappings_using_style_names_can_be_used_to_map_paragraphs():
    result = convert_document_element_to_html(
        documents.paragraph(style_id="TipsParagraph",
                            style_name="Tips Paragraph",
                            children=[_run_with_text("Tip")]),
        style_map=[
            style_reader.read_style("p[style-name='Tips Paragraph'] => p.tip")
        ])
    assert_equal('<p class="tip">Tip</p>', result.value)
Ejemplo n.º 11
0
def bulleted_paragraphs_are_converted_using_matching_styles():
    result = convert_document_element_to_html(
        documents.paragraph(children=[_run_with_text("Hello")],
                            numbering=documents.numbering_level(
                                level_index=0, is_ordered=False)),
        style_map=[
            style_reader.read_style("p:unordered-list(1) => ul > li:fresh")
        ])
    assert_equal('<ul><li>Hello</li></ul>', result.value)
Ejemplo n.º 12
0
def style_names_in_style_mappings_are_case_insensitive():
    result = convert_document_element_to_html(
        documents.paragraph(style_id="TipsParagraph", style_name="Tips Paragraph", children=[
            _run_with_text("Tip")
        ]),
        style_map=[
            style_reader.read_style("p[style-name='tips paragraph'] => p.tip")
        ]
    )
    assert_equal('<p class="tip">Tip</p>', result.value)
Ejemplo n.º 13
0
def style_mappings_using_style_names_can_be_used_to_map_paragraphs():
    result = convert_document_element_to_html(
        documents.paragraph(style_id="TipsParagraph", style_name="Tips Paragraph", children=[
            _run_with_text("Tip")
        ]),
        style_map=[
            style_reader.read_style("p[style-name='Tips Paragraph'] => p.tip")
        ]
    )
    assert_equal('<p class="tip">Tip</p>', result.value)
Ejemplo n.º 14
0
def default_paragraph_style_is_specified_by_mapping_plain_paragraphs():
    result = convert_document_element_to_html(
        documents.paragraph(style_id="TipsParagraph", children=[
            _run_with_text("Tip")
        ]),
        style_map=[
            style_reader.read_style("p => p.tip")
        ]
    )
    assert_equal('<p class="tip">Tip</p>', result.value)
Ejemplo n.º 15
0
def default_paragraph_style_is_specified_by_mapping_plain_paragraphs():
    result = convert_document_element_to_html(
        documents.paragraph(style_name="TipsParagraph", children=[
            _run_with_text("Tip")
        ]),
        style_map=[
            style_reader.read_style("p => p.tip")
        ]
    )
    assert_equal('<p class="tip">Tip</p>', result.value)
Ejemplo n.º 16
0
def paragraphs_are_converted_by_satisfying_matching_paths():
    result = convert_document_element_to_html(
        documents.paragraph(style_name="TipsParagraph", children=[
            _run_with_text("Tip")
        ]),
        style_map=[
            style_reader.read_style("p.TipsParagraph => p.tip")
        ]
    )
    assert_equal('<p class="tip">Tip</p>', result.value)
Ejemplo n.º 17
0
def bulleted_styles_dont_match_plain_paragraph():
    result = convert_document_element_to_html(
        documents.paragraph(children=[
            _run_with_text("Hello")
        ]),
        style_map=[
            style_reader.read_style("p:unordered-list(1) => ul > li:fresh")
        ]
    )
    assert_equal('<p>Hello</p>', result.value)
Ejemplo n.º 18
0
def _style_mapping(text):
    result = style_reader.read_style(text)
    assert_equal([], result.messages)
    return result.value
Ejemplo n.º 19
0
def custom_style_mappings_are_prepended_to_default_style_mappings():
    style_map = read_options({
        "style_map": "p.SectionTitle => h2"
    }).value["style_map"]
    assert_equal(style_reader.read_style("p.SectionTitle => h2").value, style_map[0])
    assert_equal(_default_style_map, style_map[1:])
Ejemplo n.º 20
0
def default_style_mappings_are_ignored_if_include_default_style_map_is_false():
    style_map = read_options({
        "style_map": "p.SectionTitle => h2",
        "include_default_style_map": False
    }).value["style_map"]
    assert_equal([style_reader.read_style("p.SectionTitle => h2").value], style_map)
Ejemplo n.º 21
0
def document_matcher_is_mapped_to_html_path_using_fat_arrow():
    assert_equal(
        styles.style(document_matchers.paragraph(), html_paths.path([html_paths.element(["h1"])])),
        read_style("p => h1")
    )
Ejemplo n.º 22
0
def lines_starting_with_hash_in_custom_style_map_are_ignored():
    style_map = read_options({
        "style_map": "#p.SectionTitle => h3\np.SectionTitle => h2",
        "include_default_style_map": False
    }).value["style_map"]
    assert_equal([style_reader.read_style("p.SectionTitle => h2").value], style_map)
Ejemplo n.º 23
0
def underline_runs_can_be_mapped_using_style_mapping():
    result = convert_document_element_to_html(
        documents.run(children=[documents.text("Hello")], is_underline=True),
        style_map=[style_reader.read_style("u => em")],
    )
    assert_equal("<em>Hello</em>", result.value)
Ejemplo n.º 24
0
def style_mapping_for_underline_runs_does_not_close_parent_elements():
    result = convert_document_element_to_html(
        documents.run(children=[documents.text("Hello")], is_underline=True, is_bold=True),
        style_map=[style_reader.read_style("u => em")],
    )
    assert_equal("<strong><em>Hello</em></strong>", result.value)
Ejemplo n.º 25
0
def strikethrough_runs_can_be_configured_with_style_mapping():
    result = convert_document_element_to_html(
        documents.run(children=[documents.text("Hello")], is_strikethrough=True),
        style_map=[style_reader.read_style("strike => del")],
    )
    assert_equal("<del>Hello</del>", result.value)
Ejemplo n.º 26
0
def _style_mapping(text):
    result = style_reader.read_style(text)
    assert not result.messages
    return result.value