Skip to content

Commit

Permalink
HTML5 writer: use "figcaption" only for captions nested in a figure.
Browse files Browse the repository at this point in the history
Third-party applications may (ab)use the "caption" element
for other purposes as a figure caption.

See sphinx-doc/sphinx#8870

git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk/docutils@8624 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
  • Loading branch information
Günter Milde committed Feb 13, 2021
1 parent 0efd8fc commit 452f43e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions docutils/writers/html5_polyglot/__init__.py
Expand Up @@ -183,13 +183,15 @@ def visit_authors(self, node):
def depart_authors(self, node):
self.depart_docinfo_item()

# don't add 'caption' class value
# use the <figcaption> semantic tag.
def visit_caption(self, node):
self.body.append('<figcaption>\n')
if isinstance(node.parent, nodes.figure):
self.body.append('<figcaption>\n')
self.body.append(self.starttag(node, 'p', ''))

def depart_caption(self, node):
self.body.append('</p>\n')
# <figcaption> is closed in depart_figure(), as legend may follow.

# use HTML block-level tags if matching class value found
supported_block_tags = set(('ins', 'del'))
Expand Down Expand Up @@ -305,8 +307,7 @@ def depart_header(self, node):
'bdi', 'del', 'ins', 'mark', 'small',
'b', 'i', 'q', 's', 'u'))
def visit_inline(self, node):
# Use "supported inline tag" as tag name if found in class values
# (first:
# Use `supported_inline_tags` if found in class values
classes = node.get('classes', [])
tags = [cls for cls in self.supported_inline_tags
if cls in classes]
Expand Down

0 comments on commit 452f43e

Please sign in to comment.