From fe41ddbc51b4b7c6ce7d958ea7622983d7805b7e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 17 Feb 2024 13:52:16 +0000 Subject: Support attributes in HTML paths in style mappings --- mammoth/html_paths.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'mammoth/html_paths.py') diff --git a/mammoth/html_paths.py b/mammoth/html_paths.py index c91813a..a8fb952 100644 --- a/mammoth/html_paths.py +++ b/mammoth/html_paths.py @@ -7,15 +7,16 @@ def path(elements): return HtmlPath(elements) -def element(names, class_names=None, fresh=None, separator=None): +def element(names, attributes=None, class_names=None, fresh=None, separator=None): + if attributes is None: + attributes = {} if class_names is None: class_names = [] if fresh is None: fresh = False if class_names: - attributes = {"class": " ".join(class_names)} - else: - attributes = {} + attributes["class"] = " ".join(class_names) + return HtmlPathElement(html.tag( tag_names=names, attributes=attributes, @@ -27,13 +28,13 @@ def element(names, class_names=None, fresh=None, separator=None): @cobble.data class HtmlPath(object): elements = cobble.field() - + def wrap(self, generate_nodes): nodes = generate_nodes() for element in reversed(self.elements): nodes = element.wrap_nodes(nodes) - + return nodes -- cgit v1.2.3