From 4758ee1ed18769150fd69679c9a41fb479f31335 Mon Sep 17 00:00:00 2001 From: Daniel Ari Friedman <6911384+docxology@users.noreply.github.com> Date: Thu, 12 Nov 2026 04:58:07 -0800 Subject: [PATCH] fix(archive): match reference-link definitions on every line The refactor into archive_checks.py dropped re.MULTILINE from REFERENCE_LINK, so a reference definition such as '[appendix]: missing.md' below the first line stopped being checked while the docs and the module docstring still promised reference-style links were covered. Restore the flag and the pre-refactor semantics, and cover both directions with regression tests (an unresolved definition below a heading, and a resolving one). --- .github/scripts/archive_checks.py | 2 +- .github/scripts/tests/test_gate.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/scripts/archive_checks.py b/.github/scripts/archive_checks.py index 79ed36b..0091e92 100755 --- a/.github/scripts/archive_checks.py +++ b/.github/scripts/archive_checks.py @@ -25,7 +25,7 @@ from urllib.parse import unquote INLINE_LINK = re.compile(r"!?\[[^\]]*\]\(([^)]+)\)") -REFERENCE_LINK = re.compile(r"^\[[^\]]+\]:\s*(\S+)") +REFERENCE_LINK = re.compile(r"^\[[^\]]+\]:\s*(\S+)", re.MULTILINE) EXTERNAL_TARGET = re.compile(r"^[a-zA-Z][a-zA-Z0-9+.-]*:") CHECKPOINT = re.compile(r"(^|/)\.ipynb_checkpoints/") diff --git a/.github/scripts/tests/test_gate.py b/.github/scripts/tests/test_gate.py index 2087bee..26f6135 100644 --- a/.github/scripts/tests/test_gate.py +++ b/.github/scripts/tests/test_gate.py @@ -83,6 +83,31 @@ def test_escaping_target_is_reported(self) -> None: finally: outside.unlink() + def test_reference_definition_below_first_line_is_checked(self) -> None: + page = self.write( + "docs/page.md", + "# Guide\n" + "\n" + "See [the appendix][appendix].\n" + "\n" + "[appendix]: missing.md\n", + ) + errors = archive_checks.check_links([page], self.root) + self.assertEqual(len(errors), 1) + self.assertIn("docs/page.md: missing link target: missing.md", errors[0]) + + def test_resolving_reference_definition_passes(self) -> None: + self.write("docs/appendix.md", "# appendix\n") + page = self.write( + "docs/page.md", + "# Guide\n" + "\n" + "See [the appendix][appendix].\n" + "\n" + "[appendix]: appendix.md\n", + ) + self.assertEqual(archive_checks.check_links([page], self.root), []) + def test_non_markdown_files_are_skipped(self) -> None: script = self.write("docs/note.txt", "[gone](does-not-exist.md)\n") self.assertEqual(archive_checks.check_links([script], self.root), [])