Skip to content

Commit bd1be95

Browse files
committed
fix ep export
1 parent 6517c35 commit bd1be95

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

eval_protocol/cli_commands/export_docs.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@
1313
logger = logging.getLogger(__name__)
1414

1515

16+
def _escape_mdx_text(text: str) -> str:
17+
"""
18+
Escape text that will be emitted as the *children* of an MDX/JSX component.
19+
20+
In MDX, `{` and `}` can start JS expressions even in otherwise plain text,
21+
which can break parsing when help strings include JSON examples.
22+
"""
23+
if not text:
24+
return ""
25+
# IMPORTANT: escape '&' first to avoid double-escaping.
26+
return (
27+
text.replace("&", "&")
28+
.replace("<", "&lt;")
29+
.replace(">", "&gt;")
30+
.replace("{", "&#123;")
31+
.replace("}", "&#125;")
32+
)
33+
34+
1635
def _get_parser_info(parser: argparse.ArgumentParser, subparser_help: str = "") -> Dict:
1736
"""Extract information from an ArgumentParser."""
1837
info = {
@@ -110,10 +129,19 @@ def _format_argument_item(arg: Dict) -> List[str]:
110129
if arg["required"]:
111130
attrs.append("required")
112131

113-
# Build description with short alias mention
114-
help_text = (arg["help"] or "").replace("<", "&lt;").replace(">", "&gt;")
115-
if short_opts:
116-
alias_note = f"Short: `{short_opts[0]}`"
132+
# Build description with alias mention (short + additional long aliases)
133+
help_text = _escape_mdx_text(arg["help"] or "")
134+
135+
aliases: List[str] = []
136+
if arg["option_strings"]:
137+
aliases = [o for o in arg["option_strings"] if o != primary]
138+
139+
if aliases:
140+
# Put long aliases first, then short ones for readability.
141+
long_aliases = [a for a in aliases if a.startswith("--")]
142+
short_aliases = [a for a in aliases if not a.startswith("--")]
143+
aliases_fmt = ", ".join([f"`{a}`" for a in (long_aliases + short_aliases)])
144+
alias_note = f"Aliases: {aliases_fmt}"
117145
if help_text:
118146
help_text = f"{help_text} ({alias_note})"
119147
else:

0 commit comments

Comments
 (0)