@refrakt-md/runes 0.38.0 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collection-helpers.d.ts +21 -2
- package/dist/collection-helpers.d.ts.map +1 -1
- package/dist/collection-helpers.js +72 -15
- package/dist/collection-helpers.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +73 -40
- package/dist/config.js.map +1 -1
- package/dist/data-pipeline.d.ts +24 -10
- package/dist/data-pipeline.d.ts.map +1 -1
- package/dist/data-pipeline.js +34 -56
- package/dist/data-pipeline.js.map +1 -1
- package/dist/file-ref-resolve.js +9 -13
- package/dist/file-ref-resolve.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/index.d.ts +47 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +112 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/preprocess.d.ts +63 -0
- package/dist/lib/preprocess.d.ts.map +1 -0
- package/dist/lib/preprocess.js +71 -0
- package/dist/lib/preprocess.js.map +1 -0
- package/dist/lib/registers.d.ts +132 -0
- package/dist/lib/registers.d.ts.map +1 -0
- package/dist/lib/registers.js +328 -0
- package/dist/lib/registers.js.map +1 -0
- package/dist/lib/resolver.d.ts +9 -1
- package/dist/lib/resolver.d.ts.map +1 -1
- package/dist/lib/resolver.js +16 -0
- package/dist/lib/resolver.js.map +1 -1
- package/dist/lib/schema-table.d.ts +46 -9
- package/dist/lib/schema-table.d.ts.map +1 -1
- package/dist/lib/schema-table.js +111 -22
- package/dist/lib/schema-table.js.map +1 -1
- package/dist/lib/slots.d.ts +99 -0
- package/dist/lib/slots.d.ts.map +1 -0
- package/dist/lib/slots.js +448 -0
- package/dist/lib/slots.js.map +1 -0
- package/dist/reference.d.ts +18 -0
- package/dist/reference.d.ts.map +1 -1
- package/dist/reference.js +34 -1
- package/dist/reference.js.map +1 -1
- package/dist/registers-pipeline.d.ts +50 -0
- package/dist/registers-pipeline.d.ts.map +1 -0
- package/dist/registers-pipeline.js +218 -0
- package/dist/registers-pipeline.js.map +1 -0
- package/dist/schema-row.d.ts +5 -0
- package/dist/schema-row.d.ts.map +1 -1
- package/dist/schema-row.js +1 -0
- package/dist/schema-row.js.map +1 -1
- package/dist/tags/data.d.ts +2 -2
- package/dist/tags/data.d.ts.map +1 -1
- package/dist/tags/data.js +6 -4
- package/dist/tags/data.js.map +1 -1
- package/dist/tags/figure.d.ts +10 -4
- package/dist/tags/figure.d.ts.map +1 -1
- package/dist/tags/figure.js +65 -20
- package/dist/tags/figure.js.map +1 -1
- package/dist/tags/include.d.ts +51 -7
- package/dist/tags/include.d.ts.map +1 -1
- package/dist/tags/include.js +216 -7
- package/dist/tags/include.js.map +1 -1
- package/dist/tags/snippet.d.ts +9 -10
- package/dist/tags/snippet.d.ts.map +1 -1
- package/dist/tags/snippet.js +213 -10
- package/dist/tags/snippet.js.map +1 -1
- package/dist/universal-attributes.d.ts +1 -1
- package/package.json +3 -3
- package/dist/include-pipeline.d.ts +0 -52
- package/dist/include-pipeline.d.ts.map +0 -1
- package/dist/include-pipeline.js +0 -206
- package/dist/include-pipeline.js.map +0 -1
- package/dist/snippet-pipeline.d.ts +0 -44
- package/dist/snippet-pipeline.d.ts.map +0 -1
- package/dist/snippet-pipeline.js +0 -307
- package/dist/snippet-pipeline.js.map +0 -1
package/dist/tags/snippet.js
CHANGED
|
@@ -1,20 +1,222 @@
|
|
|
1
|
+
import Markdoc from '@markdoc/markdoc';
|
|
1
2
|
import { createContentModelSchema } from '../lib/index.js';
|
|
3
|
+
import { formatHighlight, highlightMatchLines, parseHighlightMatch, reindent, shouldReindent, } from '../lib/present.js';
|
|
4
|
+
import { readSnippetFile, SnippetSandboxError } from '../lib/read-file.js';
|
|
5
|
+
import { compareMarker, parseMarker } from '../lib/review-marker.js';
|
|
6
|
+
import { inferLanguage } from '../lang-map.js';
|
|
7
|
+
const { Ast } = Markdoc;
|
|
8
|
+
/** Resolve a Markdoc attribute value to a string. Handles literal strings
|
|
9
|
+
* and Markdoc `Variable` AST nodes (e.g. `path=$file.path` parses as a
|
|
10
|
+
* Variable, not a string). Unresolvable references (variable missing from
|
|
11
|
+
* the context, or attribute is some other AST shape) return an empty
|
|
12
|
+
* string — matching transform-time variable-evaluation behaviour. */
|
|
13
|
+
function resolveAttributeValue(value, variables) {
|
|
14
|
+
if (value === undefined || value === null)
|
|
15
|
+
return '';
|
|
16
|
+
if (typeof value === 'string')
|
|
17
|
+
return value;
|
|
18
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
19
|
+
return String(value);
|
|
20
|
+
if (typeof value === 'object' && '$$mdtype' in value) {
|
|
21
|
+
const node = value;
|
|
22
|
+
if (node.$$mdtype === 'Variable' && Array.isArray(node.path)) {
|
|
23
|
+
let current = variables;
|
|
24
|
+
for (const segment of node.path) {
|
|
25
|
+
if (current === null || current === undefined)
|
|
26
|
+
return '';
|
|
27
|
+
current = current[segment];
|
|
28
|
+
}
|
|
29
|
+
return current === null || current === undefined ? '' : String(current);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
/** Build a `fence` AST node that renders a clear error message in place of
|
|
35
|
+
* the snippet. Used when resolution fails (sandbox, missing file, malformed
|
|
36
|
+
* lines, unresolvable variable reference). The fence carries the original
|
|
37
|
+
* attempted path in `source` so tooling can still detect snippet
|
|
38
|
+
* provenance, plus a `data-snippet-error` raw data-attr that's
|
|
39
|
+
* forwarded through the fence transform for the error styling hook. */
|
|
40
|
+
function makeErrorFence(pathAttr, message) {
|
|
41
|
+
return new Ast.Node('fence', {
|
|
42
|
+
content: `snippet error: ${message}\n`,
|
|
43
|
+
language: 'text',
|
|
44
|
+
source: pathAttr || '(unresolved)',
|
|
45
|
+
'data-snippet-error': message,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function resolveSnippetToFence(tag, page, ctx, files) {
|
|
49
|
+
const pathAttr = resolveAttributeValue(tag.attributes.path, ctx.variables);
|
|
50
|
+
const lines = tag.attributes.lines !== undefined
|
|
51
|
+
? resolveAttributeValue(tag.attributes.lines, ctx.variables)
|
|
52
|
+
: undefined;
|
|
53
|
+
const langAttr = tag.attributes.lang !== undefined
|
|
54
|
+
? resolveAttributeValue(tag.attributes.lang, ctx.variables)
|
|
55
|
+
: undefined;
|
|
56
|
+
// WORK-304 — propagate author-set fence-level annotations from the
|
|
57
|
+
// snippet rune through to the fence node. The fence schema renders
|
|
58
|
+
// them as `data-linenumbers` / `data-highlight-lines`. `linenumbers`
|
|
59
|
+
// arrives as a Boolean from the rune schema; `highlight` as a String.
|
|
60
|
+
const linenumbers = tag.attributes.linenumbers === true;
|
|
61
|
+
const highlight = tag.attributes.highlight !== undefined
|
|
62
|
+
? resolveAttributeValue(tag.attributes.highlight, ctx.variables)
|
|
63
|
+
: undefined;
|
|
64
|
+
// SPEC-131 — anchor attributes. Resolution lands in the shared reader, so
|
|
65
|
+
// `file-ref` gains the same capability from the same change.
|
|
66
|
+
const str = (name) => tag.attributes[name] !== undefined
|
|
67
|
+
? resolveAttributeValue(tag.attributes[name], ctx.variables)
|
|
68
|
+
: undefined;
|
|
69
|
+
const anchor = {
|
|
70
|
+
symbol: str('symbol'),
|
|
71
|
+
match: str('match'),
|
|
72
|
+
occurrence: tag.attributes.occurrence !== undefined ? Number(tag.attributes.occurrence) : undefined,
|
|
73
|
+
extent: str('extent'),
|
|
74
|
+
until: str('until'),
|
|
75
|
+
through: str('through'),
|
|
76
|
+
doc: tag.attributes.doc === undefined ? undefined : tag.attributes.doc === true,
|
|
77
|
+
};
|
|
78
|
+
const reindentAttr = tag.attributes.reindent === undefined ? undefined : tag.attributes.reindent === true;
|
|
79
|
+
const highlightMatch = str('highlight-match');
|
|
80
|
+
const reviewedAttr = str('reviewed');
|
|
81
|
+
if (!pathAttr) {
|
|
82
|
+
const msg = 'snippet `path` attribute is required (and an unresolvable variable reference resolves to empty)';
|
|
83
|
+
ctx.error(msg, page.url);
|
|
84
|
+
return makeErrorFence('', msg);
|
|
85
|
+
}
|
|
86
|
+
let result;
|
|
87
|
+
try {
|
|
88
|
+
result = readSnippetFile({
|
|
89
|
+
files,
|
|
90
|
+
pathAttr,
|
|
91
|
+
lines: lines || undefined,
|
|
92
|
+
anchor,
|
|
93
|
+
lang: langAttr || undefined,
|
|
94
|
+
referencingPage: page.relativePath,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
if (err instanceof SnippetSandboxError) {
|
|
99
|
+
ctx.error(err.message, page.url);
|
|
100
|
+
return makeErrorFence(pathAttr, err.message);
|
|
101
|
+
}
|
|
102
|
+
// Unexpected error type — still produce an error fence so the build
|
|
103
|
+
// doesn't crash on a single page.
|
|
104
|
+
const msg = err.message ?? String(err);
|
|
105
|
+
ctx.error(`snippet "${pathAttr}" failed unexpectedly: ${msg}`, page.url);
|
|
106
|
+
return makeErrorFence(pathAttr, msg);
|
|
107
|
+
}
|
|
108
|
+
for (const warning of result.warnings) {
|
|
109
|
+
ctx.warn(warning, page.url);
|
|
110
|
+
}
|
|
111
|
+
// SPEC-134 — the review marker. Evaluated only after the anchor resolved,
|
|
112
|
+
// because D9 layers the two features: SPEC-131 answers *can I find the
|
|
113
|
+
// region* and refuses if not, so a refusal never reaches here at all.
|
|
114
|
+
//
|
|
115
|
+
// A finding is a `PipelineWarning` beside the page and **nothing is
|
|
116
|
+
// rendered into it** (D6). This is deliberately different from SPEC-131's
|
|
117
|
+
// error fence, and the difference is principled: there, the content could
|
|
118
|
+
// not be produced, so the fence takes its place. Here the content was
|
|
119
|
+
// produced perfectly — real, current, correctly located. What is uncertain
|
|
120
|
+
// is the prose beside it, which the resolver cannot see. Replacing a
|
|
121
|
+
// correct code block with an error because a paragraph *might* be stale is
|
|
122
|
+
// a straightforward regression for every reader.
|
|
123
|
+
if (reviewedAttr && reviewedAttr.length > 0) {
|
|
124
|
+
const stored = parseMarker(reviewedAttr);
|
|
125
|
+
const comparison = compareMarker(stored.strict, result.content, stored.loose);
|
|
126
|
+
if (comparison.verdict === 'stale') {
|
|
127
|
+
// Deliberately no diff here: at transform time the only record of
|
|
128
|
+
// the reviewed version is its hash, and a hash cannot be turned
|
|
129
|
+
// back into content. `refrakt snippet review --update` recovers the
|
|
130
|
+
// old slice from git and shows the diff — which is why D5's "show
|
|
131
|
+
// content, never hashes" is the CLI's job rather than this one's.
|
|
132
|
+
ctx.warn(`snippet \`${pathAttr}\` has changed since it was last reviewed. Re-read the prose ` +
|
|
133
|
+
'around it, then run `refrakt snippet review --update` to see the diff and re-stamp.', page.url);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const language = langAttr && langAttr.length > 0 ? langAttr : inferLanguage(result.relativePath);
|
|
137
|
+
// WORK-589 — presentation runs strictly **after** the resolved range is
|
|
138
|
+
// fixed, so `reindent` can never shift the coordinates `linenumbers` and a
|
|
139
|
+
// numeric `highlight` read (D13). `highlight-match` is computed against the
|
|
140
|
+
// pre-reindent text because reindent changes columns, not lines.
|
|
141
|
+
const highlightMatchLinesFound = highlightMatch
|
|
142
|
+
? highlightMatchLines(result.content, parseHighlightMatch(highlightMatch))
|
|
143
|
+
: [];
|
|
144
|
+
const content = shouldReindent(result.anchored, reindentAttr)
|
|
145
|
+
? reindent(result.content)
|
|
146
|
+
: result.content;
|
|
147
|
+
// WORK-304 — write unprefixed `source` / `lines` directly. The fence
|
|
148
|
+
// schema renders them as `data-source` / `data-lines`. `linenumbers` /
|
|
149
|
+
// `highlight` are propagated from the rune attributes (file-coordinate
|
|
150
|
+
// semantics — see WORK-304 acceptance criteria).
|
|
151
|
+
const fenceAttrs = {
|
|
152
|
+
content,
|
|
153
|
+
language,
|
|
154
|
+
source: result.relativePath,
|
|
155
|
+
};
|
|
156
|
+
// The coordinate frame survives anchoring (D13): an anchored slice reports
|
|
157
|
+
// the range it actually resolved to, so `linenumbers` still starts at the
|
|
158
|
+
// real file line and the displayed numbers stay a pointer back into it.
|
|
159
|
+
if (lines)
|
|
160
|
+
fenceAttrs.lines = lines;
|
|
161
|
+
else if (result.anchored && result.start !== undefined && result.end !== undefined) {
|
|
162
|
+
fenceAttrs.lines = `${result.start}-${result.end}`;
|
|
163
|
+
}
|
|
164
|
+
if (linenumbers)
|
|
165
|
+
fenceAttrs.linenumbers = true;
|
|
166
|
+
if (highlightMatchLinesFound.length > 0) {
|
|
167
|
+
// Slice offsets converted into the file frame the fence expects.
|
|
168
|
+
const base = result.start ?? 1;
|
|
169
|
+
fenceAttrs.highlight = formatHighlight(highlightMatchLinesFound.map((n) => n + base - 1));
|
|
170
|
+
}
|
|
171
|
+
else if (highlight && highlight.length > 0) {
|
|
172
|
+
fenceAttrs.highlight = highlight;
|
|
173
|
+
}
|
|
174
|
+
// Construct a fence Ast.Node. Markdoc parses ``` blocks as
|
|
175
|
+
// new Ast.Node('fence', { content, language }) — same shape here.
|
|
176
|
+
return new Ast.Node('fence', fenceAttrs);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Preprocess (SPEC-062, WORK-304): resolve + slice the source file and replace
|
|
180
|
+
* the tag with a Markdoc `fence` node. The fence carries `content` + `language`
|
|
181
|
+
* (so the code-block transform syntax-highlights it identically to a
|
|
182
|
+
* triple-backtick fence) plus `source` / `lines` and the author-set
|
|
183
|
+
* `linenumbers` / `highlight` annotations, which the fence schema renders as
|
|
184
|
+
* `data-source` / `data-lines` / `data-linenumbers` / `data-highlight-lines` on
|
|
185
|
+
* the output `<pre>` + `<code>`.
|
|
186
|
+
*
|
|
187
|
+
* That is the whole rune: there is no postProcess step (SPEC-141 D5). A
|
|
188
|
+
* standalone snippet renders as the `<pre data-source>` the fence produces —
|
|
189
|
+
* `pre[data-source]` is the selector for snippet-derived code — and container
|
|
190
|
+
* runes (`codegroup`, `diff`) see it as a regular fence and consume it
|
|
191
|
+
* transparently. Captions / titles are intentionally not provided — wrap a
|
|
192
|
+
* snippet in `{% codegroup title="..." %}` if you want a labelled chrome.
|
|
193
|
+
*
|
|
194
|
+
* Always produces a fence: sandbox / missing-file / variable-resolution errors
|
|
195
|
+
* produce an error fence, so the tag never reaches the throwing `transform`.
|
|
196
|
+
* The build keeps going and the failure is visible on the rendered page.
|
|
197
|
+
*
|
|
198
|
+
* No-op without a file provider (e.g. a tree-mode build that hasn't wired one
|
|
199
|
+
* yet) — the tag then falls through to the transform, which names the wiring.
|
|
200
|
+
*/
|
|
201
|
+
function preprocessSnippet(tag, page, ctx) {
|
|
202
|
+
if (!ctx.sandbox)
|
|
203
|
+
return;
|
|
204
|
+
return resolveSnippetToFence(tag, page, ctx, ctx.sandbox);
|
|
205
|
+
}
|
|
2
206
|
/**
|
|
3
207
|
* The `snippet` rune — embed a file's contents as a syntax-highlighted code
|
|
4
208
|
* block (SPEC-062).
|
|
5
209
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* `transform` function is **unreachable in normal operation**.
|
|
210
|
+
* Snippet is an **AST preprocessor** rather than a transform-time rune: its
|
|
211
|
+
* `preprocess` hook (above) replaces every `{% snippet %}` tag with a Markdoc
|
|
212
|
+
* `fence` node before the schema-driven transform runs (SPEC-141). By the time
|
|
213
|
+
* the transform reaches the AST, no snippet tags exist — only fences. So this
|
|
214
|
+
* schema's `transform` function is **unreachable in normal operation**.
|
|
12
215
|
*
|
|
13
216
|
* The schema still exists for tooling: `refrakt inspect snippet`, the
|
|
14
217
|
* contracts generator, attribute validation, and the rune-catalog docs all
|
|
15
|
-
* read from it. If the transform ever does execute
|
|
16
|
-
*
|
|
17
|
-
* the user at the registration site.
|
|
218
|
+
* read from it. If the transform ever does execute, it throws a clear error
|
|
219
|
+
* naming the likely cause (SPEC-141 D7).
|
|
18
220
|
*/
|
|
19
221
|
export const snippet = createContentModelSchema({
|
|
20
222
|
attributes: {
|
|
@@ -96,8 +298,9 @@ export const snippet = createContentModelSchema({
|
|
|
96
298
|
},
|
|
97
299
|
},
|
|
98
300
|
contentModel: { type: 'sequence', fields: [] },
|
|
301
|
+
preprocess: preprocessSnippet,
|
|
99
302
|
transform(_resolved, _attrs) {
|
|
100
|
-
// Unreachable in normal operation —
|
|
303
|
+
// Unreachable in normal operation — the `preprocess` hook above
|
|
101
304
|
// replaces snippet tags with fence nodes before the transform runs.
|
|
102
305
|
//
|
|
103
306
|
// The reachable case is a content author's, not a framework author's:
|
package/dist/tags/snippet.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet.js","sourceRoot":"","sources":["../../src/tags/snippet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D
|
|
1
|
+
{"version":3,"file":"snippet.js","sourceRoot":"","sources":["../../src/tags/snippet.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,kBAAkB,CAAC;AAGvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EACN,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,QAAQ,EACR,cAAc,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;AAExB;;;;sEAIsE;AACtE,SAAS,qBAAqB,CAC7B,KAAc,EACd,SAA8C;IAE9C,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,OAAO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AAC;IACH,CAAC;CACD,CAAC,CAAC"}
|
|
@@ -61,7 +61,7 @@ export type UniversalAttributePosture = 'auto' | 'inline' | 'configurator' | 'no
|
|
|
61
61
|
/** The prose behind a non-`auto` posture, for tooling that explains itself.
|
|
62
62
|
* Re-exported from the transform registry rather than restated, so the schema
|
|
63
63
|
* layer and the structure contract give the same reason. */
|
|
64
|
-
export declare const POSTURE_REASONS: Readonly<Record<"inline" | "
|
|
64
|
+
export declare const POSTURE_REASONS: Readonly<Record<"inline" | "none" | "configurator", string>>;
|
|
65
65
|
export interface UniversalAttributeInput {
|
|
66
66
|
/** Defaults to `auto`. */
|
|
67
67
|
posture?: UniversalAttributePosture;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refrakt-md/runes",
|
|
3
3
|
"description": "Semantic Markdoc runes for refrakt.md",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.39.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"generate-translations": "node scripts/generate-translations.mjs"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@refrakt-md/types": "0.
|
|
36
|
-
"@refrakt-md/transform": "0.
|
|
35
|
+
"@refrakt-md/types": "0.39.0",
|
|
36
|
+
"@refrakt-md/transform": "0.39.0",
|
|
37
37
|
"@markdoc/markdoc": "0.4.0",
|
|
38
38
|
"reflect-metadata": "^0.2.0",
|
|
39
39
|
"fast-xml-parser": "4.5.1",
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Include pipeline hook (SPEC-129).
|
|
3
|
-
*
|
|
4
|
-
* The first preprocess step: walk the parsed AST and replace every
|
|
5
|
-
* `{% include %}` tag with the referenced partial's AST, cloned and with the
|
|
6
|
-
* tag's `variables` substituted. It runs **before** `preprocessSnippets` and
|
|
7
|
-
* `preprocessData` so a `data` or `snippet` inside the pasted file is in the
|
|
8
|
-
* tree when those hooks walk it — the case `{% partial %}` cannot serve,
|
|
9
|
-
* because Markdoc expands partials during the transform.
|
|
10
|
-
*
|
|
11
|
-
* Three properties are load-bearing:
|
|
12
|
-
*
|
|
13
|
-
* - **Splice, never wrap.** One include produces N nodes and they land as
|
|
14
|
-
* direct siblings. A container to keep the replacement 1:1 breaks
|
|
15
|
-
* composition invisibly: measured in SPEC-127, `{% section %}` and
|
|
16
|
-
* `{% grid %}` consume their children, so wrapped content vanishes with no
|
|
17
|
-
* error. Same constraint, same reason, as the `data` per-row body.
|
|
18
|
-
*
|
|
19
|
-
* - **Always clone.** The partial ASTs are parsed once per build and shared by
|
|
20
|
-
* every page that references them. The later preprocessors mutate the tree in
|
|
21
|
-
* place, so pasting the shared nodes would let one page's `data` resolution
|
|
22
|
-
* leak into the next page's copy.
|
|
23
|
-
*
|
|
24
|
-
* - **Substitute, don't scope.** `partial` binds variables into a
|
|
25
|
-
* transform-time scope, which is precisely what a preprocessor attribute
|
|
26
|
-
* cannot read. `include` rewrites `Variable` nodes in the cloned AST at paste
|
|
27
|
-
* time — the same thing `bindRow` does for `$row` — so a binding reaches
|
|
28
|
-
* `{% data where=$q %}`. Variables the include does not bind are left alone
|
|
29
|
-
* and resolve at transform against the page's own variables.
|
|
30
|
-
*
|
|
31
|
-
* Failures render a visible error callout and record a build error rather than
|
|
32
|
-
* throwing, matching `data`: one bad include does not take out the build, and
|
|
33
|
-
* the failure is on the page where the author will see it.
|
|
34
|
-
*/
|
|
35
|
-
import type { Node } from '@markdoc/markdoc';
|
|
36
|
-
import type { PreprocessContext, PreprocessPage } from '@refrakt-md/types';
|
|
37
|
-
/**
|
|
38
|
-
* How deep includes may nest.
|
|
39
|
-
*
|
|
40
|
-
* A cycle is caught by name before this ever fires — the stack check below is
|
|
41
|
-
* the real guard. This bounds the other shape: a chain of distinct files deep
|
|
42
|
-
* enough that it is a mistake rather than a structure anyone meant to author.
|
|
43
|
-
*/
|
|
44
|
-
export declare const MAX_INCLUDE_DEPTH = 16;
|
|
45
|
-
/**
|
|
46
|
-
* Preprocess: splice every `{% include %}` tag away. No-op when no partials are
|
|
47
|
-
* available (a tree-mode build with none wired), matching how snippet and data
|
|
48
|
-
* no-op without a sandbox — the tag then falls through to its schema transform,
|
|
49
|
-
* which names the wiring.
|
|
50
|
-
*/
|
|
51
|
-
export declare function preprocessIncludes(ast: Node, page: PreprocessPage, ctx: PreprocessContext): Node | void;
|
|
52
|
-
//# sourceMappingURL=include-pipeline.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"include-pipeline.d.ts","sourceRoot":"","sources":["../src/include-pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAK3E;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,IAAI,EACT,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,iBAAiB,GACpB,IAAI,GAAG,IAAI,CAeb"}
|
package/dist/include-pipeline.js
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Include pipeline hook (SPEC-129).
|
|
3
|
-
*
|
|
4
|
-
* The first preprocess step: walk the parsed AST and replace every
|
|
5
|
-
* `{% include %}` tag with the referenced partial's AST, cloned and with the
|
|
6
|
-
* tag's `variables` substituted. It runs **before** `preprocessSnippets` and
|
|
7
|
-
* `preprocessData` so a `data` or `snippet` inside the pasted file is in the
|
|
8
|
-
* tree when those hooks walk it — the case `{% partial %}` cannot serve,
|
|
9
|
-
* because Markdoc expands partials during the transform.
|
|
10
|
-
*
|
|
11
|
-
* Three properties are load-bearing:
|
|
12
|
-
*
|
|
13
|
-
* - **Splice, never wrap.** One include produces N nodes and they land as
|
|
14
|
-
* direct siblings. A container to keep the replacement 1:1 breaks
|
|
15
|
-
* composition invisibly: measured in SPEC-127, `{% section %}` and
|
|
16
|
-
* `{% grid %}` consume their children, so wrapped content vanishes with no
|
|
17
|
-
* error. Same constraint, same reason, as the `data` per-row body.
|
|
18
|
-
*
|
|
19
|
-
* - **Always clone.** The partial ASTs are parsed once per build and shared by
|
|
20
|
-
* every page that references them. The later preprocessors mutate the tree in
|
|
21
|
-
* place, so pasting the shared nodes would let one page's `data` resolution
|
|
22
|
-
* leak into the next page's copy.
|
|
23
|
-
*
|
|
24
|
-
* - **Substitute, don't scope.** `partial` binds variables into a
|
|
25
|
-
* transform-time scope, which is precisely what a preprocessor attribute
|
|
26
|
-
* cannot read. `include` rewrites `Variable` nodes in the cloned AST at paste
|
|
27
|
-
* time — the same thing `bindRow` does for `$row` — so a binding reaches
|
|
28
|
-
* `{% data where=$q %}`. Variables the include does not bind are left alone
|
|
29
|
-
* and resolve at transform against the page's own variables.
|
|
30
|
-
*
|
|
31
|
-
* Failures render a visible error callout and record a build error rather than
|
|
32
|
-
* throwing, matching `data`: one bad include does not take out the build, and
|
|
33
|
-
* the failure is on the page where the author will see it.
|
|
34
|
-
*/
|
|
35
|
-
import Markdoc from '@markdoc/markdoc';
|
|
36
|
-
import { emitErrorNode } from './data-emit.js';
|
|
37
|
-
const { Ast } = Markdoc;
|
|
38
|
-
/**
|
|
39
|
-
* How deep includes may nest.
|
|
40
|
-
*
|
|
41
|
-
* A cycle is caught by name before this ever fires — the stack check below is
|
|
42
|
-
* the real guard. This bounds the other shape: a chain of distinct files deep
|
|
43
|
-
* enough that it is a mistake rather than a structure anyone meant to author.
|
|
44
|
-
*/
|
|
45
|
-
export const MAX_INCLUDE_DEPTH = 16;
|
|
46
|
-
/**
|
|
47
|
-
* Preprocess: splice every `{% include %}` tag away. No-op when no partials are
|
|
48
|
-
* available (a tree-mode build with none wired), matching how snippet and data
|
|
49
|
-
* no-op without a sandbox — the tag then falls through to its schema transform,
|
|
50
|
-
* which names the wiring.
|
|
51
|
-
*/
|
|
52
|
-
export function preprocessIncludes(ast, page, ctx) {
|
|
53
|
-
const partials = ctx.partials;
|
|
54
|
-
if (!partials)
|
|
55
|
-
return;
|
|
56
|
-
let mutated = false;
|
|
57
|
-
walkAndReplaceIncludes(ast, page, ctx, partials, () => {
|
|
58
|
-
mutated = true;
|
|
59
|
-
}, []);
|
|
60
|
-
return mutated ? ast : undefined;
|
|
61
|
-
}
|
|
62
|
-
function walkAndReplaceIncludes(node, page, ctx, partials, onReplaced, stack) {
|
|
63
|
-
if (!node.children)
|
|
64
|
-
return;
|
|
65
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
66
|
-
const child = node.children[i];
|
|
67
|
-
if (child.type === 'tag' && child.tag === 'include') {
|
|
68
|
-
const replacement = resolveInclude(child, page, ctx, partials, stack);
|
|
69
|
-
node.children.splice(i, 1, ...replacement);
|
|
70
|
-
// Skip the pasted nodes: nested includes inside them were already
|
|
71
|
-
// expanded by `resolveInclude`, under the cycle stack that names the
|
|
72
|
-
// chain. Re-walking here would expand them a second time with an empty
|
|
73
|
-
// stack, which is exactly how a cycle becomes an infinite paste.
|
|
74
|
-
i += replacement.length - 1;
|
|
75
|
-
onReplaced();
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
walkAndReplaceIncludes(child, page, ctx, partials, onReplaced, stack);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function fail(ctx, page, message) {
|
|
82
|
-
ctx.error(`include: ${message}`, page.url);
|
|
83
|
-
return [emitErrorNode(`include error: ${message}`)];
|
|
84
|
-
}
|
|
85
|
-
function resolveInclude(tag, page, ctx, partials, stack) {
|
|
86
|
-
const file = resolveValue(tag.attributes?.file, ctx.variables);
|
|
87
|
-
if (typeof file !== 'string' || file.length === 0) {
|
|
88
|
-
return fail(ctx, page, 'the `file` attribute is required (an unresolvable variable reference resolves to empty)');
|
|
89
|
-
}
|
|
90
|
-
if (stack.includes(file)) {
|
|
91
|
-
return fail(ctx, page, `cycle — ${[...stack, file].join(' → ')}`);
|
|
92
|
-
}
|
|
93
|
-
if (stack.length >= MAX_INCLUDE_DEPTH) {
|
|
94
|
-
return fail(ctx, page, `nested more than ${MAX_INCLUDE_DEPTH} deep — ${[...stack, file].join(' → ')}`);
|
|
95
|
-
}
|
|
96
|
-
const source = partials[file];
|
|
97
|
-
if (!source || typeof source !== 'object') {
|
|
98
|
-
const known = Object.keys(partials).sort();
|
|
99
|
-
const available = known.length > 0
|
|
100
|
-
? ` Available: ${known.join(', ')}.`
|
|
101
|
-
: ' No partials are registered for this site.';
|
|
102
|
-
return fail(ctx, page, `"${file}" was not found in \`_partials/\` or any registered file root.${available}`);
|
|
103
|
-
}
|
|
104
|
-
const bindings = resolveVariables(tag.attributes?.variables, ctx.variables);
|
|
105
|
-
const pasted = source.children ?? [];
|
|
106
|
-
const children = pasted.map((child) => cloneWithBindings(child, bindings));
|
|
107
|
-
// Expand nested includes inside what was just pasted, under a stack carrying
|
|
108
|
-
// this file — so a cycle is reported by name instead of overflowing.
|
|
109
|
-
if (children.length > 0) {
|
|
110
|
-
const container = new Ast.Node('document', {}, children);
|
|
111
|
-
walkAndReplaceIncludes(container, page, ctx, partials, () => { }, [...stack, file]);
|
|
112
|
-
return container.children;
|
|
113
|
-
}
|
|
114
|
-
return children;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Clone a node, substituting bound variables.
|
|
118
|
-
*
|
|
119
|
-
* `$q` reaches the AST as a `Variable` in a node's *attributes* — on a tag
|
|
120
|
-
* (`where=$q`) and equally on a `text` node, where `{% $q %}` becomes
|
|
121
|
-
* `content: Variable(['q'])`. One rule covers both, exactly as `bindRow` does.
|
|
122
|
-
*/
|
|
123
|
-
function cloneWithBindings(node, bindings) {
|
|
124
|
-
const attributes = {};
|
|
125
|
-
for (const [key, value] of Object.entries(node.attributes ?? {})) {
|
|
126
|
-
attributes[key] = substitute(value, bindings);
|
|
127
|
-
}
|
|
128
|
-
const children = (node.children ?? []).map((child) => cloneWithBindings(child, bindings));
|
|
129
|
-
const copy = new Ast.Node(node.type, attributes, children, node.tag);
|
|
130
|
-
// The constructor takes four fields; everything else Markdoc's parser sets
|
|
131
|
-
// has to be carried across by hand. `inline` decides whether a node renders
|
|
132
|
-
// inline, and `annotations` carries `{% .class #id %}` shorthand — dropping
|
|
133
|
-
// either changes the output silently.
|
|
134
|
-
if (node.lines)
|
|
135
|
-
copy.lines = node.lines;
|
|
136
|
-
if (node.location)
|
|
137
|
-
copy.location = node.location;
|
|
138
|
-
copy.inline = node.inline;
|
|
139
|
-
if (node.annotations?.length)
|
|
140
|
-
copy.annotations = node.annotations;
|
|
141
|
-
if (node.slots && Object.keys(node.slots).length > 0) {
|
|
142
|
-
copy.slots = Object.fromEntries(Object.entries(node.slots).map(([k, v]) => [k, cloneWithBindings(v, bindings)]));
|
|
143
|
-
}
|
|
144
|
-
return copy;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Replace a `Variable` node whose root segment the include binds.
|
|
148
|
-
*
|
|
149
|
-
* Unbound variables pass through untouched rather than resolving to empty: the
|
|
150
|
-
* pasted AST is page content now, so `$page.slug` and friends still resolve at
|
|
151
|
-
* transform against the page's own variables. That is a capability `partial`
|
|
152
|
-
* does not have — its scope *replaces* the variable surface.
|
|
153
|
-
*/
|
|
154
|
-
function substitute(value, bindings) {
|
|
155
|
-
if (!value || typeof value !== 'object')
|
|
156
|
-
return value;
|
|
157
|
-
const node = value;
|
|
158
|
-
if (node.$$mdtype === 'Variable' && Array.isArray(node.path) && node.path.length > 0) {
|
|
159
|
-
const [root, ...rest] = node.path;
|
|
160
|
-
if (!(root in bindings))
|
|
161
|
-
return value;
|
|
162
|
-
let current = bindings[root];
|
|
163
|
-
for (const segment of rest) {
|
|
164
|
-
if (current === null || current === undefined)
|
|
165
|
-
return '';
|
|
166
|
-
current = current[segment];
|
|
167
|
-
}
|
|
168
|
-
return current === null || current === undefined ? '' : current;
|
|
169
|
-
}
|
|
170
|
-
return value;
|
|
171
|
-
}
|
|
172
|
-
/** The include's own `variables={...}`, with any page-variable references in
|
|
173
|
-
* its values resolved before they are substituted into the pasted AST. */
|
|
174
|
-
function resolveVariables(raw, pageVariables) {
|
|
175
|
-
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
176
|
-
return {};
|
|
177
|
-
const out = {};
|
|
178
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
179
|
-
out[key] = resolveValue(value, pageVariables);
|
|
180
|
-
}
|
|
181
|
-
return out;
|
|
182
|
-
}
|
|
183
|
-
/** Resolve an attribute value against the page's variables — literals pass
|
|
184
|
-
* through, `Variable` nodes are looked up. Mirrors snippet's and data's
|
|
185
|
-
* resolvers; anything else (a `Function` node) resolves to empty — the same
|
|
186
|
-
* silent-empty behaviour BUG-010 tracks for `data`'s `where`. */
|
|
187
|
-
function resolveValue(value, variables) {
|
|
188
|
-
if (value === undefined || value === null)
|
|
189
|
-
return '';
|
|
190
|
-
if (typeof value !== 'object')
|
|
191
|
-
return value;
|
|
192
|
-
const node = value;
|
|
193
|
-
if (node.$$mdtype === 'Variable' && Array.isArray(node.path)) {
|
|
194
|
-
let current = variables;
|
|
195
|
-
for (const segment of node.path) {
|
|
196
|
-
if (current === null || current === undefined)
|
|
197
|
-
return '';
|
|
198
|
-
current = current[segment];
|
|
199
|
-
}
|
|
200
|
-
return current === null || current === undefined ? '' : current;
|
|
201
|
-
}
|
|
202
|
-
if (node.$$mdtype === undefined)
|
|
203
|
-
return value;
|
|
204
|
-
return '';
|
|
205
|
-
}
|
|
206
|
-
//# sourceMappingURL=include-pipeline.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"include-pipeline.js","sourceRoot":"","sources":["../src/include-pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;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pipeline hooks (SPEC-062, WORK-304).
|
|
3
|
-
*
|
|
4
|
-
* - **Preprocess** walks the parsed Markdoc AST, finds every `{% snippet %}`
|
|
5
|
-
* tag, resolves + slices its source file, and replaces the tag with a
|
|
6
|
-
* Markdoc `fence` node. The fence carries `content` + `language` (so
|
|
7
|
-
* the existing code-block transform syntax-highlights it identically to
|
|
8
|
-
* a triple-backtick fence) plus `source` / `lines` + author-set
|
|
9
|
-
* `linenumbers` / `highlight` annotations (WORK-304). The fence schema
|
|
10
|
-
* renders them as `data-source` / `data-lines` / `data-linenumbers` /
|
|
11
|
-
* `data-highlight-lines` on the output `<pre>` + `<code>`.
|
|
12
|
-
*
|
|
13
|
-
* - **PostProcess** walks the rendered renderable tree, finds every `<pre>`
|
|
14
|
-
* element carrying `data-source`, and — when not nested under a
|
|
15
|
-
* fence-consuming container (`data-rune="code-group"`, `data-rune="diff"`)
|
|
16
|
-
* — wraps it in `<figure class="rf-snippet">` so themes can style snippet
|
|
17
|
-
* blocks distinctly from regular code blocks (and tooling can find
|
|
18
|
-
* `data-source-path` on the figure).
|
|
19
|
-
*
|
|
20
|
-
* This separation is the SPEC-062 composition story: container runes see
|
|
21
|
-
* snippet output as a regular fence (because preprocess made it one) and
|
|
22
|
-
* consume it transparently; standalone snippets get the figure chrome via
|
|
23
|
-
* the wrap step. Captions / titles are intentionally not provided — wrap
|
|
24
|
-
* a snippet in `{% codegroup title="..." %}` if you want a labelled chrome.
|
|
25
|
-
*/
|
|
26
|
-
import type { Node } from '@markdoc/markdoc';
|
|
27
|
-
import type { PreprocessContext, PreprocessPage, PipelineContext, TransformedPage, AggregatedData } from '@refrakt-md/types';
|
|
28
|
-
/**
|
|
29
|
-
* Preprocess: replace every `{% snippet %}` tag in the AST with a `fence`
|
|
30
|
-
* node carrying the resolved file content. After this runs, no snippet
|
|
31
|
-
* tags remain in the AST — only fences (some "snippet-derived" identified
|
|
32
|
-
* by their `data-snippet-source` attribute).
|
|
33
|
-
*/
|
|
34
|
-
export declare function preprocessSnippets(ast: Node, page: PreprocessPage, ctx: PreprocessContext): Node | void;
|
|
35
|
-
/**
|
|
36
|
-
* PostProcess: wrap standalone snippet-derived `<pre>` elements in the
|
|
37
|
-
* snippet figure chrome. Run as part of `corePipelineHooks.postProcess`.
|
|
38
|
-
*
|
|
39
|
-
* Container-nested snippets (inside `<div data-rune="code-group">` or
|
|
40
|
-
* `<div data-rune="diff">` outputs) are left alone — the container's chrome
|
|
41
|
-
* is already there and the figure would be duplicate.
|
|
42
|
-
*/
|
|
43
|
-
export declare function wrapStandaloneSnippets(page: TransformedPage, _aggregated: AggregatedData, _ctx: PipelineContext): TransformedPage;
|
|
44
|
-
//# sourceMappingURL=snippet-pipeline.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snippet-pipeline.d.ts","sourceRoot":"","sources":["../src/snippet-pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAEX,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,eAAe,EACf,cAAc,EACd,MAAM,mBAAmB,CAAC;AA6C3B;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,IAAI,EACT,IAAI,EAAE,cAAc,EACpB,GAAG,EAAE,iBAAiB,GACpB,IAAI,GAAG,IAAI,CAab;AAuMD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACrC,IAAI,EAAE,eAAe,EACrB,WAAW,EAAE,cAAc,EAC3B,IAAI,EAAE,eAAe,GACnB,eAAe,CAIjB"}
|