diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-12-14 15:03:26 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-12-14 15:03:26 +0000 |
| commit | c1eb161cc9d4b8e41d85643ba7b090f2f2d95471 (patch) | |
| tree | ba760723399c5cc9728a5061c1c88e6f0779330f /mammoth/html_generation.py | |
| parent | f5af218e186ff49e0c277f75668c1256be9cd861 (diff) | |
Add attributes to self-closing tags
Diffstat (limited to 'mammoth/html_generation.py')
| -rw-r--r-- | mammoth/html_generation.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/mammoth/html_generation.py b/mammoth/html_generation.py index 22db85e..37d191a 100644 --- a/mammoth/html_generation.py +++ b/mammoth/html_generation.py @@ -23,8 +23,9 @@ class HtmlGenerator(object): while self._stack: self.end() - def self_closing(self, name): - self._fragments.append("<{0} />".format(name)) + def self_closing(self, name, attributes=None): + attribute_string = _generate_attribute_string(attributes) + self._fragments.append("<{0}{1} />".format(name, attribute_string)) def _write_all(self): for element in self._stack: @@ -47,3 +48,13 @@ class _Element(object): def _escape_html(text): return cgi.escape(text, quote=True) + + +def _generate_attribute_string(attributes): + if attributes is None: + return "" + else: + return "".join( + ' {0}="{1}"'.format(key, value) + for key, value in attributes.iteritems() + ) |
