diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-05-11 18:01:31 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-05-11 18:01:31 +0100 |
| commit | 61e88321b9e5dc67a0373edc69f8114db8c1d3b7 (patch) | |
| tree | 3f43fd006b6c095f91c2424086b273928881336c /mammoth | |
| parent | 7e57058cf120717cc2d2fea3b897b12c3891b28a (diff) | |
Rename existing concept of style names to style IDs to match docx
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/conversion.py | 8 | ||||
| -rw-r--r-- | mammoth/document_matchers.py | 12 | ||||
| -rw-r--r-- | mammoth/documents.py | 12 | ||||
| -rw-r--r-- | mammoth/docx/document_xml.py | 8 | ||||
| -rw-r--r-- | mammoth/style_reader/document_matcher_reader.py | 14 |
5 files changed, 27 insertions, 27 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py index 8123ebd..56d0fae 100644 --- a/mammoth/conversion.py +++ b/mammoth/conversion.py @@ -104,8 +104,8 @@ class DocumentConverter(object): if _document_matcher_matches(document_matcher, element, element_type): return style.html_path - if element.style_name is not None: - self.messages.append(results.warning("Unrecognised {0} style: {1}".format(element_type, element.style_name))) + if element.style_id is not None: + self.messages.append(results.warning("Unrecognised {0} style: {1}".format(element_type, element.style_id))) return default @@ -113,8 +113,8 @@ class DocumentConverter(object): def _document_matcher_matches(matcher, element, element_type): return ( matcher.element_type == element_type and ( - matcher.style_name is None or - matcher.style_name == element.style_name + matcher.style_id is None or + matcher.style_id == element.style_id ) and ( element_type != "paragraph" or matcher.numbering is None or diff --git a/mammoth/document_matchers.py b/mammoth/document_matchers.py index ed4171b..014e4e3 100644 --- a/mammoth/document_matchers.py +++ b/mammoth/document_matchers.py @@ -1,17 +1,17 @@ import collections -def paragraph(style_name=None, numbering=None): - return ParagraphMatcher(style_name, numbering) +def paragraph(style_id=None, numbering=None): + return ParagraphMatcher(style_id, numbering) -ParagraphMatcher = collections.namedtuple("ParagraphMatcher", ["style_name", "numbering"]) +ParagraphMatcher = collections.namedtuple("ParagraphMatcher", ["style_id", "numbering"]) ParagraphMatcher.element_type = "paragraph" -def run(style_name=None): - return RunMatcher(style_name) +def run(style_id=None): + return RunMatcher(style_id) -RunMatcher = collections.namedtuple("RunMatcher", ["style_name"]) +RunMatcher = collections.namedtuple("RunMatcher", ["style_id"]) RunMatcher.element_type = "run" diff --git a/mammoth/documents.py b/mammoth/documents.py index 65a9b84..b8da897 100644 --- a/mammoth/documents.py +++ b/mammoth/documents.py @@ -2,8 +2,8 @@ import dodge Document = dodge.data_class("Document", ["children"]) -Paragraph = dodge.data_class("Paragraph", ["children", "style_name", "numbering"]) -Run = dodge.data_class("Run", ["children", "style_name", "is_bold", "is_italic"]) +Paragraph = dodge.data_class("Paragraph", ["children", "style_id", "numbering"]) +Run = dodge.data_class("Run", ["children", "style_id", "is_bold", "is_italic"]) Text = dodge.data_class("Text", ["value"]) Hyperlink = dodge.data_class("Hyperlink", ["href", "children"]) @@ -20,11 +20,11 @@ class Image(object): document = Document -def paragraph(children, style_name=None, numbering=None): - return Paragraph(children, style_name, numbering) +def paragraph(children, style_id=None, numbering=None): + return Paragraph(children, style_id, numbering) -def run(children, style_name=None, is_bold=None, is_italic=None): - return Run(children, style_name, bool(is_bold), bool(is_italic)) +def run(children, style_id=None, is_bold=None, is_italic=None): + return Run(children, style_id, bool(is_bold), bool(is_italic)) text = Text diff --git a/mammoth/docx/document_xml.py b/mammoth/docx/document_xml.py index e4682a6..5023ec5 100644 --- a/mammoth/docx/document_xml.py +++ b/mammoth/docx/document_xml.py @@ -42,7 +42,7 @@ def _create_reader(numbering, content_types, relationships, docx_file): @handler("w:r") def run(element): properties = element.find_child_or_null("w:rPr") - style_name = properties \ + style_id = properties \ .find_child_or_null("w:rStyle") \ .attributes.get("w:val") is_bold = properties.find_child("w:b") @@ -51,7 +51,7 @@ def _create_reader(numbering, content_types, relationships, docx_file): return _read_xml_elements(element.children) \ .map(lambda children: documents.run( children=children, - style_name=style_name, + style_id=style_id, is_bold=is_bold, is_italic=is_italic, )) @@ -60,7 +60,7 @@ def _create_reader(numbering, content_types, relationships, docx_file): @handler("w:p") def paragraph(element): properties = element.find_child_or_null("w:pPr") - style_name = properties \ + style_id = properties \ .find_child_or_null("w:pStyle") \ .attributes.get("w:val") numbering_properties = properties.find_child("w:numPr") @@ -72,7 +72,7 @@ def _create_reader(numbering, content_types, relationships, docx_file): return _read_xml_elements(element.children) \ .map(lambda children: documents.paragraph( children=children, - style_name=style_name, + style_id=style_id, numbering=numbering, )) diff --git a/mammoth/style_reader/document_matcher_reader.py b/mammoth/style_reader/document_matcher_reader.py index 44a9896..5b50f24 100644 --- a/mammoth/style_reader/document_matcher_reader.py +++ b/mammoth/style_reader/document_matcher_reader.py @@ -17,14 +17,14 @@ def read_document_matcher_node(root_node): def _read_paragraph_node(paragraph_node): - style_name = _read_style_node(paragraph_node.children[1]) + style_id = _read_style_node(paragraph_node.children[1]) numbering = _read_list_node(paragraph_node.children[2]) - return document_matchers.paragraph(style_name=style_name, numbering=numbering) + return document_matchers.paragraph(style_id=style_id, numbering=numbering) def _read_run_node(run_node): - style_name = _read_style_node(run_node.children[1]) - return document_matchers.run(style_name=style_name) + style_id = _read_style_node(run_node.children[1]) + return document_matchers.run(style_id=style_id) def _read_style_node(style_node): @@ -46,11 +46,11 @@ def _read_list_node(list_node): grammar_text = r""" document_matcher = paragraph / run -paragraph = "p" style_name? list? +paragraph = "p" style_id? list? -run = "r" style_name? +run = "r" style_id? -style_name = "." style_identifier +style_id = "." style_identifier style_identifier = ~"[A-Z0-9]*"i |
