aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-07-03 14:15:27 +0100
committerMichael Williamson <mike@zwobble.org>2016-07-03 14:15:27 +0100
commit8059e5f4d09fb14f2109cedb63ae0d353537e6b3 (patch)
treec6eb6869e4bd0bc3d9a84fac0ecd54f17ae34401
parentf5563e5a26ebcd51cc73f3cffbd51cff3c4d4ca7 (diff)
Add HTML path for ignoring elements
-rw-r--r--mammoth/html_paths.py5
-rw-r--r--mammoth/style_reader/html_path_reader.py10
-rw-r--r--tests/style_reader_tests.py8
3 files changed, 20 insertions, 3 deletions
diff --git a/mammoth/html_paths.py b/mammoth/html_paths.py
index 487f278..53580ed 100644
--- a/mammoth/html_paths.py
+++ b/mammoth/html_paths.py
@@ -49,3 +49,8 @@ class HtmlPathElement(object):
return [element]
empty = path([])
+
+
+class ignore(object):
+ def wrap(self, generate_nodes):
+ return []
diff --git a/mammoth/style_reader/html_path_reader.py b/mammoth/style_reader/html_path_reader.py
index 20666d4..f70c8e3 100644
--- a/mammoth/style_reader/html_path_reader.py
+++ b/mammoth/style_reader/html_path_reader.py
@@ -9,8 +9,10 @@ def read_html_path(string):
def read_html_path_node(path_node):
- if path_node.children:
- return _read_html_path_elements_node(path_node.children[0])
+ if path_node.children[0].expr_name == "ignore":
+ return html_paths.ignore
+ elif path_node.children[0].children:
+ return _read_html_path_elements_node(path_node.children[0].children[0])
else:
return html_paths.empty
@@ -67,7 +69,9 @@ def _repeated_children_with_separator(node, has_whitespace):
grammar_text = r"""
-html_path = html_path_elements?
+html_path = ignore / html_path_elements?
+
+ignore = "!"
html_path_elements = element (whitespace* ">" whitespace* element)*
diff --git a/tests/style_reader_tests.py b/tests/style_reader_tests.py
index fddc75b..61bc911 100644
--- a/tests/style_reader_tests.py
+++ b/tests/style_reader_tests.py
@@ -68,6 +68,14 @@ class ReadHtmlPathTests(object):
read_html_path("p:fresh")
)
+
+ @istest
+ def can_read_ignore_element(self):
+ assert_equal(
+ html_paths.ignore,
+ read_html_path("!")
+ )
+
@istest
class ReadDocumentMatcherTests(object):