diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-06-01 11:37:20 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-06-01 11:37:20 +0100 |
| commit | e2f39827f29ece66875e9fb4bb501cb391d3aa09 (patch) | |
| tree | 2a627bb26cad5f1c7fc62839b0fc1aa7aefe6e9d | |
| parent | 013e2601d214bfbc0eef10c28d8f939cb7e599e1 (diff) | |
Add Apple Pages paragraph styles to default style map
| -rw-r--r-- | NEWS | 5 | ||||
| -rw-r--r-- | mammoth/options.py | 20 |
2 files changed, 19 insertions, 6 deletions
@@ -1,3 +1,8 @@ +# 1.10.0 + +* Add "Heading" and "Body" styles, as found in documents created by Apple Pages, + to the default style map. + # 1.9.1 * Ignore AlternateContent elements when there is no Fallback element. diff --git a/mammoth/options.py b/mammoth/options.py index 11a61b6..a2031e2 100644 --- a/mammoth/options.py +++ b/mammoth/options.py @@ -6,18 +6,18 @@ 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) @@ -27,7 +27,7 @@ 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() @@ -57,6 +57,10 @@ p[style-name='heading 4'] => h4:fresh p[style-name='heading 5'] => h5:fresh p[style-name='heading 6'] => h6:fresh +# Apple Pages +p.Heading => h1:fresh +p[style-name='Heading'] => h1:fresh + r[style-name='Strong'] => strong p[style-name='footnote text'] => p:fresh @@ -65,7 +69,7 @@ p[style-name='endnote text'] => p:fresh r[style-name='endnote reference'] => p[style-name='annotation text'] => p:fresh r[style-name='annotation reference'] => - + # LibreOffice p[style-name='Footnote'] => p:fresh r[style-name='Footnote anchor'] => @@ -86,6 +90,10 @@ p:ordered-list(5) => ul|ol > li > ul|ol > li > ul|ol > li > ul|ol > li > ol > li r[style-name='Hyperlink'] => p[style-name='Normal'] => p:fresh + +# Apple Pages +p.Body => p:fresh +p[style-name='Body'] => p:fresh """) |
