diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2020-01-30 00:45:02 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2020-01-30 00:45:02 +0000 |
| commit | 39cf6537c69d5b62362fd0fa7b382e7cded718b9 (patch) | |
| tree | 8f95f6d29526fabc9d5bcc6aa8602e0642244c6a | |
| parent | 5a88602e966b7d8bf04193afb1e56261114ba3fe (diff) | |
| download | docutils-39cf6537c69d5b62362fd0fa7b382e7cded718b9.tar.gz | |
html5: support <ins> and <del> tags.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8476 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
| -rw-r--r-- | docutils/docutils/writers/html5_polyglot/__init__.py | 23 | ||||
| -rw-r--r-- | docutils/test/functional/expected/standalone_rst_html5.html | 12 |
2 files changed, 28 insertions, 7 deletions
diff --git a/docutils/docutils/writers/html5_polyglot/__init__.py b/docutils/docutils/writers/html5_polyglot/__init__.py index 5aa510357..d3064946e 100644 --- a/docutils/docutils/writers/html5_polyglot/__init__.py +++ b/docutils/docutils/writers/html5_polyglot/__init__.py @@ -182,6 +182,26 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): def depart_caption(self, node): self.body.append('</p>\n') + # use HTML block-level tags if matching class value found + supported_block_tags = set(('ins', 'del')) + def visit_container(self, node): + # If there is exactly one of the "supported block tags" in + # the list of class values, use it as tag name: + classes = node.get('classes', []) + tags = [cls for cls in classes + if cls in self.supported_block_tags] + if len(tags) == 1: + node.html5tagname = tags[0] + classes.remove(tags[0]) + else: + node.html5tagname = 'div' + self.body.append(self.starttag(node, node.html5tagname, + CLASS='docutils container')) + + def depart_container(self, node): + self.body.append('</%s>\n' % node.html5tagname) + + # no standard meta tag name in HTML5, use dcterms.rights # see https://wiki.whatwg.org/wiki/MetaExtensions def visit_copyright(self, node): @@ -273,7 +293,8 @@ class HTMLTranslator(writers._html_base.HTMLTranslator): # use HTML text-level tags if matching class value found supported_inline_tags = set(('small', 's', 'q', 'dfn', 'var', 'samp', - 'kbd', 'i', 'b', 'u', 'mark', 'bdi')) + 'kbd', 'i', 'b', 'u', 'mark', 'bdi', + 'ins', 'del')) def visit_inline(self, node): # If there is exactly one of the "supported inline tags" in # the list of class values, use it as tag name: diff --git a/docutils/test/functional/expected/standalone_rst_html5.html b/docutils/test/functional/expected/standalone_rst_html5.html index 821edcb4b..86382bac3 100644 --- a/docutils/test/functional/expected/standalone_rst_html5.html +++ b/docutils/test/functional/expected/standalone_rst_html5.html @@ -1548,19 +1548,19 @@ reStructuredText equivalents.</p> <dt>ins</dt> <dd><p>Additions <a class="footnote-reference brackets" href="#attribute-optional" id="footnote-reference-16">5</a></p> <blockquote> -<p>This text has "always" been here. <span class="ins">This text has been inserted.</span></p> -<div class="ins docutils container"> +<p>This text has "always" been here. <ins>This text has been inserted.</ins></p> +<ins class="docutils container"> <p>This paragraph has been inserted.</p> -</div> +</ins> </blockquote> </dd> <dt>del</dt> <dd><p>Removed content <a class="footnote-reference brackets" href="#attribute-optional" id="footnote-reference-17">5</a></p> <blockquote> -<p><span class="del">This text has been deleted</span>, here is the rest of the paragraph.</p> -<div class="del docutils container"> +<p><del>This text has been deleted</del>, here is the rest of the paragraph.</p> +<del class="docutils container"> <p>This paragraph has been deleted.</p> -</div> +</del> </blockquote> </dd> </dl> |
