diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-12-12 22:22:16 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-12-12 22:22:16 +0000 |
| commit | 2791c74b8c1afc1014e380111b7e7f4d4ea09539 (patch) | |
| tree | 966d0718caa3522eb2477d1f64558ff7085d19a6 /mammoth | |
| parent | eab369b5721b933c080516fd1dcdfa67e6e2dfcd (diff) | |
Read :fresh on HTML path elements
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/html_paths.py | 8 | ||||
| -rw-r--r-- | mammoth/style_reader.py | 13 |
2 files changed, 15 insertions, 6 deletions
diff --git a/mammoth/html_paths.py b/mammoth/html_paths.py index 0f2184d..887288b 100644 --- a/mammoth/html_paths.py +++ b/mammoth/html_paths.py @@ -5,11 +5,13 @@ def path(elements): return HtmlPath(elements) -def element(names, class_names=None): +def element(names, class_names=None, fresh=None): if class_names is None: class_names = [] - return HtmlPathElement(names, class_names) + if fresh is None: + fresh = False + return HtmlPathElement(names, class_names, fresh) HtmlPath = collections.namedtuple("HtmlPath", ["elements"]) -HtmlPathElement = collections.namedtuple("HtmlPathElement", ["names", "class_names"]) +HtmlPathElement = collections.namedtuple("HtmlPathElement", ["names", "class_names", "fresh"]) diff --git a/mammoth/style_reader.py b/mammoth/style_reader.py index 4418dbb..2cdc261 100644 --- a/mammoth/style_reader.py +++ b/mammoth/style_reader.py @@ -20,7 +20,8 @@ def _read_path_node(path_node): def _read_element_node(node): tag_names = _read_tag_names_node(node.children[0]) class_names = _read_class_names_node(node.children[1]) - return html_paths.element(tag_names, class_names=class_names) + fresh = _read_fresh_node(node.children[2]) + return html_paths.element(tag_names, class_names=class_names, fresh=fresh) def _read_tag_names_node(node): @@ -41,6 +42,10 @@ def _read_class_name_node(node): return node.children[1].text +def _read_fresh_node(node): + return len(node.children) > 0 + + def _repeated_children_with_separator(node, has_whitespace): yield node.children[0] @@ -58,11 +63,13 @@ _grammar = Grammar(r""" path = element whitespace* (">" whitespace* element)* -element = tag_names class_name* +element = tag_names class_name* fresh? + +tag_names = identifier ("|" identifier)* class_name = "." identifier -tag_names = identifier ("|" identifier)* +fresh = ":fresh" identifier = ~"[A-Z0-9]*"i |
