Skip to content

Commit

Permalink
texinfo: fix emission of @footnote directives.
Browse files Browse the repository at this point in the history
Right now, labels are emitted as part of a @footnote directive.
That results in e.g.

Note1: (@footnote{@w{(1)}
Future versions of GCC may zero-extend...
})

which is incorrect and should be rather:

Note1: (@footnote{Future versions of GCC may zero-extend...})
  • Loading branch information
marxin committed Jun 30, 2021
1 parent 805fd98 commit 61f839c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sphinx/writers/texinfo.py
Expand Up @@ -761,10 +761,12 @@ def visit_title_reference(self, node: Element) -> None:
# -- Blocks

def visit_paragraph(self, node: Element) -> None:
self.body.append('\n')
if not self.in_footnote:
self.body.append('\n')

def depart_paragraph(self, node: Element) -> None:
self.body.append('\n')
if not self.in_footnote:
self.body.append('\n')

def visit_block_quote(self, node: Element) -> None:
self.body.append('\n@quotation\n')
Expand Down Expand Up @@ -1223,7 +1225,10 @@ def depart_sidebar(self, node: Element) -> None:
self.depart_topic(node)

def visit_label(self, node: Element) -> None:
self.body.append('@w{(')
if self.in_footnote:
raise nodes.SkipNode
else:
self.body.append('@w{(')

def depart_label(self, node: Element) -> None:
self.body.append(')} ')
Expand Down
8 changes: 8 additions & 0 deletions tests/test_build_texinfo.py
Expand Up @@ -112,3 +112,11 @@ def test_texinfo_escape_id(app, status, warning):
assert translator.escape_id('Hello(world)') == 'Hello world'
assert translator.escape_id('Hello world.') == 'Hello world'
assert translator.escape_id('.') == '.'

@pytest.mark.sphinx('texinfo', testroot='footnotes')
def test_texinfo_footnote(app, status, warning):
app.builder.build_all()

output = (app.outdir / 'python.texi').read_text()
assert '@footnote{@w{' not in output
assert 'First footnote: @footnote{First}' in output

0 comments on commit 61f839c

Please sign in to comment.