diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-12-23 19:54:35 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-12-23 19:54:35 +0300 |
commit | b5a9a056020e6bf5424a77a350b3204fd0e79a5a (patch) | |
tree | b17136105a8612ce3ddd0ff3dc850fbf2fc1b73f /sphinx/writers/texinfo.py | |
parent | f2dc8a999a589bc7a9a85f6f0dd5691aabc17062 (diff) | |
parent | 6ad6594ec73d44d51c18faf0f41dd92f958cc45b (diff) |
Merge branch '4.x' into drop-translator-specific-unknown_visit-calls
Diffstat (limited to 'sphinx/writers/texinfo.py')
-rw-r--r-- | sphinx/writers/texinfo.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index 539a72388..c764b3027 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -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 @@ -545,9 +546,12 @@ class TexinfoTranslator(SphinxTranslator): def add_xref(self, id: str, name: str, node: Node) -> None: name = self.escape_menu(name) sid = self.get_short_id(id) - self.body.append('@ref{%s,,%s}' % (sid, name)) - self.referenced_ids.add(sid) - self.referenced_ids.add(self.escape_id(id)) + if self.config.texinfo_cross_references: + self.body.append('@ref{%s,,%s}' % (sid, name)) + self.referenced_ids.add(sid) + self.referenced_ids.add(self.escape_id(id)) + else: + self.body.append(name) # -- Visiting @@ -809,15 +813,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: @@ -1223,7 +1235,11 @@ class TexinfoTranslator(SphinxTranslator): self.depart_topic(node) def visit_label(self, node: Element) -> None: - self.body.append('@w{(') + # label numbering is automatically generated by Texinfo + if self.in_footnote: + raise nodes.SkipNode + else: + self.body.append('@w{(') def depart_label(self, node: Element) -> None: self.body.append(')} ') |