From eeef10aeb28dc75e035e3fb56f7de92f622beaef Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 5 Dec 2026 06:48:56 -0800 Subject: [PATCH] fix(block-ci): mask code spans that wrap lines before matching links Co-Authored-By: Claude Opus 5.5 --- .github/block/scripts/doc-links-check-test.py | 5 ++++- .github/block/scripts/doc-links-check.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/block/scripts/doc-links-check-test.py b/.github/block/scripts/doc-links-check-test.py index c6543d650e..ef5a2a62b9 100644 --- a/.github/block/scripts/doc-links-check-test.py +++ b/.github/block/scripts/doc-links-check-test.py @@ -64,6 +64,9 @@ class DocLinksTests(unittest.TestCase): "", "see the [wrapped", "label](wrapped.md) here", + "", + "`[wrapped", + "code](gone.md)` then [after](after.md)", "````md", "```", "[example](missing.md)", @@ -71,7 +74,7 @@ class DocLinksTests(unittest.TestCase): "````", ]) + "\n") broken = [(line, target) for _, line, target in links.broken_links(root)] - self.assertEqual(broken, [(1, "guide(v1).md"), (3, "wrapped.md")]) + self.assertEqual(broken, [(1, "guide(v1).md"), (3, "wrapped.md"), (7, "after.md")]) def test_main_exit_status(self): out = io.StringIO() diff --git a/.github/block/scripts/doc-links-check.py b/.github/block/scripts/doc-links-check.py index 409c4b122d..693ab5fc04 100644 --- a/.github/block/scripts/doc-links-check.py +++ b/.github/block/scripts/doc-links-check.py @@ -10,7 +10,7 @@ import urllib.parse SKIP_DIRS = {".git", "node_modules", "vendor"} FENCE = re.compile(r"^\s*(`{3,}|~{3,})(.*)$") -INLINE_CODE = re.compile(r"(`+)(?:(?!\1).)+?\1") +INLINE_CODE = re.compile(r"(`+)(?:(?!\1).)+?\1", re.S) INLINE_LINK = re.compile(r"!?\[(?:[^\[\]]|\[[^\[\]]*\])*\]\(\s*(<[^>\n]*>|(?:[^\s()]|\([^\s()]*\))+)") REFERENCE = re.compile(r"^[ \t]{0,3}\[[^\]]+\]:\s*(<[^>]*>|\S+)", re.M) SCHEME = re.compile(r"^[A-Za-z][A-Za-z0-9+.-]*:") @@ -18,7 +18,7 @@ SCHEME = re.compile(r"^[A-Za-z][A-Za-z0-9+.-]*:") def paragraph_targets(first, lines): # A link label may wrap, so links are matched per paragraph. - text = INLINE_CODE.sub("", "\n".join(lines)) + text = INLINE_CODE.sub(lambda m: "\n" * m.group().count("\n"), "\n".join(lines)) found = [(m.start(), m.group(1)) for regex in (INLINE_LINK, REFERENCE) for m in regex.finditer(text)] for pos, target in sorted(found): yield first + text.count("\n", 0, pos), target