diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-07-03 14:04:33 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-07-03 14:04:33 +0100 |
| commit | f5563e5a26ebcd51cc73f3cffbd51cff3c4d4ca7 (patch) | |
| tree | 2aca74fd234f547de0563f40ee16d34a018493f2 /mammoth/html_paths.py | |
| parent | ed8acdfd79b014fd002890361593a9b2c1f21534 (diff) | |
Defer generation of child nodes until necessary
Diffstat (limited to 'mammoth/html_paths.py')
| -rw-r--r-- | mammoth/html_paths.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/mammoth/html_paths.py b/mammoth/html_paths.py index e043e23..487f278 100644 --- a/mammoth/html_paths.py +++ b/mammoth/html_paths.py @@ -19,9 +19,11 @@ def element(names, class_names=None, fresh=None): class HtmlPath(object): elements = cobble.field() - def wrap(self, nodes): + def wrap(self, generate_nodes): + nodes = generate_nodes() + for element in reversed(self.elements): - nodes = element.wrap(nodes) + nodes = element.wrap_nodes(nodes) return nodes @@ -31,7 +33,10 @@ class HtmlPathElement(object): class_names = cobble.field() fresh = cobble.field() - def wrap(self, nodes): + 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: |
