Unlike most Wikidot constructs that are handled during AST parsing, include
directives are resolved as a text-level macro expansion BEFORE the main parse.
This is necessary because included content may contain partial block structures
(e.g., an opening [[div]] tag in one include and its closing [[/div]] in
another) that must be visible to the parser as a single continuous text.
The resolution process follows Wikidot's iterative (do-while) approach:
Scan the entire source text for [[include page | var=val]] patterns
Replace ALL matches in one pass (each fetched, variable-substituted)
Compare the result with the previous source
Repeat until no changes occur or maxIterations is reached
This differs from a DFS recursive approach: each iteration expands one
"layer" of includes across the whole source, rather than drilling into
each include immediately. This allows patterns like inc-loop (where the
same page is included with different variables across iterations) to work.
Text-level expansion of
[[include]]directives.Unlike most Wikidot constructs that are handled during AST parsing, include directives are resolved as a text-level macro expansion BEFORE the main parse. This is necessary because included content may contain partial block structures (e.g., an opening
[[div]]tag in one include and its closing[[/div]]in another) that must be visible to the parser as a single continuous text.The resolution process follows Wikidot's iterative (do-while) approach:
[[include page | var=val]]patternsmaxIterationsis reachedThis differs from a DFS recursive approach: each iteration expands one "layer" of includes across the whole source, rather than drilling into each include immediately. This allows patterns like inc-loop (where the same page is included with different variables across iterations) to work.