summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-25 19:07:27 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-25 19:07:27 +0000
commit3ed30fd8bc749d3c8009b3fd9e8ce125af5ee441 (patch)
tree6460c7e1f2e9940a6ef1e84a2626acfd8ae5aff0
parent17ba20787c2637c65df0c02c6ffbd71a318e451a (diff)
Read italic document matcher
-rw-r--r--mammoth/document_matchers.py12
-rw-r--r--mammoth/style_reader/document_matcher_reader.py10
-rw-r--r--tests/style_reader_tests.py7
3 files changed, 22 insertions, 7 deletions
diff --git a/mammoth/document_matchers.py b/mammoth/document_matchers.py
index 1116a07..6f40318 100644
--- a/mammoth/document_matchers.py
+++ b/mammoth/document_matchers.py
@@ -17,13 +17,17 @@ RunMatcher = collections.namedtuple("RunMatcher", ["style_id", "style_name"])
RunMatcher.element_type = "run"
+class bold(object):
+ element_type = "bold"
+
+
+class italic(object):
+ element_type = "italic"
+
+
class underline(object):
element_type = "underline"
class strikethrough(object):
element_type = "strikethrough"
-
-
-class bold(object):
- element_type = "bold"
diff --git a/mammoth/style_reader/document_matcher_reader.py b/mammoth/style_reader/document_matcher_reader.py
index ee5b467..66f5d19 100644
--- a/mammoth/style_reader/document_matcher_reader.py
+++ b/mammoth/style_reader/document_matcher_reader.py
@@ -14,12 +14,14 @@ def read_document_matcher_node(root_node):
return _read_paragraph_node(element_node)
elif element_node.expr_name == "run":
return _read_run_node(element_node)
+ elif element_node.expr_name == "bold":
+ return document_matchers.bold
+ elif element_node.expr_name == "italic":
+ return document_matchers.italic
elif element_node.expr_name == "underline":
return document_matchers.underline
elif element_node.expr_name == "strikethrough":
return document_matchers.strikethrough
- elif element_node.expr_name == "bold":
- return document_matchers.bold
def _read_paragraph_node(paragraph_node):
@@ -59,7 +61,7 @@ def _read_list_node(list_node):
return None
grammar_text = r"""
-document_matcher = paragraph / run / underline / strikethrough / bold
+document_matcher = paragraph / run / underline / strikethrough / bold / italic
underline = "u"
@@ -67,6 +69,8 @@ strikethrough = "strike"
bold = "b"
+italic = "i"
+
paragraph = "p" style_id? style_name_specifier? list?
run = "r" style_id? style_name_specifier?
diff --git a/tests/style_reader_tests.py b/tests/style_reader_tests.py
index 62b1a2b..1f68ac2 100644
--- a/tests/style_reader_tests.py
+++ b/tests/style_reader_tests.py
@@ -142,6 +142,13 @@ class ReadDocumentMatcherTests(object):
)
@istest
+ def reads_italic(self):
+ assert_equal(
+ document_matchers.italic,
+ read_document_matcher("i")
+ )
+
+ @istest
def reads_underline(self):
assert_equal(
document_matchers.underline,