aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-12 21:57:49 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-12 21:57:49 +0000
commitd745ac4b6d65e6729b3d70ddaa23a95bb59fbd39 (patch)
tree4a8891a371ca84f5cbb657f3382284992df86b6c /mammoth
parente2a87dbda6d32200b5fa68ba2f5e48aa526499f2 (diff)
Support choice of element
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/html_paths.py6
-rw-r--r--mammoth/style_reader.py19
2 files changed, 21 insertions, 4 deletions
diff --git a/mammoth/html_paths.py b/mammoth/html_paths.py
index bc4eba1..cb53968 100644
--- a/mammoth/html_paths.py
+++ b/mammoth/html_paths.py
@@ -5,9 +5,9 @@ def path(elements):
return HtmlPath(elements)
-def element(name):
- return HtmlPathElement(name)
+def element(names):
+ return HtmlPathElement(names)
HtmlPath = collections.namedtuple("HtmlPath", ["elements"])
-HtmlPathElement = collections.namedtuple("HtmlPathElement", ["name"])
+HtmlPathElement = collections.namedtuple("HtmlPathElement", ["names"])
diff --git a/mammoth/style_reader.py b/mammoth/style_reader.py
index 18c848d..0c27bd8 100644
--- a/mammoth/style_reader.py
+++ b/mammoth/style_reader.py
@@ -1,5 +1,22 @@
+from parsimonious.grammar import Grammar
+
from . import html_paths
def read_html_path(string):
- return html_paths.path([html_paths.element(string)])
+ root_node = _grammar.parse(string)
+ tag_names = [root_node.children[0].text]
+
+ for choice_node in root_node.children[1].children:
+ tag_names.append(choice_node.children[1].text)
+
+ return html_paths.path([html_paths.element(tag_names)])
+
+
+_grammar = Grammar("""
+
+tag_names = identifier ("|" identifier)*
+
+identifier = ~"[A-Z0-9]*"i
+
+""")