diff options
| author | Michael Williamson <mike@zwobble.org> | 2017-07-21 12:19:15 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2017-07-21 12:19:15 +0100 |
| commit | 500a2aca545c47b9677bd85e55b9b24dc4ec9c7c (patch) | |
| tree | 61a7bb91ae91ffd498b5ad1c2e5aac4178f72bb3 /mammoth | |
| parent | 6f7fbaa001eda6aca41f9a4f54f526ef7b87b738 (diff) | |
Add style mapping for small caps
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/conversion.py | 4 | ||||
| -rw-r--r-- | mammoth/document_matchers.py | 4 | ||||
| -rw-r--r-- | mammoth/documents.py | 13 | ||||
| -rw-r--r-- | mammoth/docx/body_xml.py | 2 | ||||
| -rw-r--r-- | mammoth/styles/parser/document_matcher_parser.py | 3 |
5 files changed, 23 insertions, 3 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py index 0fc3d58..066544e 100644 --- a/mammoth/conversion.py +++ b/mammoth/conversion.py @@ -109,6 +109,8 @@ class _DocumentConverter(documents.element_visitor(args=1)): def visit_run(self, run, context): nodes = lambda: self._visit_all(run.children, context) paths = [] + if run.is_small_caps: + paths.append(self._find_style_for_run_property("small_caps")) if run.is_strikethrough: paths.append(self._find_style_for_run_property("strikethrough", default="s")) if run.is_underline: @@ -346,7 +348,7 @@ class _DocumentConverter(documents.element_visitor(args=1)): def _document_matcher_matches(matcher, element, element_type): - if matcher.element_type in ["underline", "strikethrough", "bold", "italic", "comment_reference"]: + if matcher.element_type in ["underline", "strikethrough", "small_caps", "bold", "italic", "comment_reference"]: return matcher.element_type == element_type elif matcher.element_type == "break": return ( diff --git a/mammoth/document_matchers.py b/mammoth/document_matchers.py index faccb50..6429911 100644 --- a/mammoth/document_matchers.py +++ b/mammoth/document_matchers.py @@ -35,6 +35,10 @@ class strikethrough(object): element_type = "strikethrough" +class small_caps(object): + element_type = "small_caps" + + class comment_reference(object): element_type = "comment_reference" diff --git a/mammoth/documents.py b/mammoth/documents.py index 04e9d8e..d89de3f 100644 --- a/mammoth/documents.py +++ b/mammoth/documents.py @@ -30,6 +30,7 @@ class Run(HasChildren): is_italic = cobble.field() is_underline = cobble.field() is_strikethrough = cobble.field() + is_small_caps = cobble.field() vertical_alignment = cobble.field() font = cobble.field() @@ -95,14 +96,22 @@ def run( is_italic=None, is_underline=None, is_strikethrough=None, + is_small_caps=None, vertical_alignment=None, font=None, ): if vertical_alignment is None: vertical_alignment = VerticalAlignment.baseline return Run( - children, style_id, style_name, bool(is_bold), bool(is_italic), - bool(is_underline), bool(is_strikethrough), vertical_alignment, + children=children, + style_id=style_id, + style_name=style_name, + is_bold=bool(is_bold), + is_italic=bool(is_italic), + is_underline=bool(is_underline), + is_strikethrough=bool(is_strikethrough), + is_small_caps=bool(is_small_caps), + vertical_alignment=vertical_alignment, font=font, ) diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index 312e9de..12951c9 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -84,6 +84,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f is_italic = read_boolean_element(properties.find_child("w:i")) is_underline = read_boolean_element(properties.find_child("w:u")) is_strikethrough = read_boolean_element(properties.find_child("w:strike")) + is_small_caps = read_boolean_element(properties.find_child("w:smallCaps")) def add_complex_field_hyperlink(children): hyperlink_href = current_hyperlink_href() @@ -103,6 +104,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f is_italic=is_italic, is_underline=is_underline, is_strikethrough=is_strikethrough, + is_small_caps=is_small_caps, vertical_alignment=vertical_alignment, font=font, )) diff --git a/mammoth/styles/parser/document_matcher_parser.py b/mammoth/styles/parser/document_matcher_parser.py index 36999d0..034c59c 100644 --- a/mammoth/styles/parser/document_matcher_parser.py +++ b/mammoth/styles/parser/document_matcher_parser.py @@ -37,6 +37,9 @@ def parse_document_matcher(tokens): elif tokens.try_skip(TokenType.IDENTIFIER, "strike"): return document_matchers.strikethrough + elif tokens.try_skip(TokenType.IDENTIFIER, "small-caps"): + return document_matchers.small_caps + elif tokens.try_skip(TokenType.IDENTIFIER, "comment-reference"): return document_matchers.comment_reference |
