aboutsummaryrefslogtreecommitdiff
path: root/mammoth/style_reader/document_matcher_reader.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-06-08 21:45:14 +0100
committerMichael Williamson <mike@zwobble.org>2014-06-08 21:45:14 +0100
commit178a640539e1af27fb7b64fc540adc17e58c30c4 (patch)
tree6fc31d523668335cb72943f6299916b9f841ed1e /mammoth/style_reader/document_matcher_reader.py
parent54faefdf17f764742da91685d10d589e0bc87f7d (diff)
Add support for reading style names in style maps
Diffstat (limited to 'mammoth/style_reader/document_matcher_reader.py')
-rw-r--r--mammoth/style_reader/document_matcher_reader.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/mammoth/style_reader/document_matcher_reader.py b/mammoth/style_reader/document_matcher_reader.py
index 5b50f24..0152fd2 100644
--- a/mammoth/style_reader/document_matcher_reader.py
+++ b/mammoth/style_reader/document_matcher_reader.py
@@ -17,19 +17,29 @@ def read_document_matcher_node(root_node):
def _read_paragraph_node(paragraph_node):
- style_id = _read_style_node(paragraph_node.children[1])
- numbering = _read_list_node(paragraph_node.children[2])
- return document_matchers.paragraph(style_id=style_id, numbering=numbering)
+ style_id = _read_style_id_node(paragraph_node.children[1])
+ style_name = _read_style_name_node(paragraph_node.children[2])
+ numbering = _read_list_node(paragraph_node.children[3])
+ return document_matchers.paragraph(style_id=style_id, style_name=style_name, numbering=numbering)
def _read_run_node(run_node):
- style_id = _read_style_node(run_node.children[1])
- return document_matchers.run(style_id=style_id)
+ style_id = _read_style_id_node(run_node.children[1])
+ style_name = _read_style_name_node(run_node.children[2])
+ return document_matchers.run(style_id=style_id, style_name=style_name)
-def _read_style_node(style_node):
- if style_node.children:
- return style_node.children[0].children[1].text
+def _read_style_id_node(style_id_node):
+ if style_id_node.children:
+ return style_id_node.children[0].children[1].text
+ else:
+ return None
+
+
+def _read_style_name_node(style_name_node):
+ if style_name_node.children:
+ print style_name_node.children[0].children[1]
+ return style_name_node.children[0].children[1].text
else:
return None
@@ -46,14 +56,18 @@ def _read_list_node(list_node):
grammar_text = r"""
document_matcher = paragraph / run
-paragraph = "p" style_id? list?
+paragraph = "p" style_id? style_name_specifier? list?
-run = "r" style_id?
+run = "r" style_id? style_name_specifier?
style_id = "." style_identifier
style_identifier = ~"[A-Z0-9]*"i
+style_name_specifier = "[style-name='" style_name "']"
+
+style_name = ~"[^']+"
+
list = ":" list_type "(" ~"[0-9]+" ")"
list_type = "ordered-list" / "unordered-list"