Skip to content

Support opt-in template transclusion on Markdown pages#16

Merged
JeroenDeDauw merged 2 commits into
masterfrom
feature/template-transclusion
Jul 6, 2026
Merged

Support opt-in template transclusion on Markdown pages#16
JeroenDeDauw merged 2 commits into
masterfrom
feature/template-transclusion

Conversation

@JeroenDeDauw

Copy link
Copy Markdown
Member

For #4

Add $wgNativeMarkdownTemplateTransclusion (default false). When on, {{...}}
on Markdown pages expands via MediaWiki's parser, so infobox, citation and
navbox templates render with dependency tracking (editing a template reparses
the pages using it), recursion/size limits, and wikitext-level sanitization.
Own-line calls render as block HTML (infoboxes are not paragraph-wrapped and
may span multiple lines); inline calls render within text. The pure Application
layer stays MediaWiki-free behind a TemplateExpander port; the adapter reuses
one parser per render and merges each child ParserOutput into the page.

Delegating to the parser also enables parser functions and magic words inside
the braces, amending the SPEC's "no parser functions or magic words" non-goal
(approved when directing this build). Deferred, and documented in the README:
<ref>/<references/> in the Markdown body and cross-call citation state,
{{:MarkdownPage}} full-page transclusion, and subst.

Built at @JeroenDeDauw's direction: design-first, with two independent Fable design reviews before implementation, and amending the SPEC's no-parser-functions decision per his go-ahead. Context: the NativeMarkdown codebase and the MediaWiki 1.43 parser APIs verified against core.
Written by Claude Code, Opus 4.8 (max)

JeroenDeDauw and others added 2 commits July 6, 2026 02:57
For #4

Add $wgNativeMarkdownTemplateTransclusion (default false). When on, `{{...}}`
on Markdown pages expands via MediaWiki's parser, so infobox, citation and
navbox templates render with dependency tracking (editing a template reparses
the pages using it), recursion/size limits, and wikitext-level sanitization.
Own-line calls render as block HTML (infoboxes are not paragraph-wrapped and
may span multiple lines); inline calls render within text. The pure Application
layer stays MediaWiki-free behind a TemplateExpander port; the adapter reuses
one parser per render and merges each child ParserOutput into the page.

Delegating to the parser also enables parser functions and magic words inside
the braces, amending the SPEC's "no parser functions or magic words" non-goal
(approved when directing this build). Deferred, and documented in the README:
`<ref>`/`<references/>` in the Markdown body and cross-call citation state,
`{{:MarkdownPage}}` full-page transclusion, and subst.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Addresses findings from a self-review of the transclusion PR:

- registerSections now authoritatively rebuilds the table of contents from the
  page's own markdown headings, overwriting any TOCData/SHOW_TOC a transcluded
  template merged in. This fixes template headings leaking into the ToC of a
  page that has no headings of its own.
- Extract TemplateBraces (matchLeadingCall + depthDelta) as the single balanced
  `{{...}}` definition shared by the inline and block parsers, replacing the
  duplicated brace scans.
- Strengthen tests: block calls keep their paragraph while inline calls strip
  it; `{{...}}` in a GFM table cell with an escaped pipe; the ToC stays clean
  when the page's only content is a heading-bearing template.
- README: note that an unclosed block `{{` renders as literal text to page end.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@JeroenDeDauw JeroenDeDauw marked this pull request as ready for review July 6, 2026 13:35
@JeroenDeDauw JeroenDeDauw merged commit a8c5c6b into master Jul 6, 2026
12 checks passed
@JeroenDeDauw JeroenDeDauw deleted the feature/template-transclusion branch July 6, 2026 13:35
JeroenDeDauw added a commit that referenced this pull request Jul 6, 2026
Follows-up to #16

Flip $wgNativeMarkdownTemplateTransclusion to true. $wgNativeMarkdownEverywhere
already defaults to true, so out of the box every prose page is Markdown; with
transclusion off, shared infoboxes, navboxes and citation templates render as
literal {{...}} across the wiki. Turning it on completes the wiki integration
with no cost to the AI story (action=raw still returns literal {{...}}) or to
safety (parser output is sanitized as on any wikitext page).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant