From 72229119a3e056ac41e7a2aea787be8bf3bec54e Mon Sep 17 00:00:00 2001 From: L4XB Date: Fri, 23 Oct 2026 01:24:15 +0200 Subject: [PATCH] fix(docs-governance): ignore link-shaped text inside HTML comments The audit read links inside comments, so a commented-out link to a removed or planned page was reported as a broken Markdown link. Blank out closed HTML comments after code is removed, the same way code examples are already skipped; an opener without a closer stays literal text, as in CommonMark. The three copies of markdown_links.py stay identical, and the skill trigger manifest's registry binding is refreshed for the changed skill files. --- .../docs-governance/scripts/markdown_links.py | 24 ++++++++++++++++++- manifests/context-packs/skill-triggers@1.json | 2 +- .../docs-governance/scripts/markdown_links.py | 24 ++++++++++++++++++- .../docs-governance/scripts/markdown_links.py | 24 ++++++++++++++++++- tests/test_docs_governance_audit.py | 14 +++++++++++ 5 files changed, 84 insertions(+), 4 deletions(-) diff --git a/.agents/skills/docs-governance/scripts/markdown_links.py b/.agents/skills/docs-governance/scripts/markdown_links.py index bb4612469..05ebb3423 100644 --- a/.agents/skills/docs-governance/scripts/markdown_links.py +++ b/.agents/skills/docs-governance/scripts/markdown_links.py @@ -74,6 +74,28 @@ def without_inline_code(text: str) -> str: return "".join(output) +def without_html_comments(text: str) -> str: + """Blank out HTML comments, where link-shaped text is not a link. + + A comment runs from `` after it (`` and `` included). An + opener with no closer is left alone, as CommonMark leaves it literal text inline. + """ + output: list[str] = [] + cursor = 0 + while True: + start = text.find("", start + 2) + if end == -1: + break + output.append(text[cursor:start]) + output.append(re.sub(r"[^\n]", " ", text[start : end + 3])) + cursor = end + 3 + output.append(text[cursor:]) + return "".join(output) + + def inline_link_targets(text: str) -> list[str]: targets: list[str] = [] matches = list(INLINE_LINK_START_RE.finditer(text)) @@ -173,7 +195,7 @@ def reference_link_targets(text: str) -> list[str]: def markdown_link_targets(text: str) -> list[str]: - text = without_inline_code(without_fenced_code(text)) + text = without_html_comments(without_inline_code(without_fenced_code(text))) return inline_link_targets(text) + reference_link_targets(text) diff --git a/manifests/context-packs/skill-triggers@1.json b/manifests/context-packs/skill-triggers@1.json index a49a8c824..edcb97000 100644 --- a/manifests/context-packs/skill-triggers@1.json +++ b/manifests/context-packs/skill-triggers@1.json @@ -10,7 +10,7 @@ "id": "hand-seeded", "source": "manual-curation-pending-regeneration" }, - "registryDigest": "498caee2738006d64530e9be34883111cf67742d8c4389f39d61299e1a1c4400", + "registryDigest": "26e3471f7d97e474b311e1cc45c3d967f5be98fca09f264a8cfd8de33ac1158d", "schemaVersion": 1, "triggers": { "skill:agent-runtime-gateway-smoke-test": [ diff --git a/pi/core/skills/docs-governance/scripts/markdown_links.py b/pi/core/skills/docs-governance/scripts/markdown_links.py index bb4612469..05ebb3423 100644 --- a/pi/core/skills/docs-governance/scripts/markdown_links.py +++ b/pi/core/skills/docs-governance/scripts/markdown_links.py @@ -74,6 +74,28 @@ def without_inline_code(text: str) -> str: return "".join(output) +def without_html_comments(text: str) -> str: + """Blank out HTML comments, where link-shaped text is not a link. + + A comment runs from `` after it (`` and `` included). An + opener with no closer is left alone, as CommonMark leaves it literal text inline. + """ + output: list[str] = [] + cursor = 0 + while True: + start = text.find("", start + 2) + if end == -1: + break + output.append(text[cursor:start]) + output.append(re.sub(r"[^\n]", " ", text[start : end + 3])) + cursor = end + 3 + output.append(text[cursor:]) + return "".join(output) + + def inline_link_targets(text: str) -> list[str]: targets: list[str] = [] matches = list(INLINE_LINK_START_RE.finditer(text)) @@ -173,7 +195,7 @@ def reference_link_targets(text: str) -> list[str]: def markdown_link_targets(text: str) -> list[str]: - text = without_inline_code(without_fenced_code(text)) + text = without_html_comments(without_inline_code(without_fenced_code(text))) return inline_link_targets(text) + reference_link_targets(text) diff --git a/skills/docs-governance/scripts/markdown_links.py b/skills/docs-governance/scripts/markdown_links.py index bb4612469..05ebb3423 100644 --- a/skills/docs-governance/scripts/markdown_links.py +++ b/skills/docs-governance/scripts/markdown_links.py @@ -74,6 +74,28 @@ def without_inline_code(text: str) -> str: return "".join(output) +def without_html_comments(text: str) -> str: + """Blank out HTML comments, where link-shaped text is not a link. + + A comment runs from `` after it (`` and `` included). An + opener with no closer is left alone, as CommonMark leaves it literal text inline. + """ + output: list[str] = [] + cursor = 0 + while True: + start = text.find("", start + 2) + if end == -1: + break + output.append(text[cursor:start]) + output.append(re.sub(r"[^\n]", " ", text[start : end + 3])) + cursor = end + 3 + output.append(text[cursor:]) + return "".join(output) + + def inline_link_targets(text: str) -> list[str]: targets: list[str] = [] matches = list(INLINE_LINK_START_RE.finditer(text)) @@ -173,7 +195,7 @@ def reference_link_targets(text: str) -> list[str]: def markdown_link_targets(text: str) -> list[str]: - text = without_inline_code(without_fenced_code(text)) + text = without_html_comments(without_inline_code(without_fenced_code(text))) return inline_link_targets(text) + reference_link_targets(text) diff --git a/tests/test_docs_governance_audit.py b/tests/test_docs_governance_audit.py index 04c39dd73..073f4676b 100644 --- a/tests/test_docs_governance_audit.py +++ b/tests/test_docs_governance_audit.py @@ -266,6 +266,20 @@ def test_artifact_scope_ignores_links_inside_code_examples(project: Path) -> Non assert result.returncode == 0, result.stdout +def test_artifact_scope_ignores_links_inside_html_comments(project: Path) -> None: + (project / "guide.md").write_text( + "Intro text\n\n" + "\n\n" + " [after](missing-after.md)\n", + encoding="utf-8", + ) + result = run_audit(project, "artifacts") + assert result.returncode == 1 + assert "missing-inline.md" not in result.stdout + assert "missing-draft.md" not in result.stdout + assert "Broken Markdown link: 'guide.md' -> 'missing-after.md'" in result.stdout + + def test_artifact_scope_ignores_title_with_escaped_quotes(project: Path) -> None: (project / "guide.md").write_text("# Guide\n", encoding="utf-8") (project / "index.md").write_text(