diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-11-29 22:23:49 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-11-29 22:23:49 +0000 |
| commit | f49ef5f80a0d20bebd5155f7d8f99b5e6366e35f (patch) | |
| tree | 68c18f3ec1f84e31d5ebeab596c3edce6030ff34 /mammoth/html_paths.py | |
| parent | 2f8bd9edc77b8508203e221ad96c79f516205d92 (diff) | |
Introduce tag object for HTML elements
Diffstat (limited to 'mammoth/html_paths.py')
| -rw-r--r-- | mammoth/html_paths.py | 29 |
1 files changed, 13 insertions, 16 deletions
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([]) |
