From 17ba20787c2637c65df0c02c6ffbd71a318e451a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 25 Feb 2016 19:06:15 +0000 Subject: Parse bold document matcher --- mammoth/document_matchers.py | 4 ++++ mammoth/style_reader/document_matcher_reader.py | 6 +++++- tests/style_reader_tests.py | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mammoth/document_matchers.py b/mammoth/document_matchers.py index 9f05a8e..1116a07 100644 --- a/mammoth/document_matchers.py +++ b/mammoth/document_matchers.py @@ -23,3 +23,7 @@ class underline(object): 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 04a26c0..ee5b467 100644 --- a/mammoth/style_reader/document_matcher_reader.py +++ b/mammoth/style_reader/document_matcher_reader.py @@ -18,6 +18,8 @@ def read_document_matcher_node(root_node): 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): @@ -57,12 +59,14 @@ def _read_list_node(list_node): return None grammar_text = r""" -document_matcher = paragraph / run / underline / strikethrough +document_matcher = paragraph / run / underline / strikethrough / bold underline = "u" strikethrough = "strike" +bold = "b" + 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 776e2dc..62b1a2b 100644 --- a/tests/style_reader_tests.py +++ b/tests/style_reader_tests.py @@ -134,6 +134,13 @@ class ReadDocumentMatcherTests(object): read_document_matcher("r[style-name='Emphasis']") ) + @istest + def reads_bold(self): + assert_equal( + document_matchers.bold, + read_document_matcher("b") + ) + @istest def reads_underline(self): assert_equal( -- cgit v1.2.3