Skip to content

Commit e2f3982

Browse files
committed
Add Apple Pages paragraph styles to default style map
1 parent 013e260 commit e2f3982

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.10.0
2+
3+
* Add "Heading" and "Body" styles, as found in documents created by Apple Pages,
4+
to the default style map.
5+
16
# 1.9.1
27

38
* Ignore AlternateContent elements when there is no Fallback element.

mammoth/options.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ def read_options(options):
66
custom_style_map_text = options.pop("style_map", "") or ""
77
embedded_style_map_text = options.pop("embedded_style_map", "") or ""
88
include_default_style_map = options.pop("include_default_style_map", True)
9-
9+
1010
read_style_map_result = results.combine([
1111
_read_style_map(custom_style_map_text),
1212
_read_style_map(embedded_style_map_text),
1313
])
14-
14+
1515
custom_style_map, embedded_style_map = read_style_map_result.value
1616
style_map = custom_style_map + embedded_style_map
17-
17+
1818
if include_default_style_map:
1919
style_map += _default_style_map
20-
20+
2121
options["ignore_empty_paragraphs"] = options.get("ignore_empty_paragraphs", True)
2222
options["style_map"] = style_map
2323
return read_style_map_result.map(lambda _: options)
@@ -27,7 +27,7 @@ def _read_style_map(style_text):
2727
lines = filter(None, map(_get_line, style_text.split("\n")))
2828
return results.combine(lists.map(read_style_mapping, lines)) \
2929
.map(lambda style_mappings: lists.filter(None, style_mappings))
30-
30+
3131

3232
def _get_line(line):
3333
line = line.strip()
@@ -57,6 +57,10 @@ def _get_line(line):
5757
p[style-name='heading 5'] => h5:fresh
5858
p[style-name='heading 6'] => h6:fresh
5959
60+
# Apple Pages
61+
p.Heading => h1:fresh
62+
p[style-name='Heading'] => h1:fresh
63+
6064
r[style-name='Strong'] => strong
6165
6266
p[style-name='footnote text'] => p:fresh
@@ -65,7 +69,7 @@ def _get_line(line):
6569
r[style-name='endnote reference'] =>
6670
p[style-name='annotation text'] => p:fresh
6771
r[style-name='annotation reference'] =>
68-
72+
6973
# LibreOffice
7074
p[style-name='Footnote'] => p:fresh
7175
r[style-name='Footnote anchor'] =>
@@ -86,6 +90,10 @@ def _get_line(line):
8690
r[style-name='Hyperlink'] =>
8791
8892
p[style-name='Normal'] => p:fresh
93+
94+
# Apple Pages
95+
p.Body => p:fresh
96+
p[style-name='Body'] => p:fresh
8997
""")
9098

9199

0 commit comments

Comments
 (0)