aboutsummaryrefslogtreecommitdiff
path: root/mammoth/style_reader
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-13 17:41:57 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-13 17:41:57 +0000
commit52a0281824ebe97f4233066b73a1e9739b639d9d (patch)
tree6e704b641c11b97fc141a7c0f4a44269a3f0ec7f /mammoth/style_reader
parentd091e47adf6cd69d986cac935de9d61b7da17f82 (diff)
Parse ordered list document matcher
Diffstat (limited to 'mammoth/style_reader')
-rw-r--r--mammoth/style_reader/document_matcher_reader.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/mammoth/style_reader/document_matcher_reader.py b/mammoth/style_reader/document_matcher_reader.py
index ba08e09..837da51 100644
--- a/mammoth/style_reader/document_matcher_reader.py
+++ b/mammoth/style_reader/document_matcher_reader.py
@@ -1,6 +1,6 @@
from parsimonious.grammar import Grammar
-from .. import document_matchers
+from .. import document_matchers, documents
def read_document_matcher(string):
@@ -14,7 +14,8 @@ def read_document_matcher(string):
def _read_paragraph_node(paragraph_node):
style_name = _read_style_node(paragraph_node.children[1])
- return document_matchers.paragraph(style_name=style_name)
+ numbering = _read_list_node(paragraph_node.children[2])
+ return document_matchers.paragraph(style_name=style_name, numbering=numbering)
def _read_run_node(run_node):
@@ -29,15 +30,27 @@ def _read_style_node(style_node):
return None
+def _read_list_node(list_node):
+ if list_node.children:
+ return documents.NumberingLevel(
+ int(list_node.children[0].children[1].text),
+ is_ordered=True,
+ )
+ else:
+ return None
+
+
_grammar = Grammar(r"""
matcher = paragraph / run
-paragraph = "p" style_name?
+paragraph = "p" style_name? list?
run = "r" style_name?
style_name = "." style_identifier
style_identifier = ~"[A-Z0-9]*"i
+
+list = ":ordered-list(" ~"[0-9]+" ")"
""")