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)
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:])
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)
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)
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 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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
def _style_mapping(text): result = style_reader.read_style(text) assert_equal([], result.messages) return result.value
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:])
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") )
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)
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)
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)
def _style_mapping(text): result = style_reader.read_style(text) assert not result.messages return result.value