<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">from .styles.parser import read_style_mapping
from . import lists, results


def read_options(options):
    custom_style_map_text = options.pop("style_map", "") or ""
    embedded_style_map_text = options.pop("embedded_style_map", "") or ""
    include_default_style_map = options.pop("include_default_style_map", True)
    
    read_style_map_result = results.combine([
        _read_style_map(custom_style_map_text),
        _read_style_map(embedded_style_map_text),
    ])
    
    custom_style_map, embedded_style_map = read_style_map_result.value
    style_map = custom_style_map + embedded_style_map
    
    if include_default_style_map:
        style_map += _default_style_map
    
    options["ignore_empty_paragraphs"] = options.get("ignore_empty_paragraphs", True)
    options["style_map"] = style_map
    return read_style_map_result.map(lambda _: options)


def _read_style_map(style_text):
    lines = filter(None, map(_get_line, style_text.split("\n")))
    return results.combine(lists.map(read_style_mapping, lines)) \
        .map(lambda style_mappings: lists.filter(None, style_mappings))
    

def _get_line(line):
    line = line.strip()
    if line.startswith("#"):
        return None
    else:
        return line


_default_style_map_result = _read_style_map("""
p.Heading1 =&gt; h1:fresh
p.Heading2 =&gt; h2:fresh
p.Heading3 =&gt; h3:fresh
p.Heading4 =&gt; h4:fresh
p.Heading5 =&gt; h5:fresh
p.Heading6 =&gt; h6:fresh
p[style-name='Heading 1'] =&gt; h1:fresh
p[style-name='Heading 2'] =&gt; h2:fresh
p[style-name='Heading 3'] =&gt; h3:fresh
p[style-name='Heading 4'] =&gt; h4:fresh
p[style-name='Heading 5'] =&gt; h5:fresh
p[style-name='Heading 6'] =&gt; h6:fresh
p[style-name='heading 1'] =&gt; h1:fresh
p[style-name='heading 2'] =&gt; h2:fresh
p[style-name='heading 3'] =&gt; h3:fresh
p[style-name='heading 4'] =&gt; h4:fresh
p[style-name='heading 5'] =&gt; h5:fresh
p[style-name='heading 6'] =&gt; h6:fresh

r[style-name='Strong'] =&gt; strong

p[style-name='footnote text'] =&gt; p:fresh
r[style-name='footnote reference'] =&gt;
p[style-name='endnote text'] =&gt; p:fresh
r[style-name='endnote reference'] =&gt;
p[style-name='annotation text'] =&gt; p:fresh
r[style-name='annotation reference'] =&gt;
        
# LibreOffice
p[style-name='Footnote'] =&gt; p:fresh
r[style-name='Footnote anchor'] =&gt;
p[style-name='Endnote'] =&gt; p:fresh
r[style-name='Endnote anchor'] =&gt;

p:unordered-list(1) =&gt; ul &gt; li:fresh
p:unordered-list(2) =&gt; ul|ol &gt; li &gt; ul &gt; li:fresh
p:unordered-list(3) =&gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ul &gt; li:fresh
p:unordered-list(4) =&gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ul &gt; li:fresh
p:unordered-list(5) =&gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ul &gt; li:fresh
p:ordered-list(1) =&gt; ol &gt; li:fresh
p:ordered-list(2) =&gt; ul|ol &gt; li &gt; ol &gt; li:fresh
p:ordered-list(3) =&gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ol &gt; li:fresh
p:ordered-list(4) =&gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ol &gt; li:fresh
p:ordered-list(5) =&gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ul|ol &gt; li &gt; ol &gt; li:fresh

r[style-name='Hyperlink'] =&gt;

p[style-name='Normal'] =&gt; p:fresh
""")


assert not _default_style_map_result.messages
_default_style_map = _default_style_map_result.value
</pre></body></html>