diff options
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/document_matchers.py | 7 | ||||
| -rw-r--r-- | mammoth/style_reader/document_matcher_reader.py | 18 |
2 files changed, 22 insertions, 3 deletions
diff --git a/mammoth/document_matchers.py b/mammoth/document_matchers.py index 8bae5b1..1049c94 100644 --- a/mammoth/document_matchers.py +++ b/mammoth/document_matchers.py @@ -6,3 +6,10 @@ def paragraph(style_name=None): ParagraphMatcher = collections.namedtuple("ParagraphMatcher", ["style_name"]) + + +def run(style_name=None): + return RunMatcher(style_name) + + +RunMatcher = collections.namedtuple("RunMatcher", ["style_name"]) diff --git a/mammoth/style_reader/document_matcher_reader.py b/mammoth/style_reader/document_matcher_reader.py index f72f03d..ba08e09 100644 --- a/mammoth/style_reader/document_matcher_reader.py +++ b/mammoth/style_reader/document_matcher_reader.py @@ -4,14 +4,22 @@ from .. import document_matchers def read_document_matcher(string): - paragraph_node = _grammar.parse(string) - return _read_paragraph_node(paragraph_node) + root_node = _grammar.parse(string) + element_node = root_node.children[0] + if element_node.expr_name == "paragraph": + return _read_paragraph_node(element_node) + elif element_node.expr_name == "run": + return _read_run_node(element_node) - def _read_paragraph_node(paragraph_node): style_name = _read_style_node(paragraph_node.children[1]) return document_matchers.paragraph(style_name=style_name) + + +def _read_run_node(run_node): + style_name = _read_style_node(run_node.children[1]) + return document_matchers.run(style_name=style_name) def _read_style_node(style_node): @@ -22,8 +30,12 @@ def _read_style_node(style_node): _grammar = Grammar(r""" +matcher = paragraph / run + paragraph = "p" style_name? +run = "r" style_name? + style_name = "." style_identifier style_identifier = ~"[A-Z0-9]*"i |
