diff options
Diffstat (limited to 'sphinx/writers/texinfo.py')
-rw-r--r-- | sphinx/writers/texinfo.py | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index 7032c65..6e0a7de 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -96,7 +96,8 @@ def find_subsections(section: Element) -> list[nodes.section]: def smart_capwords(s: str, sep: str | None = None) -> str: """Like string.capwords() but does not capitalize words that already - contain a capital letter.""" + contain a capital letter. + """ words = s.split(sep) for i, word in enumerate(words): if all(x.islower() for x in word): @@ -106,6 +107,7 @@ def smart_capwords(s: str, sep: str | None = None) -> str: class TexinfoWriter(writers.Writer): """Texinfo writer for generating Texinfo documents.""" + supported = ('texinfo', 'texi') settings_spec: tuple[str, Any, tuple[tuple[str, list[str], dict[str, str]], ...]] = ( @@ -255,7 +257,8 @@ class TexinfoTranslator(SphinxTranslator): def collect_node_names(self) -> None: """Generates a unique id for each section. - Assigns the attribute ``node_name`` to each section.""" + Assigns the attribute ``node_name`` to each section. + """ def add_node_name(name: str) -> str: node_id = self.escape_id(name) @@ -278,7 +281,7 @@ class TexinfoTranslator(SphinxTranslator): for name, content in self.indices] # each section is also a node for section in self.document.findall(nodes.section): - title = cast(nodes.TextElement, section.next_node(nodes.Titular)) + title = cast(nodes.TextElement, section.next_node(nodes.Titular)) # type: ignore[type-var] name = title.astext() if title else '<untitled>' section['node_name'] = add_node_name(name) @@ -288,7 +291,7 @@ class TexinfoTranslator(SphinxTranslator): targets: list[Element] = [self.document] targets.extend(self.document.findall(nodes.section)) for node in targets: - assert 'node_name' in node and node['node_name'] # NoQA: PT018 + assert node.get('node_name', False) entries = [s['node_name'] for s in find_subsections(node)] node_menus[node['node_name']] = entries # try to find a suitable "Top" node @@ -352,7 +355,8 @@ class TexinfoTranslator(SphinxTranslator): def escape_arg(self, s: str) -> str: """Return an escaped string suitable for use as an argument - to a Texinfo command.""" + to a Texinfo command. + """ s = self.escape(s) # commas are the argument delimiters s = s.replace(',', '@comma{}') @@ -430,7 +434,7 @@ class TexinfoTranslator(SphinxTranslator): entries = self.node_menus[name] if not entries: return - self.body.append(f'\n{self.escape(self.node_names[name], )}\n\n') + self.body.append(f'\n{self.escape(self.node_names[name])}\n\n') self.add_menu_entries(entries) for subentry in entries: _add_detailed_menu(subentry) @@ -524,7 +528,7 @@ class TexinfoTranslator(SphinxTranslator): try: sid = self.short_ids[id] except KeyError: - sid = hex(len(self.short_ids))[2:] + sid = f'{len(self.short_ids):x}' self.short_ids[id] = sid return sid @@ -1287,11 +1291,10 @@ class TexinfoTranslator(SphinxTranslator): def visit_productionlist(self, node: Element) -> None: self.visit_literal_block(None) - names = [] productionlist = cast(Iterable[addnodes.production], node) - for production in productionlist: - names.append(production['tokenname']) + names = (production['tokenname'] for production in productionlist) maxlen = max(len(name) for name in names) + for production in productionlist: if production['tokenname']: for id in production.get('ids'): |