fix(okf-check): treat a cite line range as a reading aid, not a symbol

A `path:92-97` cite fell through the `isdigit()` suffix rule and was
matched as a literal symbol, so it could never resolve. Line ranges are
the same reading aid a bare line number is, and are idiomatic in this
repo prose, so the grammar now admits `N` and `N-M` alike.
This commit is contained in:
Łukasz Boryń 2026-07-22 14:05:19 +02:00
parent 6cb19302ea
commit aa61a3f51f
2 changed files with 6 additions and 4 deletions

View File

@ -47,7 +47,8 @@ loop, not on disk.
`path:symbol`; all three resolve only if the path exists. `path:symbol` `path:symbol`; all three resolve only if the path exists. `path:symbol`
additionally needs the symbol as a literal substring of the file — that additionally needs the symbol as a literal substring of the file — that
is the shape that breaks when the thing it cites moves. A `path:line` is the shape that breaks when the thing it cites moves. A `path:line`
number is a reading aid, never validated. suffix — one number or a `92-97` range — is a reading aid, never
validated.
- **Derived zone** — a page carries at most one region delimited by - **Derived zone** — a page carries at most one region delimited by
`<!-- okf:derived begin -->` and `<!-- okf:derived end -->`, each marker `<!-- okf:derived begin -->` and `<!-- okf:derived end -->`, each marker
alone on its line. Refresh regenerates the inside wholesale and may not alone on its line. Refresh regenerates the inside wholesale and may not

View File

@ -17,6 +17,7 @@ import sys
from pathlib import Path from pathlib import Path
CAP = 110 CAP = 110
LINE_SUFFIX = re.compile(r"\d+(-\d+)?")
def frontmatter(text): def frontmatter(text):
@ -94,14 +95,14 @@ def cite_resolves(cite, page, okf):
"""`path` and `path:line` need the path; `path:symbol` needs both. """`path` and `path:line` need the path; `path:symbol` needs both.
The symbol is matched as a literal substring — no language awareness, The symbol is matched as a literal substring — no language awareness,
no tags file. A `:suffix` that parses as an integer is a reading aid, no tags file. A `:suffix` that is a line number or a line range is a
never validated: a check that cannot fail is not a check. reading aid, never validated: a check that cannot fail is not a check.
""" """
path, _, symbol = cite.split("#")[0].partition(":") path, _, symbol = cite.split("#")[0].partition(":")
path, symbol = path.strip(), symbol.strip() path, symbol = path.strip(), symbol.strip()
if not path: if not path:
return False return False
if symbol.isdigit(): if LINE_SUFFIX.fullmatch(symbol):
symbol = "" symbol = ""
for root in (page.parent, okf, okf.parent): for root in (page.parent, okf, okf.parent):
target = root / path target = root / path