@driftsys/markspec 0.10.1 → 0.10.3
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/esm/collect/mod.d.ts +34 -0
- package/esm/collect/mod.d.ts.map +1 -0
- package/esm/collect/mod.js +37 -0
- package/esm/decl/mod.d.ts +18 -0
- package/esm/decl/mod.d.ts.map +1 -0
- package/esm/decl/mod.js +14 -0
- package/esm/decl/resolve.d.ts +104 -0
- package/esm/decl/resolve.d.ts.map +1 -0
- package/esm/decl/resolve.js +66 -0
- package/esm/decl/surfaces.d.ts +96 -0
- package/esm/decl/surfaces.d.ts.map +1 -0
- package/esm/decl/surfaces.js +122 -0
- package/esm/decl/table.d.ts +50 -0
- package/esm/decl/table.d.ts.map +1 -0
- package/esm/decl/table.js +124 -0
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +29 -1
- package/esm/gates/mod.d.ts +82 -0
- package/esm/gates/mod.d.ts.map +1 -0
- package/esm/gates/mod.js +139 -0
- package/esm/lint/runner.d.ts +26 -3
- package/esm/lint/runner.d.ts.map +1 -1
- package/esm/lint/runner.js +39 -9
- package/esm/lock/edge_drift.d.ts +31 -0
- package/esm/lock/edge_drift.d.ts.map +1 -0
- package/esm/lock/edge_drift.js +29 -0
- package/esm/lock/mod.d.ts +2 -0
- package/esm/lock/mod.d.ts.map +1 -1
- package/esm/lock/mod.js +1 -0
- package/esm/mod.d.ts +11 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +10 -4
- package/esm/model/mod.d.ts +8 -0
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +10 -0
- package/esm/model/profile.d.ts +8 -0
- package/esm/model/profile.d.ts.map +1 -1
- package/esm/parser/directives.d.ts +6 -0
- package/esm/parser/directives.d.ts.map +1 -1
- package/esm/parser/directives.js +17 -0
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +47 -11
- package/esm/profile/delivered.d.ts +22 -1
- package/esm/profile/delivered.d.ts.map +1 -1
- package/esm/profile/delivered.js +44 -1
- package/esm/profile/merge.js +1 -0
- package/esm/reporter/mod.d.ts.map +1 -1
- package/esm/reporter/mod.js +2 -3
- package/esm/typl/bullet.d.ts +13 -23
- package/esm/typl/bullet.d.ts.map +1 -1
- package/esm/typl/bullet.js +6 -40
- package/esm/typl/fence.d.ts +12 -21
- package/esm/typl/fence.d.ts.map +1 -1
- package/esm/typl/fence.js +5 -20
- package/esm/typl/inline.d.ts +15 -24
- package/esm/typl/inline.d.ts.map +1 -1
- package/esm/typl/inline.js +6 -44
- package/esm/typl/recognize.d.ts +14 -0
- package/esm/typl/recognize.d.ts.map +1 -0
- package/esm/typl/recognize.js +19 -0
- package/esm/util/fence.d.ts +8 -0
- package/esm/util/fence.d.ts.map +1 -1
- package/esm/util/fence.js +22 -0
- package/esm/validator/body_blocks.d.ts.map +1 -1
- package/esm/validator/body_blocks.js +3 -9
- package/esm/validator/corpus.d.ts.map +1 -1
- package/esm/validator/corpus.js +14 -12
- package/package.json +1 -1
- package/script/collect/mod.d.ts +34 -0
- package/script/collect/mod.d.ts.map +1 -0
- package/script/collect/mod.js +40 -0
- package/script/decl/mod.d.ts +18 -0
- package/script/decl/mod.d.ts.map +1 -0
- package/script/decl/mod.js +24 -0
- package/script/decl/resolve.d.ts +104 -0
- package/script/decl/resolve.d.ts.map +1 -0
- package/script/decl/resolve.js +70 -0
- package/script/decl/surfaces.d.ts +96 -0
- package/script/decl/surfaces.d.ts.map +1 -0
- package/script/decl/surfaces.js +128 -0
- package/script/decl/table.d.ts +50 -0
- package/script/decl/table.d.ts.map +1 -0
- package/script/decl/table.js +127 -0
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +29 -1
- package/script/gates/mod.d.ts +82 -0
- package/script/gates/mod.d.ts.map +1 -0
- package/script/gates/mod.js +144 -0
- package/script/lint/runner.d.ts +26 -3
- package/script/lint/runner.d.ts.map +1 -1
- package/script/lint/runner.js +39 -9
- package/script/lock/edge_drift.d.ts +31 -0
- package/script/lock/edge_drift.d.ts.map +1 -0
- package/script/lock/edge_drift.js +32 -0
- package/script/lock/mod.d.ts +2 -0
- package/script/lock/mod.d.ts.map +1 -1
- package/script/lock/mod.js +3 -1
- package/script/mod.d.ts +11 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +45 -29
- package/script/model/mod.d.ts +8 -0
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +11 -0
- package/script/model/profile.d.ts +8 -0
- package/script/model/profile.d.ts.map +1 -1
- package/script/parser/directives.d.ts +6 -0
- package/script/parser/directives.d.ts.map +1 -1
- package/script/parser/directives.js +18 -0
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +47 -11
- package/script/profile/delivered.d.ts +22 -1
- package/script/profile/delivered.d.ts.map +1 -1
- package/script/profile/delivered.js +45 -1
- package/script/profile/merge.js +1 -0
- package/script/reporter/mod.d.ts.map +1 -1
- package/script/reporter/mod.js +2 -3
- package/script/typl/bullet.d.ts +13 -23
- package/script/typl/bullet.d.ts.map +1 -1
- package/script/typl/bullet.js +6 -40
- package/script/typl/fence.d.ts +12 -21
- package/script/typl/fence.d.ts.map +1 -1
- package/script/typl/fence.js +5 -20
- package/script/typl/inline.d.ts +15 -24
- package/script/typl/inline.d.ts.map +1 -1
- package/script/typl/inline.js +6 -44
- package/script/typl/recognize.d.ts +14 -0
- package/script/typl/recognize.d.ts.map +1 -0
- package/script/typl/recognize.js +22 -0
- package/script/util/fence.d.ts +8 -0
- package/script/util/fence.d.ts.map +1 -1
- package/script/util/fence.js +23 -0
- package/script/validator/body_blocks.d.ts.map +1 -1
- package/script/validator/body_blocks.js +3 -9
- package/script/validator/corpus.d.ts.map +1 -1
- package/script/validator/corpus.js +14 -12
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/decl/resolve
|
|
3
|
+
*
|
|
4
|
+
* Entry-local base-resolution engine (uxil epic #717 §A). The DSL-agnostic
|
|
5
|
+
* *normative rule set* for resolving a relative reference against the base
|
|
6
|
+
* an enclosing declaration established. typl's published tier and uxil both
|
|
7
|
+
* consume it; the engine knows nothing about either vocabulary.
|
|
8
|
+
*
|
|
9
|
+
* The six rules from #722, and where each lives:
|
|
10
|
+
*
|
|
11
|
+
* 1. Only *declarations* create bases; *citations* never do. — The caller
|
|
12
|
+
* sets {@linkcode BaseScope.base} only for declaration scopes; a scope
|
|
13
|
+
* built from a citation leaves it `undefined`.
|
|
14
|
+
* 2. Bases are entry-local (no document-ambient scope). — The engine only
|
|
15
|
+
* ever walks the `parent` chain it is given; there is no global lookup.
|
|
16
|
+
* 3. Innermost base wins. — {@linkcode resolveRef} returns on the first
|
|
17
|
+
* ancestor (nearest first) that carries a base.
|
|
18
|
+
* 4. Scope is structural, never sequential. — The engine follows `parent`
|
|
19
|
+
* links only; siblings are unreachable, so reordering declarations can
|
|
20
|
+
* never rebind a ref.
|
|
21
|
+
* 5. Exactly one root declaration per declaring entry. —
|
|
22
|
+
* {@linkcode checkSingleRoot}.
|
|
23
|
+
* 6. Declarations/citations sit in code spans. — A surface concern
|
|
24
|
+
* (core/decl/surfaces + the DSL recognizer); the engine sees only the
|
|
25
|
+
* already-extracted ref token.
|
|
26
|
+
*
|
|
27
|
+
* The caller builds the {@linkcode BaseScope} chain from the entry's
|
|
28
|
+
* structural nesting (list membership, table membership) — that mapping is
|
|
29
|
+
* DSL- and surface-specific and lands with the table surface (S3) and the
|
|
30
|
+
* DSL consumers (S5/S7).
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* A structural scope in an entry's declaration tree. {@linkcode resolveRef}
|
|
34
|
+
* walks `parent` links from innermost to outermost.
|
|
35
|
+
*
|
|
36
|
+
* `base` is the base a *declaration* established at this scope, or
|
|
37
|
+
* `undefined` when this scope establishes none (a citation scope, or a
|
|
38
|
+
* structural container that declares nothing). Because the engine reaches
|
|
39
|
+
* enclosing scopes only through `parent`, siblings are invisible to one
|
|
40
|
+
* another and ordering within a level is irrelevant — the scope is purely
|
|
41
|
+
* structural (rule 4).
|
|
42
|
+
*/
|
|
43
|
+
export interface BaseScope {
|
|
44
|
+
/** The base declared at this scope, if any. */
|
|
45
|
+
readonly base?: string;
|
|
46
|
+
/** The enclosing scope, or `undefined` at the entry root. */
|
|
47
|
+
readonly parent?: BaseScope;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The DSL-specific reference operations the engine is parameterized by.
|
|
51
|
+
* Keeping these injected is what makes the engine vocabulary-agnostic: typl
|
|
52
|
+
* dotted paths and uxil `ux:` URIs supply their own notions of "absolute"
|
|
53
|
+
* and of how a base combines with a relative ref.
|
|
54
|
+
*/
|
|
55
|
+
export interface RefOps {
|
|
56
|
+
/** True when `ref` is already absolute and needs no base. */
|
|
57
|
+
readonly isAbsolute: (ref: string) => boolean;
|
|
58
|
+
/** Combine an enclosing `base` with a relative `ref` into a full ref. */
|
|
59
|
+
readonly join: (base: string, ref: string) => string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Outcome of {@linkcode resolveRef}. `no-base-in-scope` is returned for a
|
|
63
|
+
* relative ref that finds no base in any ancestor; the DSL host maps that
|
|
64
|
+
* reason to its own diagnostic code (typl TYPL-0xx, uxil UXIL-0xx).
|
|
65
|
+
*/
|
|
66
|
+
export type RefResolution = {
|
|
67
|
+
readonly ok: true;
|
|
68
|
+
readonly ref: string;
|
|
69
|
+
} | {
|
|
70
|
+
readonly ok: false;
|
|
71
|
+
readonly reason: "no-base-in-scope";
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Resolve `ref` at `scope`. An absolute ref passes through unchanged. A
|
|
75
|
+
* relative ref is joined with the base of the nearest enclosing scope that
|
|
76
|
+
* carries one (innermost wins, rule 3); a single join with that base only —
|
|
77
|
+
* bases are not accumulated up the chain, because each scope's `base` is
|
|
78
|
+
* already its fully-qualified prefix. A relative ref with no base in any
|
|
79
|
+
* ancestor yields `{ ok: false, reason: "no-base-in-scope" }`.
|
|
80
|
+
*
|
|
81
|
+
* `scope` may be `undefined` (a ref at the very top with no enclosing
|
|
82
|
+
* declaration); a relative ref there is likewise `no-base-in-scope`.
|
|
83
|
+
*/
|
|
84
|
+
export declare function resolveRef(ref: string, scope: BaseScope | undefined, ops: RefOps): RefResolution;
|
|
85
|
+
/**
|
|
86
|
+
* Outcome of {@linkcode checkSingleRoot}. On failure, `roots` carries the
|
|
87
|
+
* offending set so the DSL host can locate each one for its diagnostic.
|
|
88
|
+
*/
|
|
89
|
+
export type RootCheck<T> = {
|
|
90
|
+
readonly ok: true;
|
|
91
|
+
readonly root: T;
|
|
92
|
+
} | {
|
|
93
|
+
readonly ok: false;
|
|
94
|
+
readonly reason: "no-root" | "multiple-roots";
|
|
95
|
+
readonly roots: readonly T[];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Enforce the one-root invariant (rule 5): a declaring entry must have
|
|
99
|
+
* exactly one root declaration. Returns the sole root on success, or a
|
|
100
|
+
* `no-root` / `multiple-roots` failure carrying the offending set. Generic
|
|
101
|
+
* over the DSL's root-declaration type — the engine only counts.
|
|
102
|
+
*/
|
|
103
|
+
export declare function checkSingleRoot<T>(roots: readonly T[]): RootCheck<T>;
|
|
104
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/decl/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,SAAS;IACxB,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6DAA6D;IAC7D,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;CAC7B;AAED;;;;;GAKG;AACH,MAAM,WAAW,MAAM;IACrB,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAC9C,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CACtD;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC3C;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,SAAS,GAAG,SAAS,EAC5B,GAAG,EAAE,MAAM,GACV,aAAa,CAMf;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IACnB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACvC;IACA,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,gBAAgB,CAAC;IAC9C,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC;CAC9B,CAAC;AAEJ;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAOpE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/decl/resolve
|
|
4
|
+
*
|
|
5
|
+
* Entry-local base-resolution engine (uxil epic #717 §A). The DSL-agnostic
|
|
6
|
+
* *normative rule set* for resolving a relative reference against the base
|
|
7
|
+
* an enclosing declaration established. typl's published tier and uxil both
|
|
8
|
+
* consume it; the engine knows nothing about either vocabulary.
|
|
9
|
+
*
|
|
10
|
+
* The six rules from #722, and where each lives:
|
|
11
|
+
*
|
|
12
|
+
* 1. Only *declarations* create bases; *citations* never do. — The caller
|
|
13
|
+
* sets {@linkcode BaseScope.base} only for declaration scopes; a scope
|
|
14
|
+
* built from a citation leaves it `undefined`.
|
|
15
|
+
* 2. Bases are entry-local (no document-ambient scope). — The engine only
|
|
16
|
+
* ever walks the `parent` chain it is given; there is no global lookup.
|
|
17
|
+
* 3. Innermost base wins. — {@linkcode resolveRef} returns on the first
|
|
18
|
+
* ancestor (nearest first) that carries a base.
|
|
19
|
+
* 4. Scope is structural, never sequential. — The engine follows `parent`
|
|
20
|
+
* links only; siblings are unreachable, so reordering declarations can
|
|
21
|
+
* never rebind a ref.
|
|
22
|
+
* 5. Exactly one root declaration per declaring entry. —
|
|
23
|
+
* {@linkcode checkSingleRoot}.
|
|
24
|
+
* 6. Declarations/citations sit in code spans. — A surface concern
|
|
25
|
+
* (core/decl/surfaces + the DSL recognizer); the engine sees only the
|
|
26
|
+
* already-extracted ref token.
|
|
27
|
+
*
|
|
28
|
+
* The caller builds the {@linkcode BaseScope} chain from the entry's
|
|
29
|
+
* structural nesting (list membership, table membership) — that mapping is
|
|
30
|
+
* DSL- and surface-specific and lands with the table surface (S3) and the
|
|
31
|
+
* DSL consumers (S5/S7).
|
|
32
|
+
*/
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.resolveRef = resolveRef;
|
|
35
|
+
exports.checkSingleRoot = checkSingleRoot;
|
|
36
|
+
/**
|
|
37
|
+
* Resolve `ref` at `scope`. An absolute ref passes through unchanged. A
|
|
38
|
+
* relative ref is joined with the base of the nearest enclosing scope that
|
|
39
|
+
* carries one (innermost wins, rule 3); a single join with that base only —
|
|
40
|
+
* bases are not accumulated up the chain, because each scope's `base` is
|
|
41
|
+
* already its fully-qualified prefix. A relative ref with no base in any
|
|
42
|
+
* ancestor yields `{ ok: false, reason: "no-base-in-scope" }`.
|
|
43
|
+
*
|
|
44
|
+
* `scope` may be `undefined` (a ref at the very top with no enclosing
|
|
45
|
+
* declaration); a relative ref there is likewise `no-base-in-scope`.
|
|
46
|
+
*/
|
|
47
|
+
function resolveRef(ref, scope, ops) {
|
|
48
|
+
if (ops.isAbsolute(ref))
|
|
49
|
+
return { ok: true, ref };
|
|
50
|
+
for (let s = scope; s !== undefined; s = s.parent) {
|
|
51
|
+
if (s.base !== undefined)
|
|
52
|
+
return { ok: true, ref: ops.join(s.base, ref) };
|
|
53
|
+
}
|
|
54
|
+
return { ok: false, reason: "no-base-in-scope" };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Enforce the one-root invariant (rule 5): a declaring entry must have
|
|
58
|
+
* exactly one root declaration. Returns the sole root on success, or a
|
|
59
|
+
* `no-root` / `multiple-roots` failure carrying the offending set. Generic
|
|
60
|
+
* over the DSL's root-declaration type — the engine only counts.
|
|
61
|
+
*/
|
|
62
|
+
function checkSingleRoot(roots) {
|
|
63
|
+
if (roots.length === 1)
|
|
64
|
+
return { ok: true, root: roots[0] };
|
|
65
|
+
return {
|
|
66
|
+
ok: false,
|
|
67
|
+
reason: roots.length === 0 ? "no-root" : "multiple-roots",
|
|
68
|
+
roots,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/decl/surfaces
|
|
3
|
+
*
|
|
4
|
+
* DSL-agnostic declaration-surface machinery. Walks a MarkSpec entry body
|
|
5
|
+
* and extracts every *declaration site* on each of the three embedding
|
|
6
|
+
* surfaces, returning a common declaration node:
|
|
7
|
+
*
|
|
8
|
+
* - **fence** — a fenced code block whose info-string a DSL claims
|
|
9
|
+
* (e.g. ```typl). {@linkcode extractFenceDeclarations}
|
|
10
|
+
* - **bullet** — a list item whose first paragraph is a declaration.
|
|
11
|
+
* {@linkcode extractBulletDeclarations}
|
|
12
|
+
* - **inline** — a CommonMark code span whose text is a declaration.
|
|
13
|
+
* {@linkcode extractInlineDeclarations}
|
|
14
|
+
*
|
|
15
|
+
* Each walker is parameterized by a *recognizer* — the only DSL-specific
|
|
16
|
+
* input — and knows nothing about typl, uxil, or any concrete vocabulary.
|
|
17
|
+
* A DSL host (typl today; uxil and the table surface later) supplies the
|
|
18
|
+
* recognizer and consumes the returned {@linkcode BlockDeclaration} /
|
|
19
|
+
* {@linkcode InlineDeclaration} nodes.
|
|
20
|
+
*
|
|
21
|
+
* Extracted from the typl surface adapters (ADR-019) so §A of the uxil
|
|
22
|
+
* epic (#717) can share one substrate. typl's fence / bullet / inline
|
|
23
|
+
* modules are thin adapters over these functions and their observable
|
|
24
|
+
* output is unchanged.
|
|
25
|
+
*/
|
|
26
|
+
import type { BodyBlock, SourceRange } from "../ast/nodes.js";
|
|
27
|
+
import type { BodyToken, SourceLocation } from "../model/mod.js";
|
|
28
|
+
/**
|
|
29
|
+
* A declaration found on a block surface (fenced code block or bullet
|
|
30
|
+
* paragraph). Carries the raw DSL `source` and the node's body-relative
|
|
31
|
+
* {@linkcode SourceRange} — the anchor a DSL host uses to bridge parse
|
|
32
|
+
* diagnostics back to file positions.
|
|
33
|
+
*/
|
|
34
|
+
export interface BlockDeclaration {
|
|
35
|
+
/** Raw DSL source: the fence body, or the bullet's paragraph text. */
|
|
36
|
+
readonly source: string;
|
|
37
|
+
/** Source range of the fence, or of the bullet's first paragraph. */
|
|
38
|
+
readonly range: SourceRange;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A declaration found in an inline code span. Carries the raw DSL
|
|
42
|
+
* `source` (backtick delimiters stripped) and the span's file-relative
|
|
43
|
+
* {@linkcode SourceLocation} (the position `Entry.bodyTokens` records).
|
|
44
|
+
*/
|
|
45
|
+
export interface InlineDeclaration {
|
|
46
|
+
/** Raw DSL source: the code span's inner text, backticks stripped. */
|
|
47
|
+
readonly source: string;
|
|
48
|
+
/** File-relative location of the code span. */
|
|
49
|
+
readonly location: SourceLocation;
|
|
50
|
+
}
|
|
51
|
+
/** Recognizer for the fence surface: does this info-string host the DSL? */
|
|
52
|
+
export type FenceRecognizer = (lang: string | undefined) => boolean;
|
|
53
|
+
/** Recognizer for the bullet / inline surfaces: is this text a declaration? */
|
|
54
|
+
export type TextRecognizer = (text: string) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Walk a body AST and return every fenced code block whose info-string
|
|
57
|
+
* satisfies `matchLang`. Recurses into container nodes (ListNode via
|
|
58
|
+
* ListItemNode.blocks) so fences nested inside list items are found.
|
|
59
|
+
*
|
|
60
|
+
* BlockquoteNode and NoteNode carry only InlineContent (not nested
|
|
61
|
+
* BodyBlock[]), so they are not recursed into. Returns declarations in
|
|
62
|
+
* source order (depth-first traversal).
|
|
63
|
+
*/
|
|
64
|
+
export declare function extractFenceDeclarations(blocks: readonly BodyBlock[], matchLang: FenceRecognizer): readonly BlockDeclaration[];
|
|
65
|
+
/**
|
|
66
|
+
* Walk a body AST and return every bullet-list item whose first paragraph
|
|
67
|
+
* satisfies `matchText`. Recurses through ListNode → ListItemNode.blocks
|
|
68
|
+
* for nested lists. Mixed lists are supported: items whose first paragraph
|
|
69
|
+
* matches are extracted; non-matching bullets are left alone.
|
|
70
|
+
*
|
|
71
|
+
* Returns declarations in source order (depth-first).
|
|
72
|
+
*/
|
|
73
|
+
export declare function extractBulletDeclarations(blocks: readonly BodyBlock[], matchText: TextRecognizer): readonly BlockDeclaration[];
|
|
74
|
+
/**
|
|
75
|
+
* Strip the surrounding backtick delimiter(s) from an inline-code token's
|
|
76
|
+
* `text` field. `body_tokens.ts` stores inline-code text as `` `value` ``
|
|
77
|
+
* (with backtick delimiters); a DSL recognizer and parser need the inner
|
|
78
|
+
* value only.
|
|
79
|
+
*
|
|
80
|
+
* Handles both single-backtick (`` `…` ``) and double-backtick (` ``…`` `)
|
|
81
|
+
* delimiters. Returns the original string unchanged when it does not start
|
|
82
|
+
* and end with a matching backtick fence.
|
|
83
|
+
*/
|
|
84
|
+
export declare function stripCodeSpanDelimiters(text: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Filter `bodyTokens` to inline-code spans whose contents (backticks
|
|
87
|
+
* stripped) satisfy `matchText`. Returns declarations in source order
|
|
88
|
+
* (the bodyTokens contract guarantees source order).
|
|
89
|
+
*
|
|
90
|
+
* `inline-code` tokens store their `text` field with surrounding backtick
|
|
91
|
+
* delimiters (e.g. `` `$X : signal` ``). This function strips those
|
|
92
|
+
* delimiters via {@linkcode stripCodeSpanDelimiters} before recognizing
|
|
93
|
+
* and before setting `source`, so the DSL parser receives the raw source.
|
|
94
|
+
*/
|
|
95
|
+
export declare function extractInlineDeclarations(bodyTokens: readonly BodyToken[], matchText: TextRecognizer): readonly InlineDeclaration[];
|
|
96
|
+
//# sourceMappingURL=surfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surfaces.d.ts","sourceRoot":"","sources":["../../src/decl/surfaces.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,+CAA+C;IAC/C,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;CACnC;AAED,4EAA4E;AAC5E,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC;AAEpE,+EAA+E;AAC/E,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;AAEvD;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,SAAS,EAAE,eAAe,GACzB,SAAS,gBAAgB,EAAE,CAY7B;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,SAAS,EAAE,cAAc,GACxB,SAAS,gBAAgB,EAAE,CAwB7B;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ5D;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,SAAS,SAAS,EAAE,EAChC,SAAS,EAAE,cAAc,GACxB,SAAS,iBAAiB,EAAE,CAS9B"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/decl/surfaces
|
|
4
|
+
*
|
|
5
|
+
* DSL-agnostic declaration-surface machinery. Walks a MarkSpec entry body
|
|
6
|
+
* and extracts every *declaration site* on each of the three embedding
|
|
7
|
+
* surfaces, returning a common declaration node:
|
|
8
|
+
*
|
|
9
|
+
* - **fence** — a fenced code block whose info-string a DSL claims
|
|
10
|
+
* (e.g. ```typl). {@linkcode extractFenceDeclarations}
|
|
11
|
+
* - **bullet** — a list item whose first paragraph is a declaration.
|
|
12
|
+
* {@linkcode extractBulletDeclarations}
|
|
13
|
+
* - **inline** — a CommonMark code span whose text is a declaration.
|
|
14
|
+
* {@linkcode extractInlineDeclarations}
|
|
15
|
+
*
|
|
16
|
+
* Each walker is parameterized by a *recognizer* — the only DSL-specific
|
|
17
|
+
* input — and knows nothing about typl, uxil, or any concrete vocabulary.
|
|
18
|
+
* A DSL host (typl today; uxil and the table surface later) supplies the
|
|
19
|
+
* recognizer and consumes the returned {@linkcode BlockDeclaration} /
|
|
20
|
+
* {@linkcode InlineDeclaration} nodes.
|
|
21
|
+
*
|
|
22
|
+
* Extracted from the typl surface adapters (ADR-019) so §A of the uxil
|
|
23
|
+
* epic (#717) can share one substrate. typl's fence / bullet / inline
|
|
24
|
+
* modules are thin adapters over these functions and their observable
|
|
25
|
+
* output is unchanged.
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.extractFenceDeclarations = extractFenceDeclarations;
|
|
29
|
+
exports.extractBulletDeclarations = extractBulletDeclarations;
|
|
30
|
+
exports.stripCodeSpanDelimiters = stripCodeSpanDelimiters;
|
|
31
|
+
exports.extractInlineDeclarations = extractInlineDeclarations;
|
|
32
|
+
/**
|
|
33
|
+
* Walk a body AST and return every fenced code block whose info-string
|
|
34
|
+
* satisfies `matchLang`. Recurses into container nodes (ListNode via
|
|
35
|
+
* ListItemNode.blocks) so fences nested inside list items are found.
|
|
36
|
+
*
|
|
37
|
+
* BlockquoteNode and NoteNode carry only InlineContent (not nested
|
|
38
|
+
* BodyBlock[]), so they are not recursed into. Returns declarations in
|
|
39
|
+
* source order (depth-first traversal).
|
|
40
|
+
*/
|
|
41
|
+
function extractFenceDeclarations(blocks, matchLang) {
|
|
42
|
+
const results = [];
|
|
43
|
+
for (const block of blocks) {
|
|
44
|
+
if (block.kind === "code" && matchLang(block.lang)) {
|
|
45
|
+
results.push({ source: block.text, range: block.range });
|
|
46
|
+
}
|
|
47
|
+
else if (block.kind === "list") {
|
|
48
|
+
for (const item of block.items) {
|
|
49
|
+
results.push(...extractFenceDeclarations(item.blocks, matchLang));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return results;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Walk a body AST and return every bullet-list item whose first paragraph
|
|
57
|
+
* satisfies `matchText`. Recurses through ListNode → ListItemNode.blocks
|
|
58
|
+
* for nested lists. Mixed lists are supported: items whose first paragraph
|
|
59
|
+
* matches are extracted; non-matching bullets are left alone.
|
|
60
|
+
*
|
|
61
|
+
* Returns declarations in source order (depth-first).
|
|
62
|
+
*/
|
|
63
|
+
function extractBulletDeclarations(blocks, matchText) {
|
|
64
|
+
const results = [];
|
|
65
|
+
for (const block of blocks) {
|
|
66
|
+
if (block.kind === "list") {
|
|
67
|
+
for (const item of block.items) {
|
|
68
|
+
if (item.blocks.length === 0)
|
|
69
|
+
continue;
|
|
70
|
+
const first = item.blocks[0];
|
|
71
|
+
if (first.kind === "paragraph") {
|
|
72
|
+
if (matchText(first.content.text)) {
|
|
73
|
+
results.push({ source: first.content.text, range: first.range });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Recurse into nested blocks (the item may itself contain a list).
|
|
77
|
+
if (item.blocks.length > 1) {
|
|
78
|
+
results.push(...extractBulletDeclarations(item.blocks.slice(1), matchText));
|
|
79
|
+
}
|
|
80
|
+
else if (first.kind === "list") {
|
|
81
|
+
results.push(...extractBulletDeclarations([first], matchText));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return results;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Strip the surrounding backtick delimiter(s) from an inline-code token's
|
|
90
|
+
* `text` field. `body_tokens.ts` stores inline-code text as `` `value` ``
|
|
91
|
+
* (with backtick delimiters); a DSL recognizer and parser need the inner
|
|
92
|
+
* value only.
|
|
93
|
+
*
|
|
94
|
+
* Handles both single-backtick (`` `…` ``) and double-backtick (` ``…`` `)
|
|
95
|
+
* delimiters. Returns the original string unchanged when it does not start
|
|
96
|
+
* and end with a matching backtick fence.
|
|
97
|
+
*/
|
|
98
|
+
function stripCodeSpanDelimiters(text) {
|
|
99
|
+
if (text.startsWith("``") && text.endsWith("``") && text.length > 4) {
|
|
100
|
+
return text.slice(2, -2);
|
|
101
|
+
}
|
|
102
|
+
if (text.startsWith("`") && text.endsWith("`") && text.length > 2) {
|
|
103
|
+
return text.slice(1, -1);
|
|
104
|
+
}
|
|
105
|
+
return text;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Filter `bodyTokens` to inline-code spans whose contents (backticks
|
|
109
|
+
* stripped) satisfy `matchText`. Returns declarations in source order
|
|
110
|
+
* (the bodyTokens contract guarantees source order).
|
|
111
|
+
*
|
|
112
|
+
* `inline-code` tokens store their `text` field with surrounding backtick
|
|
113
|
+
* delimiters (e.g. `` `$X : signal` ``). This function strips those
|
|
114
|
+
* delimiters via {@linkcode stripCodeSpanDelimiters} before recognizing
|
|
115
|
+
* and before setting `source`, so the DSL parser receives the raw source.
|
|
116
|
+
*/
|
|
117
|
+
function extractInlineDeclarations(bodyTokens, matchText) {
|
|
118
|
+
const results = [];
|
|
119
|
+
for (const token of bodyTokens) {
|
|
120
|
+
if (token.kind !== "inline-code")
|
|
121
|
+
continue;
|
|
122
|
+
const inner = stripCodeSpanDelimiters(token.text);
|
|
123
|
+
if (!matchText(inner))
|
|
124
|
+
continue;
|
|
125
|
+
results.push({ source: inner, location: token.location });
|
|
126
|
+
}
|
|
127
|
+
return results;
|
|
128
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/decl/table
|
|
3
|
+
*
|
|
4
|
+
* Table declaration surface (uxil epic #717 §A / S3). A fourth embedding
|
|
5
|
+
* surface on the shared declaration machinery (alongside fence, bullet, and
|
|
6
|
+
* inline): each **data row** of a GFM table is one declaration, and the
|
|
7
|
+
* table's `Table:` caption may carry a base that the entry-local resolver
|
|
8
|
+
* (S4) consumes.
|
|
9
|
+
*
|
|
10
|
+
* DSL-agnostic, like its siblings: the caller supplies a `rowToSource`
|
|
11
|
+
* recognizer that maps a row's cell texts to a declaration source (or
|
|
12
|
+
* `undefined` to skip a non-declaration / malformed row), and parses the
|
|
13
|
+
* actual base ref out of the surfaced {@linkcode TableRowDeclaration.captionText}
|
|
14
|
+
* itself — the caption's ref grammar is DSL-specific.
|
|
15
|
+
*
|
|
16
|
+
* Row positions: a {@linkcode TableNode} carries one range for the whole
|
|
17
|
+
* table and its verbatim `raw` source, but rows have no individual range
|
|
18
|
+
* (cells are stored as text only). Per-row ranges are therefore derived
|
|
19
|
+
* from the table's start line plus the row's index, past the GFM header and
|
|
20
|
+
* delimiter lines.
|
|
21
|
+
*/
|
|
22
|
+
import type { BodyBlock } from "../ast/nodes.js";
|
|
23
|
+
import type { BlockDeclaration } from "./surfaces.js";
|
|
24
|
+
/**
|
|
25
|
+
* A declaration found on one data row of a table. Extends the shared
|
|
26
|
+
* {@linkcode BlockDeclaration} (`source` = the row reduced to a declaration
|
|
27
|
+
* by the DSL's recognizer; `range` = the row's line-precise span) with
|
|
28
|
+
* `captionText`: the enclosing table's `Table:` caption text, when the table
|
|
29
|
+
* has an adjacent one — the DSL parses a base ref out of it and hands that
|
|
30
|
+
* to the resolver (S4).
|
|
31
|
+
*/
|
|
32
|
+
export interface TableRowDeclaration extends BlockDeclaration {
|
|
33
|
+
/** The enclosing table's `Table:` caption text, if any. */
|
|
34
|
+
readonly captionText?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Maps a data row's cell texts to a declaration source, or returns
|
|
38
|
+
* `undefined` to skip the row (not a declaration, or malformed). The only
|
|
39
|
+
* DSL-specific input to {@linkcode extractTableDeclarations}.
|
|
40
|
+
*/
|
|
41
|
+
export type RowRecognizer = (cells: readonly string[]) => string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Walk a body AST and return a declaration for every table data row the
|
|
44
|
+
* `rowToSource` recognizer accepts, in source order. Recurses into
|
|
45
|
+
* container nodes (ListNode via ListItemNode.blocks) so tables nested
|
|
46
|
+
* inside list items are found. Rows the recognizer skips (`undefined`)
|
|
47
|
+
* contribute nothing — the malformed-row case.
|
|
48
|
+
*/
|
|
49
|
+
export declare function extractTableDeclarations(blocks: readonly BodyBlock[], rowToSource: RowRecognizer): readonly TableRowDeclaration[];
|
|
50
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/decl/table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EACV,SAAS,EAIV,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB;IAC3D,2DAA2D;IAC3D,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,KAAK,MAAM,GAAG,SAAS,CAAC;AAM7E;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,WAAW,EAAE,aAAa,GACzB,SAAS,mBAAmB,EAAE,CAIhC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/decl/table
|
|
4
|
+
*
|
|
5
|
+
* Table declaration surface (uxil epic #717 §A / S3). A fourth embedding
|
|
6
|
+
* surface on the shared declaration machinery (alongside fence, bullet, and
|
|
7
|
+
* inline): each **data row** of a GFM table is one declaration, and the
|
|
8
|
+
* table's `Table:` caption may carry a base that the entry-local resolver
|
|
9
|
+
* (S4) consumes.
|
|
10
|
+
*
|
|
11
|
+
* DSL-agnostic, like its siblings: the caller supplies a `rowToSource`
|
|
12
|
+
* recognizer that maps a row's cell texts to a declaration source (or
|
|
13
|
+
* `undefined` to skip a non-declaration / malformed row), and parses the
|
|
14
|
+
* actual base ref out of the surfaced {@linkcode TableRowDeclaration.captionText}
|
|
15
|
+
* itself — the caption's ref grammar is DSL-specific.
|
|
16
|
+
*
|
|
17
|
+
* Row positions: a {@linkcode TableNode} carries one range for the whole
|
|
18
|
+
* table and its verbatim `raw` source, but rows have no individual range
|
|
19
|
+
* (cells are stored as text only). Per-row ranges are therefore derived
|
|
20
|
+
* from the table's start line plus the row's index, past the GFM header and
|
|
21
|
+
* delimiter lines.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.extractTableDeclarations = extractTableDeclarations;
|
|
25
|
+
/** GFM layout offset: a data row at `rows[i]` sits `i` lines past the
|
|
26
|
+
* header (line 0) and delimiter (line 1) rows in the table's raw source. */
|
|
27
|
+
const HEADER_AND_DELIMITER_LINES = 2;
|
|
28
|
+
/**
|
|
29
|
+
* Walk a body AST and return a declaration for every table data row the
|
|
30
|
+
* `rowToSource` recognizer accepts, in source order. Recurses into
|
|
31
|
+
* container nodes (ListNode via ListItemNode.blocks) so tables nested
|
|
32
|
+
* inside list items are found. Rows the recognizer skips (`undefined`)
|
|
33
|
+
* contribute nothing — the malformed-row case.
|
|
34
|
+
*/
|
|
35
|
+
function extractTableDeclarations(blocks, rowToSource) {
|
|
36
|
+
const results = [];
|
|
37
|
+
walk(blocks, rowToSource, results);
|
|
38
|
+
return results;
|
|
39
|
+
}
|
|
40
|
+
function walk(blocks, rowToSource, out) {
|
|
41
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
42
|
+
const block = blocks[i];
|
|
43
|
+
if (block.kind === "table") {
|
|
44
|
+
const captionText = adjacentTableCaption(blocks, i);
|
|
45
|
+
const rawLines = block.raw.split("\n");
|
|
46
|
+
for (let r = 0; r < block.rows.length; r++) {
|
|
47
|
+
const cells = block.rows[r].map((cell) => cell.text);
|
|
48
|
+
const source = rowToSource(cells);
|
|
49
|
+
if (source === undefined)
|
|
50
|
+
continue;
|
|
51
|
+
out.push({
|
|
52
|
+
source,
|
|
53
|
+
range: rowRange(block, rawLines, r),
|
|
54
|
+
...(captionText !== undefined ? { captionText } : {}),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else if (block.kind === "list") {
|
|
59
|
+
for (const item of block.items)
|
|
60
|
+
walk(item.blocks, rowToSource, out);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Return the text of the `Table:` caption that captions the table at
|
|
66
|
+
* `blocks[index]`, or `undefined` when there is none.
|
|
67
|
+
*
|
|
68
|
+
* Pairing is by local adjacency, re-deriving the above/below rule from the
|
|
69
|
+
* neighbours rather than trusting `CaptionNode.position`: the builder assigns
|
|
70
|
+
* `position` only for top-level blocks (`assignCaptionPositions` in
|
|
71
|
+
* core/ast/build.ts), so a caption inside a list item keeps the default
|
|
72
|
+
* `"below"` and cannot be trusted. A `Table:` caption immediately before the
|
|
73
|
+
* table captions it (the table is the caption's next captionable block); one
|
|
74
|
+
* immediately after captions it only when no captionable block follows the
|
|
75
|
+
* caption — otherwise that caption belongs to the following block.
|
|
76
|
+
*/
|
|
77
|
+
function adjacentTableCaption(blocks, index) {
|
|
78
|
+
const prev = blocks[index - 1];
|
|
79
|
+
if (isTableCaption(prev))
|
|
80
|
+
return prev.text;
|
|
81
|
+
const next = blocks[index + 1];
|
|
82
|
+
if (isTableCaption(next) && !isCaptionable(blocks[index + 2])) {
|
|
83
|
+
return next.text;
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
function isTableCaption(block) {
|
|
88
|
+
return block?.kind === "caption" && block.keyword === "Table";
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Block kinds a caption can caption (mirrors the captionable set in
|
|
92
|
+
* `assignCaptionPositions`, core/ast/build.ts). Used to decide whether a
|
|
93
|
+
* caption that follows a table belongs to that table or to a later
|
|
94
|
+
* captionable block.
|
|
95
|
+
*/
|
|
96
|
+
function isCaptionable(block) {
|
|
97
|
+
if (block === undefined)
|
|
98
|
+
return false;
|
|
99
|
+
switch (block.kind) {
|
|
100
|
+
case "figure":
|
|
101
|
+
case "table":
|
|
102
|
+
case "code":
|
|
103
|
+
case "feature":
|
|
104
|
+
case "math":
|
|
105
|
+
case "list":
|
|
106
|
+
return true;
|
|
107
|
+
default:
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The line-precise range of data row `rowIndex`. The table's `range.start`
|
|
113
|
+
* is the header line; the data row sits `HEADER_AND_DELIMITER_LINES +
|
|
114
|
+
* rowIndex` lines below it, at the table's start column. `raw` is de-indented
|
|
115
|
+
* by `verbatimSlice`, so adding the de-indented row length to the table's
|
|
116
|
+
* column yields the true source span — correct for both top-level (column 1)
|
|
117
|
+
* and list-nested (indented) tables.
|
|
118
|
+
*/
|
|
119
|
+
function rowRange(table, rawLines, rowIndex) {
|
|
120
|
+
const line = table.range.start.line + HEADER_AND_DELIMITER_LINES + rowIndex;
|
|
121
|
+
const column = table.range.start.column;
|
|
122
|
+
const rawLine = rawLines[HEADER_AND_DELIMITER_LINES + rowIndex] ?? "";
|
|
123
|
+
return {
|
|
124
|
+
start: { line, column },
|
|
125
|
+
end: { line, column: column + rawLine.length },
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/formatter/mod.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAGX,MAAM,iBAAiB,CAAC;AA2BzB,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AAGrB;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAc/D;AAmSD,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,MAAM,CAAC;IACrC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IAC9B;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,cAAc,CAAC;CAC/C;AAED,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AA2BD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,aAAa,GACtB,YAAY,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/formatter/mod.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAGX,MAAM,iBAAiB,CAAC;AA2BzB,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AAGrB;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAc/D;AAmSD,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,MAAM,CAAC;IACrC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IAC9B;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,cAAc,CAAC;CAC/C;AAED,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AA2BD;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,aAAa,GACtB,YAAY,CAgQd;AA4DD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAmB/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,SAAS,EAAE,GACtB,SAAS,EAAE,CA2Bb;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,SAAS,EAAE,EACvB,MAAM,EAAE,MAAM,GACb,MAAM,CAKR;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,CAcR;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CA2B5C"}
|
package/script/formatter/mod.js
CHANGED
|
@@ -423,11 +423,39 @@ function format(markdown, options) {
|
|
|
423
423
|
for (const entry of sorted) {
|
|
424
424
|
const indent = (entry.location.column - 1) + 2;
|
|
425
425
|
let attrs = [...entry.rawAttributes];
|
|
426
|
+
const titleLineIdx = entry.location.line - 1;
|
|
427
|
+
// #686: a title that soft-wraps onto extra physical lines is a single
|
|
428
|
+
// Markdown paragraph, but the line-based passes here and in
|
|
429
|
+
// `emitBodyViaAst` (which takes `titleLineIdx + 1` as the body start)
|
|
430
|
+
// assume the title occupies one physical line. Collapse the wrapped
|
|
431
|
+
// title onto a single line so Id stamping and body splicing land on the
|
|
432
|
+
// right lines and the continuation is not clobbered or dropped. The
|
|
433
|
+
// parser already folded the title text on the model side; this repairs
|
|
434
|
+
// the raw buffer to match. The scan runs from the title line to the
|
|
435
|
+
// first blank line (the title/body separator), bounded above by the
|
|
436
|
+
// attribute block so a malformed entry with no blank line before its
|
|
437
|
+
// trailer cannot swallow it.
|
|
438
|
+
if (titleLineIdx >= 0 && titleLineIdx < lines.length) {
|
|
439
|
+
const attrRange = findAttributeBlockRange(lines, entry.location.line, indent);
|
|
440
|
+
const limit = attrRange ? attrRange.start : lines.length;
|
|
441
|
+
let titleEnd = titleLineIdx;
|
|
442
|
+
while (titleEnd + 1 < limit && lines[titleEnd + 1].trim() !== "") {
|
|
443
|
+
titleEnd++;
|
|
444
|
+
}
|
|
445
|
+
if (titleEnd > titleLineIdx) {
|
|
446
|
+
const collapsed = lines[titleLineIdx].replace(/\s+$/, "") + " " +
|
|
447
|
+
lines
|
|
448
|
+
.slice(titleLineIdx + 1, titleEnd + 1)
|
|
449
|
+
.map((l) => l.trim())
|
|
450
|
+
.join(" ");
|
|
451
|
+
lines.splice(titleLineIdx, titleEnd - titleLineIdx + 1, collapsed);
|
|
452
|
+
changed = true;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
426
455
|
// Title-line bullet canonicalisation per spec §3.2: rewrite `*`
|
|
427
456
|
// or `+` to `-`. The list-item position from the parser is the
|
|
428
457
|
// line carrying the bullet marker; we only touch the marker
|
|
429
458
|
// character itself, leaving the rest of the title alone.
|
|
430
|
-
const titleLineIdx = entry.location.line - 1;
|
|
431
459
|
if (titleLineIdx >= 0 && titleLineIdx < lines.length) {
|
|
432
460
|
const titleLine = lines[titleLineIdx];
|
|
433
461
|
const markerCol = entry.location.column - 1;
|