aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/html_paths.py8
-rw-r--r--mammoth/style_reader.py19
2 files changed, 22 insertions, 5 deletions
diff --git a/mammoth/html_paths.py b/mammoth/html_paths.py
index cb53968..0f2184d 100644
--- a/mammoth/html_paths.py
+++ b/mammoth/html_paths.py
@@ -5,9 +5,11 @@ def path(elements):
return HtmlPath(elements)
-def element(names):
- return HtmlPathElement(names)
+def element(names, class_names=None):
+ if class_names is None:
+ class_names = []
+ return HtmlPathElement(names, class_names)
HtmlPath = collections.namedtuple("HtmlPath", ["elements"])
-HtmlPathElement = collections.namedtuple("HtmlPathElement", ["names"])
+HtmlPathElement = collections.namedtuple("HtmlPathElement", ["names", "class_names"])
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)*