From f49ef5f80a0d20bebd5155f7d8f99b5e6366e35f Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 29 Nov 2016 22:23:49 +0000 Subject: Introduce tag object for HTML elements --- mammoth/html_paths.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'mammoth/html_paths.py') diff --git a/mammoth/html_paths.py b/mammoth/html_paths.py index 8f79d72..c91813a 100644 --- a/mammoth/html_paths.py +++ b/mammoth/html_paths.py @@ -12,7 +12,16 @@ def element(names, class_names=None, fresh=None, separator=None): class_names = [] if fresh is None: fresh = False - return HtmlPathElement(names, class_names, fresh, separator=separator) + if class_names: + attributes = {"class": " ".join(class_names)} + else: + attributes = {} + return HtmlPathElement(html.tag( + tag_names=names, + attributes=attributes, + collapsible=not fresh, + separator=separator, + )) @cobble.data @@ -27,28 +36,16 @@ class HtmlPath(object): return nodes + @cobble.data class HtmlPathElement(object): - names = cobble.field() - class_names = cobble.field() - fresh = cobble.field() - separator = cobble.field() + tag = cobble.field() def wrap(self, generate_nodes): return self.wrap_nodes(generate_nodes()) def wrap_nodes(self, nodes): - if self.class_names: - attributes = {"class": " ".join(self.class_names)} - else: - attributes = {} - element = html.element( - self.names, - attributes, - nodes, - collapsible=not self.fresh, - separator=self.separator, - ) + element = html.Element(self.tag, nodes) return [element] empty = path([]) -- cgit v1.2.3