mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-28 06:51:16 +08:00
fix(website): auto-wrap ASCII-art code blocks in generated skill pages (#16497)
Defensive: when the generator encounters a fenced code block containing Unicode box-drawing characters, wrap it in `<!-- ascii-guard-ignore -->` markers so the docs-site-checks lint (which scans inside code fences) can't reject the page for a skill's own diagram. Plain bash/python code blocks stay uncluttered — only blocks with box chars get wrapped. Skill authors no longer have to remember to add the ignore markers in every SKILL.md with ASCII art. Fixes #15305.
This commit is contained in:
@@ -38,6 +38,31 @@ HAND_WRITTEN = {"godmode.md", "google-workspace.md"}
|
||||
|
||||
_FENCE_RE = re.compile(r"^(?P<indent>\s*)(?P<fence>```+|~~~+)", re.MULTILINE)
|
||||
|
||||
# Unicode box-drawing characters. If a generated fenced code block contains any
|
||||
# of these, wrap it in `<!-- ascii-guard-ignore -->` so the docs-site-checks
|
||||
# lint (which scans inside code fences) can't reject the page for a skill's
|
||||
# own ASCII diagram. Skill authors shouldn't need to remember to add the
|
||||
# ignore markers in every SKILL.md — the generator handles it defensively.
|
||||
_BOX_DRAWING_CHARS = frozenset("┌┐└┘─│═║╔╗╚╝╠╣╦╩╬├┤┬┴┼╭╮╯╰▶◀▲▼")
|
||||
|
||||
|
||||
def _wrap_ascii_art_code_blocks(code_segment: str) -> str:
|
||||
"""Wrap a fenced code segment in ascii-guard-ignore markers if it contains
|
||||
box-drawing characters. No-op otherwise, so plain bash/python code blocks
|
||||
stay uncluttered.
|
||||
|
||||
Already-wrapped segments (the SKILL.md source added its own markers) are
|
||||
left alone — double-wrapping is harmless but we'd rather keep the output
|
||||
clean.
|
||||
"""
|
||||
if not any(ch in _BOX_DRAWING_CHARS for ch in code_segment):
|
||||
return code_segment
|
||||
return (
|
||||
"<!-- ascii-guard-ignore -->\n"
|
||||
f"{code_segment}\n"
|
||||
"<!-- ascii-guard-ignore-end -->"
|
||||
)
|
||||
|
||||
|
||||
def mdx_escape_body(body: str) -> str:
|
||||
"""Escape MDX-dangerous characters in markdown body, leaving fenced code blocks alone.
|
||||
@@ -194,7 +219,7 @@ def mdx_escape_body(body: str) -> str:
|
||||
processed: list[str] = []
|
||||
for kind, content in segments:
|
||||
if kind == "code":
|
||||
processed.append(content)
|
||||
processed.append(_wrap_ascii_art_code_blocks(content))
|
||||
else:
|
||||
processed.append(escape_text(content))
|
||||
return "\n".join(processed)
|
||||
|
||||
Reference in New Issue
Block a user