Skip to content

Commit d2612da

Browse files
committed
docs(sphinx_argparse_neo[renderer]) Escape asterisks in quoted strings
why: Glob patterns like "django-*" in help text contain asterisks that RST interprets as starting emphasis, causing rendering issues in docs. what: - Add _escape_glob_asterisks() to escape * inside double-quoted strings - Call it in _parse_text() before RST/MyST parsing
1 parent c076030 commit d2612da

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/_ext/sphinx_argparse_neo/renderer.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from __future__ import annotations
88

99
import dataclasses
10+
import re
1011
import typing as t
1112

1213
from docutils import nodes
@@ -465,6 +466,28 @@ def post_process(self, result_nodes: list[nodes.Node]) -> list[nodes.Node]:
465466
"""
466467
return result_nodes
467468

469+
def _escape_glob_asterisks(self, text: str) -> str:
470+
"""Escape asterisks inside double-quoted strings to prevent RST emphasis.
471+
472+
Glob patterns like "django-*" contain asterisks that RST interprets as
473+
starting emphasis. This escapes them only within quoted content.
474+
475+
Parameters
476+
----------
477+
text : str
478+
Text that may contain quoted glob patterns.
479+
480+
Returns
481+
-------
482+
str
483+
Text with asterisks escaped inside double-quoted strings.
484+
"""
485+
return re.sub(
486+
r'"([^"]*)"',
487+
lambda m: '"' + m.group(1).replace("*", r"\*") + '"',
488+
text,
489+
)
490+
468491
def _parse_text(self, text: str) -> list[nodes.Node]:
469492
"""Parse text as RST or MyST content.
470493
@@ -481,6 +504,9 @@ def _parse_text(self, text: str) -> list[nodes.Node]:
481504
if not text:
482505
return []
483506

507+
# Escape asterisks in quoted strings to prevent RST emphasis issues
508+
text = self._escape_glob_asterisks(text)
509+
484510
if self.state is None:
485511
# No state machine available, return as paragraph
486512
para = nodes.paragraph(text=text)

0 commit comments

Comments
 (0)