aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/document_matchers.py6
-rw-r--r--mammoth/style_reader/document_matcher_reader.py16
2 files changed, 17 insertions, 5 deletions
diff --git a/mammoth/document_matchers.py b/mammoth/document_matchers.py
index 5f1af2e..8bae5b1 100644
--- a/mammoth/document_matchers.py
+++ b/mammoth/document_matchers.py
@@ -1,8 +1,8 @@
import collections
-def paragraph():
- return ParagraphMatcher()
+def paragraph(style_name=None):
+ return ParagraphMatcher(style_name)
-ParagraphMatcher = collections.namedtuple("ParagraphMatcher", [])
+ParagraphMatcher = collections.namedtuple("ParagraphMatcher", ["style_name"])
diff --git a/mammoth/style_reader/document_matcher_reader.py b/mammoth/style_reader/document_matcher_reader.py
index 583613a..f72f03d 100644
--- a/mammoth/style_reader/document_matcher_reader.py
+++ b/mammoth/style_reader/document_matcher_reader.py
@@ -10,10 +10,22 @@ def read_document_matcher(string):
def _read_paragraph_node(paragraph_node):
- return document_matchers.paragraph()
+ style_name = _read_style_node(paragraph_node.children[1])
+ return document_matchers.paragraph(style_name=style_name)
+
+
+def _read_style_node(style_node):
+ if style_node.children:
+ return style_node.children[0].children[1].text
+ else:
+ return None
_grammar = Grammar(r"""
-paragraph = "p"
+paragraph = "p" style_name?
+
+style_name = "." style_identifier
+
+style_identifier = ~"[A-Z0-9]*"i
""")