expand abbreviations from a definition line

`*[TERM]: expansion` on its own line, PHP Markdown Extra's form, and every
whole-word use in the document becomes <abbr title="…">.

A transformer rather than an inline parser, because a definition may appear
after the use it explains and a parser only ever sees what it has already read.
A block parser rather than a pattern found later, because the line has to stop
being content — an author would notice that going wrong before anything else.

Whole-word matching is the part that would have bitten: without it a definition
of HTML quietly rewrites HTMLish and xHTML too, so both have cases. Code spans,
autolinks, raw HTML and an already-expanded term are skipped, the longest
definition wins where two could match, and the expansion is escaped into the
attribute so a quoted phrase cannot end it.

Definitions are document-scoped. A term defined in a page does not reach an
included fragment, which is parsed on its own bytes exactly as footnotes are —
stated in content-model.md rather than left to be discovered.

The nesting gate caught firstMatch four levels deep; the inner search is its own
function now, which reads better than it did before the warning.

core 2794/2800, ext 1483/2000, 34 gates green, 0 warnings.
This commit is contained in:
Claude Opus 5
2026-08-01 21:25:44 +06:00
committed by bdeshi
parent 53e9ef473a
commit 661fb469e8
10 changed files with 393 additions and 26 deletions
@@ -19,7 +19,9 @@ The page has a footnote of its own[^page], a table, a definition list and ~~a st
The notation marks cover what prose needs most often: the gauge measures H~2~O to about 10^-3^ m, and the
==important== column is the second. Where there is no mark for something, HTML does it: the reading is taken
with <kbd>Shift</kbd> held. Content in the site root is the author's own, so it renders rather than being
dropped.
dropped. Readings go to the NIWA archive, and the definition below expands every use of it.
*[NIWA]: National Institute of Water and Atmospheric Research
| Gauge | Reading | Note |
|-------|---------|------|