mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #9391 from marxin/info-samp-with-variable
texinfo: improve variable in :samp: directives
This commit is contained in:
commit
b232b00cf8
@ -194,6 +194,7 @@ class TexinfoTranslator(SphinxTranslator):
|
||||
self.curfilestack: List[str] = []
|
||||
self.footnotestack: List[Dict[str, List[Union[collected_footnote, bool]]]] = [] # NOQA
|
||||
self.in_footnote = 0
|
||||
self.in_samp = 0
|
||||
self.handled_abbrs: Set[str] = set()
|
||||
self.colwidths: List[int] = None
|
||||
|
||||
@ -809,15 +810,23 @@ class TexinfoTranslator(SphinxTranslator):
|
||||
self.body.append('}')
|
||||
|
||||
def visit_emphasis(self, node: Element) -> None:
|
||||
self.body.append('@emph{')
|
||||
element = 'emph' if not self.in_samp else 'var'
|
||||
self.body.append('@%s{' % element)
|
||||
|
||||
def depart_emphasis(self, node: Element) -> None:
|
||||
self.body.append('}')
|
||||
|
||||
def is_samp(self, node: Element) -> bool:
|
||||
return 'samp' in node['classes']
|
||||
|
||||
def visit_literal(self, node: Element) -> None:
|
||||
if self.is_samp(node):
|
||||
self.in_samp += 1
|
||||
self.body.append('@code{')
|
||||
|
||||
def depart_literal(self, node: Element) -> None:
|
||||
if self.is_samp(node):
|
||||
self.in_samp -= 1
|
||||
self.body.append('}')
|
||||
|
||||
def visit_superscript(self, node: Element) -> None:
|
||||
|
@ -112,3 +112,14 @@ 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='root')
|
||||
def test_texinfo_samp_with_variable(app, status, warning):
|
||||
app.build()
|
||||
|
||||
output = (app.outdir / 'sphinxtests.texi').read_text()
|
||||
|
||||
assert '@code{@var{variable_only}}' in output
|
||||
assert '@code{@var{variable} and text}' in output
|
||||
assert '@code{Show @var{variable} in the middle}' in output
|
||||
|
Loading…
Reference in New Issue
Block a user