From 39cf6537c69d5b62362fd0fa7b382e7cded718b9 Mon Sep 17 00:00:00 2001
From: milde
Date: Thu, 30 Jan 2020 00:45:02 +0000
Subject: html5: support and tags.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@8476 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
---
.../docutils/writers/html5_polyglot/__init__.py | 23 +++++++++++++++++++++-
.../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('
\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.
ins
Additions
-This text has "always" been here. This text has been inserted.
-
+
This text has "always" been here. This text has been inserted.
+
This paragraph has been inserted.
-
+
del
Removed content
-This text has been deleted, here is the rest of the paragraph.
-
+
This text has been deleted, here is the rest of the paragraph.
+
This paragraph has been deleted.
-
+
--
cgit v1.2.1