From b5606471d456a4d08ac18a97b58e353938ce39f9 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 25 Jan 2015 15:26:01 +0000 Subject: Allow empty HTML paths --- mammoth/style_reader/html_path_reader.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'mammoth/style_reader/html_path_reader.py') diff --git a/mammoth/style_reader/html_path_reader.py b/mammoth/style_reader/html_path_reader.py index b508f59..20666d4 100644 --- a/mammoth/style_reader/html_path_reader.py +++ b/mammoth/style_reader/html_path_reader.py @@ -9,6 +9,13 @@ 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]) + else: + return html_paths.empty + + +def _read_html_path_elements_node(path_node): elements = [ _read_element_node(child) for child in _repeated_children_with_separator(path_node, has_whitespace=True) @@ -60,7 +67,9 @@ def _repeated_children_with_separator(node, has_whitespace): grammar_text = r""" -html_path = element (whitespace* ">" whitespace* element)* +html_path = html_path_elements? + +html_path_elements = element (whitespace* ">" whitespace* element)* element = tag_names class_name* fresh? @@ -70,7 +79,7 @@ class_name = "." identifier fresh = ":fresh" -identifier = ~"[A-Z0-9]*"i +identifier = ~"[A-Z0-9]+"i whitespace = ~"\s"* -- cgit v1.2.3