@refrakt-md/runes 0.31.0 → 0.33.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/config.d.ts.map +1 -1
- package/dist/config.js +44 -8
- package/dist/config.js.map +1 -1
- package/dist/data-emit.d.ts +1 -0
- package/dist/data-emit.d.ts.map +1 -1
- package/dist/data-emit.js +40 -0
- package/dist/data-emit.js.map +1 -1
- package/dist/data-pipeline.d.ts +10 -4
- package/dist/data-pipeline.d.ts.map +1 -1
- package/dist/data-pipeline.js +296 -30
- package/dist/data-pipeline.js.map +1 -1
- package/dist/data-projection.d.ts +21 -0
- package/dist/data-projection.d.ts.map +1 -1
- package/dist/data-projection.js +37 -0
- package/dist/data-projection.js.map +1 -1
- package/dist/include-pipeline.d.ts +52 -0
- package/dist/include-pipeline.d.ts.map +1 -0
- package/dist/include-pipeline.js +204 -0
- package/dist/include-pipeline.js.map +1 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/component.d.ts +20 -0
- package/dist/lib/component.d.ts.map +1 -1
- package/dist/lib/component.js +35 -0
- package/dist/lib/component.js.map +1 -1
- package/dist/lib/index.d.ts +54 -4
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +44 -10
- package/dist/lib/index.js.map +1 -1
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +15 -11
- package/dist/nodes.js.map +1 -1
- package/dist/reference.d.ts +37 -2
- package/dist/reference.d.ts.map +1 -1
- package/dist/reference.js +73 -7
- package/dist/reference.js.map +1 -1
- package/dist/schema-universals.d.ts +43 -0
- package/dist/schema-universals.d.ts.map +1 -0
- package/dist/schema-universals.js +39 -0
- package/dist/schema-universals.js.map +1 -0
- package/dist/tags/accordion.d.ts.map +1 -1
- package/dist/tags/accordion.js +24 -5
- package/dist/tags/accordion.js.map +1 -1
- package/dist/tags/annotate.d.ts.map +1 -1
- package/dist/tags/annotate.js +1 -0
- package/dist/tags/annotate.js.map +1 -1
- package/dist/tags/badge.d.ts.map +1 -1
- package/dist/tags/badge.js +3 -0
- package/dist/tags/badge.js.map +1 -1
- package/dist/tags/bg.d.ts.map +1 -1
- package/dist/tags/bg.js +3 -0
- package/dist/tags/bg.js.map +1 -1
- package/dist/tags/blog.d.ts.map +1 -1
- package/dist/tags/blog.js +1 -0
- package/dist/tags/blog.js.map +1 -1
- package/dist/tags/card.d.ts.map +1 -1
- package/dist/tags/card.js +1 -0
- package/dist/tags/card.js.map +1 -1
- package/dist/tags/code.d.ts +25 -0
- package/dist/tags/code.d.ts.map +1 -0
- package/dist/tags/code.js +36 -0
- package/dist/tags/code.js.map +1 -0
- package/dist/tags/data.d.ts.map +1 -1
- package/dist/tags/data.js +26 -4
- package/dist/tags/data.js.map +1 -1
- package/dist/tags/drawer.d.ts.map +1 -1
- package/dist/tags/drawer.js +1 -0
- package/dist/tags/drawer.js.map +1 -1
- package/dist/tags/expand.d.ts.map +1 -1
- package/dist/tags/expand.js +3 -0
- package/dist/tags/expand.js.map +1 -1
- package/dist/tags/icon.d.ts +10 -0
- package/dist/tags/icon.d.ts.map +1 -1
- package/dist/tags/icon.js +13 -0
- package/dist/tags/icon.js.map +1 -1
- package/dist/tags/include.d.ts +24 -0
- package/dist/tags/include.d.ts.map +1 -0
- package/dist/tags/include.js +46 -0
- package/dist/tags/include.js.map +1 -0
- package/dist/tags/mediatext.d.ts.map +1 -1
- package/dist/tags/mediatext.js +1 -0
- package/dist/tags/mediatext.js.map +1 -1
- package/dist/tags/pullquote.d.ts.map +1 -1
- package/dist/tags/pullquote.js +1 -0
- package/dist/tags/pullquote.js.map +1 -1
- package/dist/tags/sidenote.d.ts.map +1 -1
- package/dist/tags/sidenote.js +1 -0
- package/dist/tags/sidenote.js.map +1 -1
- package/dist/tags/snippet.d.ts.map +1 -1
- package/dist/tags/snippet.js +14 -6
- package/dist/tags/snippet.js.map +1 -1
- package/dist/tags/textblock.d.ts.map +1 -1
- package/dist/tags/textblock.js +1 -0
- package/dist/tags/textblock.js.map +1 -1
- package/dist/tags/tint.d.ts.map +1 -1
- package/dist/tags/tint.js +3 -0
- package/dist/tags/tint.js.map +1 -1
- package/dist/tags/xref.d.ts.map +1 -1
- package/dist/tags/xref.js +3 -0
- package/dist/tags/xref.js.map +1 -1
- package/dist/universal-attributes.d.ts +90 -0
- package/dist/universal-attributes.d.ts.map +1 -0
- package/dist/universal-attributes.js +107 -0
- package/dist/universal-attributes.js.map +1 -0
- package/dist/util.d.ts +41 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +70 -12
- package/dist/util.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { UNIVERSAL_AXIS_FACETS, UNIVERSAL_POSTURE_REASONS } from '@refrakt-md/transform';
|
|
2
|
+
/**
|
|
3
|
+
* Which universal attributes a rune may carry — SPEC-125 Phase 3.
|
|
4
|
+
*
|
|
5
|
+
* `createContentModelSchema` used to merge all ~37 universal attributes onto
|
|
6
|
+
* every rune unconditionally. Several of them are inert on most runes: `reading`
|
|
7
|
+
* and `dropcap` need a `body` section role, `prominence` a header-ish one,
|
|
8
|
+
* `frame` a media surface, the cover `scrim*` family a `media-position`
|
|
9
|
+
* modifier. Authoring tools read the schema, so they promised every attribute
|
|
10
|
+
* everywhere, and the engine dropped the inapplicable ones — three of them in
|
|
11
|
+
* total silence.
|
|
12
|
+
*
|
|
13
|
+
* **Availability is derived from the same registry the structure contract uses.**
|
|
14
|
+
* `generateStructureContract` builds its `unavailable` map by calling
|
|
15
|
+
* `UniversalAxisFacet.describeForRune`; so does this. The two derivations are
|
|
16
|
+
* one call, not two implementations that must be kept in step — which is the
|
|
17
|
+
* only way "the contract and the schemas agree" survives the next axis.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Which universal attributes each axis owns.
|
|
21
|
+
*
|
|
22
|
+
* The axis registry's `contract.inputs` cannot serve here: for the `meta`-source
|
|
23
|
+
* axes those are engine-side `data-field` names (`bg-src`, `tint-bg`), not the
|
|
24
|
+
* author-facing attributes a schema declares. This map is the author-facing
|
|
25
|
+
* half, and `universal-attributes.test.ts` holds it to covering
|
|
26
|
+
* `UNIVERSAL_ATTRIBUTE_NAMES` exactly — every attribute owned by one axis, no
|
|
27
|
+
* attribute owned by none.
|
|
28
|
+
*/
|
|
29
|
+
export const AXIS_ATTRIBUTES = {
|
|
30
|
+
tint: ['tint', 'tint-mode'],
|
|
31
|
+
// The `scrim*` family belongs to `bg`, not to `cover`. The background layer
|
|
32
|
+
// builds the scrim on any rune — `bgAxis.contract.inputs` lists all five, and
|
|
33
|
+
// `bg` is available everywhere — while `cover` merely *reroutes* it to the
|
|
34
|
+
// media well when a rune enters cover mode. Filing them under `cover` (which
|
|
35
|
+
// is gated on a `media-position` modifier) narrowed a working attribute off
|
|
36
|
+
// 82 of 83 runes; see WORK-536.
|
|
37
|
+
bg: [
|
|
38
|
+
'bg', 'bg-gradient', 'bg-from', 'bg-to', 'bg-via', 'bg-gradient-type',
|
|
39
|
+
'scrim', 'scrim-type', 'scrim-strength', 'scrim-blur', 'scrim-tone',
|
|
40
|
+
],
|
|
41
|
+
width: ['width'],
|
|
42
|
+
spacing: ['spacing'],
|
|
43
|
+
inset: ['inset'],
|
|
44
|
+
elevation: ['elevation'],
|
|
45
|
+
prominence: ['prominence'],
|
|
46
|
+
reading: ['reading'],
|
|
47
|
+
dropcap: ['dropcap'],
|
|
48
|
+
motion: ['reveal', 'stagger'],
|
|
49
|
+
frame: [
|
|
50
|
+
'frame', 'frame-aspect', 'frame-displace', 'frame-displace-mode', 'frame-offset',
|
|
51
|
+
'frame-oversize', 'frame-place', 'frame-anchor', 'frame-overflow', 'frame-shadow',
|
|
52
|
+
],
|
|
53
|
+
substrate: ['substrate', 'substrate-size', 'substrate-opacity', 'substrate-fill', 'substrate-target'],
|
|
54
|
+
// `cover` owns no author-facing attribute of its own — like `density`,
|
|
55
|
+
// `content-measure` and `content-place`, it can still be reported unavailable
|
|
56
|
+
// on a rune, it simply removes nothing from the schema.
|
|
57
|
+
};
|
|
58
|
+
/** The prose behind a non-`auto` posture, for tooling that explains itself.
|
|
59
|
+
* Re-exported from the transform registry rather than restated, so the schema
|
|
60
|
+
* layer and the structure contract give the same reason. */
|
|
61
|
+
export const POSTURE_REASONS = UNIVERSAL_POSTURE_REASONS;
|
|
62
|
+
/**
|
|
63
|
+
* Resolve which universal attributes apply to one rune.
|
|
64
|
+
*
|
|
65
|
+
* A non-`auto` posture short-circuits: nothing structural is consulted, because
|
|
66
|
+
* the reason is about the rune's kind rather than its anatomy.
|
|
67
|
+
*/
|
|
68
|
+
export function resolveUniversalAttributes(input = {}) {
|
|
69
|
+
const posture = input.posture ?? 'auto';
|
|
70
|
+
if (posture !== 'auto') {
|
|
71
|
+
const reason = POSTURE_REASONS[posture];
|
|
72
|
+
return {
|
|
73
|
+
available: new Set(),
|
|
74
|
+
unavailable: new Map(Object.keys(AXIS_ATTRIBUTES).map((axis) => [axis, reason])),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// A config-shaped view of what the schema knows. The gates read exactly these
|
|
78
|
+
// four fields; `block` is required by the type and unused by every gate.
|
|
79
|
+
const asConfig = {
|
|
80
|
+
block: '',
|
|
81
|
+
sections: input.structure?.sections,
|
|
82
|
+
mediaSlots: input.structure?.mediaSlots,
|
|
83
|
+
frameTarget: input.structure?.frameTarget,
|
|
84
|
+
// SPEC-125 Phase 4 — `reading` and `dropcap` gate on a declared content
|
|
85
|
+
// capability rather than on the `body` section role, which was only ever
|
|
86
|
+
// a proxy for it.
|
|
87
|
+
provides: input.structure?.provides,
|
|
88
|
+
modifiers: Object.fromEntries([...(input.declaredAttributes ?? [])].map((name) => [name, { source: 'attribute' }])),
|
|
89
|
+
};
|
|
90
|
+
const unavailable = new Map();
|
|
91
|
+
for (const facet of UNIVERSAL_AXIS_FACETS) {
|
|
92
|
+
const described = facet.describeForRune(asConfig, '');
|
|
93
|
+
if (typeof described === 'string')
|
|
94
|
+
unavailable.set(facet.axis, described);
|
|
95
|
+
}
|
|
96
|
+
const available = new Set();
|
|
97
|
+
for (const [axis, names] of Object.entries(AXIS_ATTRIBUTES)) {
|
|
98
|
+
if (unavailable.has(axis))
|
|
99
|
+
continue;
|
|
100
|
+
for (const name of names)
|
|
101
|
+
available.add(name);
|
|
102
|
+
}
|
|
103
|
+
// Axes with no author-facing attributes (density, content-measure,
|
|
104
|
+
// content-place) can still be unavailable; they simply remove nothing here.
|
|
105
|
+
return { available, unavailable };
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=universal-attributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"universal-attributes.js","sourceRoot":"","sources":["../src/universal-attributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAIzF;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,eAAe,GAAgD;IAC3E,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC;IAC3B,4EAA4E;IAC5E,8EAA8E;IAC9E,2EAA2E;IAC3E,6EAA6E;IAC7E,4EAA4E;IAC5E,gCAAgC;IAChC,EAAE,EAAE;QACH,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,kBAAkB;QACrE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY;KACnE;IACD,KAAK,EAAE,CAAC,OAAO,CAAC;IAChB,OAAO,EAAE,CAAC,SAAS,CAAC;IACpB,KAAK,EAAE,CAAC,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,WAAW,CAAC;IACxB,UAAU,EAAE,CAAC,YAAY,CAAC;IAC1B,OAAO,EAAE,CAAC,SAAS,CAAC;IACpB,OAAO,EAAE,CAAC,S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,WAAW,CAC5B,CAAC,GAAG,CAAC,KAAK,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,WAAoB,EAAE,CAAC,CAAC,CAC7F;KACa,CAAC;IAEhB,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC9C,KAAK,MAAM,KAAK,IAAI,qBAAqB,EAAE,CAAC;QAC3C,MAAM,SAAS,GAAG,KAAK,CAAC,eAAe,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACtD,IAAI,OAAO,SAAS,KAAK,QAAQ;YAAE,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IACpC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;QAC7D,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,SAAS;QACpC,KAAK,MAAM,IAAI,IAAI,KAAK;YAAE,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IACD,mEAAmE;IACnE,4EAA4E;IAC5E,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AACnC,CAAC"}
|
package/dist/util.d.ts
CHANGED
|
@@ -14,9 +14,49 @@ export interface HeadingInfo {
|
|
|
14
14
|
/** Canonical name of the known section this heading belongs to, if any. */
|
|
15
15
|
knownSection?: string;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Build a heading's `id` from its plain text.
|
|
19
|
+
*
|
|
20
|
+
* The single implementation behind both the parse-time heading index
|
|
21
|
+
* (`extractHeadings`) and the rendered `<h*>` id (the `heading` node
|
|
22
|
+
* transform). They used to be two near-copies that had drifted apart — one
|
|
23
|
+
* stripped `?`, the other `?{}%` — so a heading containing `{`, `}` or `%` was
|
|
24
|
+
* indexed under one id and rendered under another (BUG-005).
|
|
25
|
+
*
|
|
26
|
+
* The rules are the ones an author writing an anchor by hand already assumes,
|
|
27
|
+
* and they match GitHub closely enough to be guessable: lowercase, drop
|
|
28
|
+
* punctuation, collapse whitespace and separator runs to a single `-`. Dropping
|
|
29
|
+
* punctuation also subsumes the reason `%` was stripped — a literal `%` not
|
|
30
|
+
* followed by a hex pair used to crash SvelteKit's prerender crawler in
|
|
31
|
+
* `decodeURI`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function headingSlug(text: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Collect a heading node's plain text, including the content of inline `code`.
|
|
36
|
+
*
|
|
37
|
+
* Concatenated rather than joined with a space: the AST's own text nodes carry
|
|
38
|
+
* the spacing, so joining would double it. Inline code used to be skipped
|
|
39
|
+
* entirely — `` ### `fileRoots` — named directories `` indexed as
|
|
40
|
+
* `" — named directories"`, losing the heading's actual subject (BUG-005).
|
|
41
|
+
*/
|
|
42
|
+
export declare function headingText(n: Node): string;
|
|
43
|
+
/**
|
|
44
|
+
* Collect the plain text of already-transformed children, walking into tags.
|
|
45
|
+
*
|
|
46
|
+
* The renderable counterpart to {@link headingText}: inline code is a `Tag` by
|
|
47
|
+
* this point, and a variable has been resolved to its value. Used for the
|
|
48
|
+
* rendered heading id, where both of those matter.
|
|
49
|
+
*/
|
|
50
|
+
export declare function renderableText(children: RenderableTreeNode[]): string;
|
|
17
51
|
/**
|
|
18
52
|
* Pre-scan an AST for heading nodes, extracting their text and generating
|
|
19
|
-
* IDs
|
|
53
|
+
* IDs with {@link headingSlug} — the same slug rules the `heading` node
|
|
54
|
+
* transform applies, so the index and the rendered anchor agree.
|
|
55
|
+
*
|
|
56
|
+
* The two necessarily read different phases: this runs at parse time, so a
|
|
57
|
+
* heading whose text comes from a variable (`### {% $row.name %}` inside a
|
|
58
|
+
* `{% data %}` body) is not knowable here and is indexed under its unresolved
|
|
59
|
+
* form. The rendered anchor, which is what a link targets, is correct.
|
|
20
60
|
*/
|
|
21
61
|
export declare function extractHeadings(node: Node): HeadingInfo[];
|
|
22
62
|
/**
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAoB7D;AAED,wBAAiB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS,CAAC,kBAAkB,CAAC,CAShE;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,2EAA2E;IAC3E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAoB7D;AAED,wBAAiB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS,CAAC,kBAAkB,CAAC,CAShE;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,2EAA2E;IAC3E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUhD;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CAQ3C;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAOrE;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,EAAE,CAsBzD;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAyBtD;AAED,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,qBAAqB,IAIpD,OAAO,IAAI,EAAE,oBAkCtB"}
|
package/dist/util.js
CHANGED
|
@@ -30,25 +30,83 @@ export function* walkTag(tag) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Build a heading's `id` from its plain text.
|
|
35
|
+
*
|
|
36
|
+
* The single implementation behind both the parse-time heading index
|
|
37
|
+
* (`extractHeadings`) and the rendered `<h*>` id (the `heading` node
|
|
38
|
+
* transform). They used to be two near-copies that had drifted apart — one
|
|
39
|
+
* stripped `?`, the other `?{}%` — so a heading containing `{`, `}` or `%` was
|
|
40
|
+
* indexed under one id and rendered under another (BUG-005).
|
|
41
|
+
*
|
|
42
|
+
* The rules are the ones an author writing an anchor by hand already assumes,
|
|
43
|
+
* and they match GitHub closely enough to be guessable: lowercase, drop
|
|
44
|
+
* punctuation, collapse whitespace and separator runs to a single `-`. Dropping
|
|
45
|
+
* punctuation also subsumes the reason `%` was stripped — a literal `%` not
|
|
46
|
+
* followed by a hex pair used to crash SvelteKit's prerender crawler in
|
|
47
|
+
* `decodeURI`.
|
|
48
|
+
*/
|
|
49
|
+
export function headingSlug(text) {
|
|
50
|
+
return text
|
|
51
|
+
.toLowerCase()
|
|
52
|
+
// Keep letters, numbers, whitespace and hyphens; drop everything else.
|
|
53
|
+
// Unicode-aware so non-ASCII headings keep their words rather than
|
|
54
|
+
// collapsing to an empty id.
|
|
55
|
+
.replace(/[^\p{L}\p{N}\s-]/gu, '')
|
|
56
|
+
.trim()
|
|
57
|
+
.replace(/[\s-]+/g, '-')
|
|
58
|
+
.replace(/^-+|-+$/g, '');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Collect a heading node's plain text, including the content of inline `code`.
|
|
62
|
+
*
|
|
63
|
+
* Concatenated rather than joined with a space: the AST's own text nodes carry
|
|
64
|
+
* the spacing, so joining would double it. Inline code used to be skipped
|
|
65
|
+
* entirely — `` ### `fileRoots` — named directories `` indexed as
|
|
66
|
+
* `" — named directories"`, losing the heading's actual subject (BUG-005).
|
|
67
|
+
*/
|
|
68
|
+
export function headingText(n) {
|
|
69
|
+
let text = '';
|
|
70
|
+
for (const child of n.walk()) {
|
|
71
|
+
if ((child.type === 'text' || child.type === 'code') && child.attributes.content) {
|
|
72
|
+
text += String(child.attributes.content);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return text;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Collect the plain text of already-transformed children, walking into tags.
|
|
79
|
+
*
|
|
80
|
+
* The renderable counterpart to {@link headingText}: inline code is a `Tag` by
|
|
81
|
+
* this point, and a variable has been resolved to its value. Used for the
|
|
82
|
+
* rendered heading id, where both of those matter.
|
|
83
|
+
*/
|
|
84
|
+
export function renderableText(children) {
|
|
85
|
+
let text = '';
|
|
86
|
+
for (const child of children) {
|
|
87
|
+
if (typeof child === 'string')
|
|
88
|
+
text += child;
|
|
89
|
+
else if (Markdoc.Tag.isTag(child))
|
|
90
|
+
text += renderableText(child.children ?? []);
|
|
91
|
+
}
|
|
92
|
+
return text;
|
|
93
|
+
}
|
|
33
94
|
/**
|
|
34
95
|
* Pre-scan an AST for heading nodes, extracting their text and generating
|
|
35
|
-
* IDs
|
|
96
|
+
* IDs with {@link headingSlug} — the same slug rules the `heading` node
|
|
97
|
+
* transform applies, so the index and the rendered anchor agree.
|
|
98
|
+
*
|
|
99
|
+
* The two necessarily read different phases: this runs at parse time, so a
|
|
100
|
+
* heading whose text comes from a variable (`### {% $row.name %}` inside a
|
|
101
|
+
* `{% data %}` body) is not knowable here and is indexed under its unresolved
|
|
102
|
+
* form. The rendered anchor, which is what a link targets, is correct.
|
|
36
103
|
*/
|
|
37
104
|
export function extractHeadings(node) {
|
|
38
105
|
const headings = [];
|
|
39
106
|
function walk(n) {
|
|
40
107
|
if (n.type === 'heading') {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
if (child.type === 'text' && child.attributes.content) {
|
|
44
|
-
textParts.push(child.attributes.content);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const text = textParts.join(' ');
|
|
48
|
-
const id = n.attributes.id || text
|
|
49
|
-
.replace(/[?]/g, '')
|
|
50
|
-
.replace(/\s+/g, '-')
|
|
51
|
-
.toLowerCase();
|
|
108
|
+
const text = headingText(n);
|
|
109
|
+
const id = n.attributes.id || headingSlug(text);
|
|
52
110
|
headings.push({
|
|
53
111
|
level: n.attributes.level,
|
|
54
112
|
text,
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources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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.33.0",
|
|
36
|
+
"@refrakt-md/transform": "0.33.0",
|
|
37
37
|
"@markdoc/markdoc": "0.4.0",
|
|
38
38
|
"reflect-metadata": "^0.2.0",
|
|
39
39
|
"fast-xml-parser": "4.5.1",
|