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.
This commit is contained in:
L4XB committed 2026-10-23 01:24:15 +02:00
1 parent 90606c8315
commit 72229119a3
5 files changed
+84 -4

No files matched your search

@@ -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 `<!--` to the first `-->` 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("<!--", cursor)
if start == -1:
break
end = 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)
@@ -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": [
@@ -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 `<!--` to the first `-->` 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("<!--", cursor)
if start == -1:
break
end = 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)
@@ -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 `<!--` to the first `-->` 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("<!--", cursor)
if start == -1:
break
end = 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)
+14
View File
@@ -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 <!-- [old](missing-inline.md) --> text\n\n"
"<!--\nSee [draft](missing-draft.md).\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(