aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-12 22:32:52 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-12 22:32:52 +0000
commit3672775a5469e06455685d74f0f4f0ee35505ff5 (patch)
tree26a9680bcd70a8a013ac7aa944cf309f052bc4dc
parent1fd31a5fa207c40aaaae74f62cc3b491f15dcd41 (diff)
Read plain document paragraph matcher
-rw-r--r--mammoth/document_matchers.py8
-rw-r--r--mammoth/style_reader/__init__.py1
-rw-r--r--mammoth/style_reader/document_matcher_reader.py19
-rw-r--r--tests/style_reader_tests.py14
4 files changed, 40 insertions, 2 deletions
diff --git a/mammoth/document_matchers.py b/mammoth/document_matchers.py
new file mode 100644
index 0000000..5f1af2e
--- /dev/null
+++ b/mammoth/document_matchers.py
@@ -0,0 +1,8 @@
+import collections
+
+
+def paragraph():
+ return ParagraphMatcher()
+
+
+ParagraphMatcher = collections.namedtuple("ParagraphMatcher", [])
diff --git a/mammoth/style_reader/__init__.py b/mammoth/style_reader/__init__.py
index 892326e..705abff 100644
--- a/mammoth/style_reader/__init__.py
+++ b/mammoth/style_reader/__init__.py
@@ -1 +1,2 @@
from .html_path_reader import read_html_path
+from .document_matcher_reader import read_document_matcher
diff --git a/mammoth/style_reader/document_matcher_reader.py b/mammoth/style_reader/document_matcher_reader.py
new file mode 100644
index 0000000..583613a
--- /dev/null
+++ b/mammoth/style_reader/document_matcher_reader.py
@@ -0,0 +1,19 @@
+from parsimonious.grammar import Grammar
+
+from .. import document_matchers
+
+
+def read_document_matcher(string):
+ paragraph_node = _grammar.parse(string)
+ return _read_paragraph_node(paragraph_node)
+
+
+
+def _read_paragraph_node(paragraph_node):
+ return document_matchers.paragraph()
+
+
+_grammar = Grammar(r"""
+paragraph = "p"
+""")
+
diff --git a/tests/style_reader_tests.py b/tests/style_reader_tests.py
index 80c3124..433b8b3 100644
--- a/tests/style_reader_tests.py
+++ b/tests/style_reader_tests.py
@@ -1,7 +1,7 @@
from nose.tools import istest, assert_equal
-from mammoth import html_paths
-from mammoth.style_reader import read_html_path
+from mammoth import html_paths, document_matchers
+from mammoth.style_reader import read_html_path, read_document_matcher
@istest
@@ -59,3 +59,13 @@ class ReadHtmlPathTests(object):
html_paths.path([html_paths.element(["p"], fresh=True)]),
read_html_path("p:fresh")
)
+
+
+@istest
+class ReadDocumentMatcherTests(object):
+ @istest
+ def reads_plain_paragraph(self):
+ assert_equal(
+ document_matchers.paragraph(),
+ read_document_matcher("p")
+ )