diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-12-12 22:19:46 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-12-12 22:19:46 +0000 |
| commit | eab369b5721b933c080516fd1dcdfa67e6e2dfcd (patch) | |
| tree | 1693be2772ec9f5c8c3ededb954842983e3d2a84 /mammoth/style_reader.py | |
| parent | 856f9968e15b4efffd9c2ac229263b659576a96e (diff) | |
Read classes on HTML path elements
Diffstat (limited to 'mammoth/style_reader.py')
| -rw-r--r-- | mammoth/style_reader.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/mammoth/style_reader.py b/mammoth/style_reader.py index 7a7474f..4418dbb 100644 --- a/mammoth/style_reader.py +++ b/mammoth/style_reader.py @@ -18,7 +18,9 @@ def _read_path_node(path_node): def _read_element_node(node): - return html_paths.element(_read_tag_names_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) def _read_tag_names_node(node): @@ -28,6 +30,17 @@ def _read_tag_names_node(node): ] +def _read_class_names_node(class_names_node): + return [ + _read_class_name_node(node) + for node in class_names_node.children + ] + + +def _read_class_name_node(node): + return node.children[1].text + + def _repeated_children_with_separator(node, has_whitespace): yield node.children[0] @@ -45,7 +58,9 @@ _grammar = Grammar(r""" path = element whitespace* (">" whitespace* element)* -element = tag_names +element = tag_names class_name* + +class_name = "." identifier tag_names = identifier ("|" identifier)* |
