Skip to content

Commit

Permalink
Fix sphinx-doc#9330: versionchanged causes error during pdf build
Browse files Browse the repository at this point in the history
The versionchanged directive breaks doctree if its contents start with
non-paragraph element (ex. lists, tables, and so on).  It causes build
error in LaTeX.

This inserts a paragraph if the first child of the contents is not a
paragraph not to break doctree.
  • Loading branch information
tk0miya committed Jun 13, 2021
1 parent e05cef5 commit 23a4fa0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -71,6 +71,8 @@ Bugs fixed
:confval:`man_make_section_directory` is not correct
* #9306: Linkcheck reports broken link when remote server closes the connection
on HEAD request
* #9330: changeset domain: :rst:dir:`versionchanged` with contents being a list
will cause error during pdf build
* #9280: py domain: "exceptions" module is not displayed
* #9224: ``:param:`` and ``:type:`` fields does not support a type containing
whitespace (ex. ``Dict[str, str]``)
Expand Down
16 changes: 12 additions & 4 deletions sphinx/domains/changeset.py
Expand Up @@ -74,8 +74,10 @@ def run(self) -> List[Node]:
if self.content:
self.state.nested_parse(self.content, self.content_offset, node)
classes = ['versionmodified', versionlabel_classes[self.name]]
if len(node):
if isinstance(node[0], nodes.paragraph) and node[0].rawsource:
if len(node) > 0 and isinstance(node[0], nodes.paragraph):
# the content starts with a paragraph
if node[0].rawsource:
# make the first paragraph translatable
content = nodes.inline(node[0].rawsource, translatable=True)
content.source = node[0].source
content.line = node[0].line
Expand All @@ -84,10 +86,16 @@ def run(self) -> List[Node]:

para = cast(nodes.paragraph, node[0])
para.insert(0, nodes.inline('', '%s: ' % text, classes=classes))
elif len(node) > 0:
# the content does not starts with a paragraph
para = nodes.paragraph('', '',
nodes.inline('', '%s: ' % text, classes=classes),
translatable=False)
node.insert(0, para)
else:
# the content is empty
para = nodes.paragraph('', '',
nodes.inline('', '%s.' % text,
classes=classes),
nodes.inline('', '%s.' % text, classes=classes),
translatable=False)
node.append(para)

Expand Down

0 comments on commit 23a4fa0

Please sign in to comment.