@driftsys/markspec 0.4.0 → 0.5.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/esm/ast/build.d.ts +70 -0
- package/esm/ast/build.d.ts.map +1 -0
- package/esm/ast/build.js +605 -0
- package/esm/ast/equivalence.d.ts +18 -0
- package/esm/ast/equivalence.d.ts.map +1 -0
- package/esm/ast/equivalence.js +56 -0
- package/esm/ast/nodes.d.ts +221 -0
- package/esm/ast/nodes.d.ts.map +1 -0
- package/esm/ast/nodes.js +12 -0
- package/esm/ast/normalize.d.ts +67 -0
- package/esm/ast/normalize.d.ts.map +1 -0
- package/esm/ast/normalize.js +255 -0
- package/esm/ast/render.d.ts +34 -0
- package/esm/ast/render.d.ts.map +1 -0
- package/esm/ast/render.js +215 -0
- package/esm/compiler/inverses.d.ts +2 -8
- package/esm/compiler/inverses.d.ts.map +1 -1
- package/esm/compiler/inverses.js +50 -14
- package/esm/compiler/manifest.d.ts +59 -0
- package/esm/compiler/manifest.d.ts.map +1 -0
- package/esm/compiler/manifest.js +48 -0
- package/esm/compiler/mod.d.ts +9 -1
- package/esm/compiler/mod.d.ts.map +1 -1
- package/esm/compiler/mod.js +21 -2
- package/esm/compiler/ndjson_writer.d.ts +50 -0
- package/esm/compiler/ndjson_writer.d.ts.map +1 -0
- package/esm/compiler/ndjson_writer.js +73 -0
- package/esm/compiler/schema.d.ts +18 -1
- package/esm/compiler/schema.d.ts.map +1 -1
- package/esm/compiler/schema.js +18 -9
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +54 -0
- package/esm/formatter/mod.d.ts +49 -4
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +362 -33
- package/esm/formatter/synth_ulid.d.ts +21 -0
- package/esm/formatter/synth_ulid.d.ts.map +1 -0
- package/esm/formatter/synth_ulid.js +64 -0
- package/esm/lint/mod.d.ts +10 -0
- package/esm/lint/mod.d.ts.map +1 -0
- package/esm/lint/mod.js +7 -0
- package/esm/lint/rules/lexicon.d.ts +24 -0
- package/esm/lint/rules/lexicon.d.ts.map +1 -0
- package/esm/lint/rules/lexicon.js +236 -0
- package/esm/lint/rules/struct.d.ts +17 -0
- package/esm/lint/rules/struct.d.ts.map +1 -0
- package/esm/lint/rules/struct.js +55 -0
- package/esm/lint/rules/suppression.d.ts +19 -0
- package/esm/lint/rules/suppression.d.ts.map +1 -0
- package/esm/lint/rules/suppression.js +75 -0
- package/esm/lint/runner.d.ts +39 -0
- package/esm/lint/runner.d.ts.map +1 -0
- package/esm/lint/runner.js +112 -0
- package/esm/lint/types.d.ts +19 -0
- package/esm/lint/types.d.ts.map +1 -0
- package/esm/lint/types.js +9 -0
- package/esm/mod.d.ts +19 -6
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +14 -3
- package/esm/model/attributes.d.ts.map +1 -1
- package/esm/model/attributes.js +163 -2
- package/esm/model/discriminating_attr.d.ts +33 -0
- package/esm/model/discriminating_attr.d.ts.map +1 -0
- package/esm/model/discriminating_attr.js +74 -0
- package/esm/model/mod.d.ts +98 -3
- package/esm/model/mod.d.ts.map +1 -1
- package/esm/model/mod.js +57 -2
- package/esm/model/profile.d.ts +33 -27
- package/esm/model/profile.d.ts.map +1 -1
- package/esm/model/source_introspection.d.ts +26 -0
- package/esm/model/source_introspection.d.ts.map +1 -0
- package/esm/model/source_introspection.js +77 -0
- package/esm/model/type_hierarchy.d.ts +51 -0
- package/esm/model/type_hierarchy.d.ts.map +1 -0
- package/esm/model/type_hierarchy.js +126 -0
- package/esm/model/uri_scheme_map.d.ts +21 -0
- package/esm/model/uri_scheme_map.d.ts.map +1 -0
- package/esm/model/uri_scheme_map.js +66 -0
- package/esm/parser/attributes.d.ts.map +1 -1
- package/esm/parser/attributes.js +9 -6
- package/esm/parser/entity_refs.d.ts +53 -0
- package/esm/parser/entity_refs.d.ts.map +1 -0
- package/esm/parser/entity_refs.js +151 -0
- package/esm/parser/glossary.d.ts +43 -0
- package/esm/parser/glossary.d.ts.map +1 -0
- package/esm/parser/glossary.js +217 -0
- package/esm/parser/markdown.d.ts.map +1 -1
- package/esm/parser/markdown.js +223 -7
- package/esm/parser/mod.d.ts +1 -0
- package/esm/parser/mod.d.ts.map +1 -1
- package/esm/parser/mod.js +1 -0
- package/esm/parser/source.d.ts +20 -0
- package/esm/parser/source.d.ts.map +1 -1
- package/esm/parser/source.js +3 -3
- package/esm/profile/chain.js +3 -13
- package/esm/profile/colors.js +1 -1
- package/esm/profile/introspect.d.ts +135 -0
- package/esm/profile/introspect.d.ts.map +1 -0
- package/esm/profile/introspect.js +378 -0
- package/esm/profile/load.d.ts.map +1 -1
- package/esm/profile/load.js +67 -0
- package/esm/profile/manifest.d.ts.map +1 -1
- package/esm/profile/manifest.js +277 -88
- package/esm/profile/merge.js +139 -39
- package/esm/profile/mod.d.ts +2 -4
- package/esm/profile/mod.d.ts.map +1 -1
- package/esm/profile/mod.js +5 -2
- package/esm/reporter/mod.js +4 -4
- package/esm/util/fence.d.ts +30 -0
- package/esm/util/fence.d.ts.map +1 -0
- package/esm/util/fence.js +40 -0
- package/esm/validator/attributes.d.ts +3 -3
- package/esm/validator/attributes.d.ts.map +1 -1
- package/esm/validator/attributes.js +1 -18
- package/esm/validator/body_blocks.d.ts +38 -0
- package/esm/validator/body_blocks.d.ts.map +1 -0
- package/esm/validator/body_blocks.js +218 -0
- package/esm/validator/caption_convention.d.ts +29 -0
- package/esm/validator/caption_convention.d.ts.map +1 -0
- package/esm/validator/caption_convention.js +58 -0
- package/esm/validator/captions.d.ts +22 -0
- package/esm/validator/captions.d.ts.map +1 -0
- package/esm/validator/captions.js +137 -0
- package/esm/validator/component_schemes.d.ts +73 -0
- package/esm/validator/component_schemes.d.ts.map +1 -0
- package/esm/validator/component_schemes.js +375 -0
- package/esm/validator/feature_ac.d.ts +28 -0
- package/esm/validator/feature_ac.d.ts.map +1 -0
- package/esm/validator/feature_ac.js +102 -0
- package/esm/validator/listing.d.ts +42 -0
- package/esm/validator/listing.d.ts.map +1 -0
- package/esm/validator/listing.js +295 -0
- package/esm/validator/mod.d.ts +2 -0
- package/esm/validator/mod.d.ts.map +1 -1
- package/esm/validator/mod.js +253 -12
- package/esm/validator/modal_keywords.d.ts +23 -0
- package/esm/validator/modal_keywords.d.ts.map +1 -0
- package/esm/validator/modal_keywords.js +137 -0
- package/esm/validator/per_type_attrs.d.ts +29 -0
- package/esm/validator/per_type_attrs.d.ts.map +1 -0
- package/esm/validator/per_type_attrs.js +75 -0
- package/esm/validator/pipeline.d.ts +7 -2
- package/esm/validator/pipeline.d.ts.map +1 -1
- package/esm/validator/pipeline.js +40 -7
- package/esm/validator/trace_types.d.ts +26 -0
- package/esm/validator/trace_types.d.ts.map +1 -0
- package/esm/validator/trace_types.js +232 -0
- package/esm/validator/traceability.d.ts +3 -4
- package/esm/validator/traceability.d.ts.map +1 -1
- package/esm/validator/traceability.js +5 -10
- package/esm/validator/type_resolution.d.ts +67 -0
- package/esm/validator/type_resolution.d.ts.map +1 -0
- package/esm/validator/type_resolution.js +140 -0
- package/esm/validator/types.d.ts +45 -0
- package/esm/validator/types.d.ts.map +1 -1
- package/esm/validator/types.js +128 -16
- package/esm/validator/value_types.d.ts +8 -0
- package/esm/validator/value_types.d.ts.map +1 -1
- package/esm/validator/value_types.js +8 -1
- package/package.json +1 -1
- package/script/ast/build.d.ts +70 -0
- package/script/ast/build.d.ts.map +1 -0
- package/script/ast/build.js +610 -0
- package/script/ast/equivalence.d.ts +18 -0
- package/script/ast/equivalence.d.ts.map +1 -0
- package/script/ast/equivalence.js +59 -0
- package/script/ast/nodes.d.ts +221 -0
- package/script/ast/nodes.d.ts.map +1 -0
- package/script/ast/nodes.js +13 -0
- package/script/ast/normalize.d.ts +67 -0
- package/script/ast/normalize.d.ts.map +1 -0
- package/script/ast/normalize.js +258 -0
- package/script/ast/render.d.ts +34 -0
- package/script/ast/render.d.ts.map +1 -0
- package/script/ast/render.js +218 -0
- package/script/compiler/inverses.d.ts +2 -8
- package/script/compiler/inverses.d.ts.map +1 -1
- package/script/compiler/inverses.js +50 -14
- package/script/compiler/manifest.d.ts +59 -0
- package/script/compiler/manifest.d.ts.map +1 -0
- package/script/compiler/manifest.js +51 -0
- package/script/compiler/mod.d.ts +9 -1
- package/script/compiler/mod.d.ts.map +1 -1
- package/script/compiler/mod.js +21 -2
- package/script/compiler/ndjson_writer.d.ts +50 -0
- package/script/compiler/ndjson_writer.d.ts.map +1 -0
- package/script/compiler/ndjson_writer.js +78 -0
- package/script/compiler/schema.d.ts +18 -1
- package/script/compiler/schema.d.ts.map +1 -1
- package/script/compiler/schema.js +18 -8
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +54 -0
- package/script/formatter/mod.d.ts +49 -4
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +365 -33
- package/script/formatter/synth_ulid.d.ts +21 -0
- package/script/formatter/synth_ulid.d.ts.map +1 -0
- package/script/formatter/synth_ulid.js +67 -0
- package/script/lint/mod.d.ts +10 -0
- package/script/lint/mod.d.ts.map +1 -0
- package/script/lint/mod.js +12 -0
- package/script/lint/rules/lexicon.d.ts +24 -0
- package/script/lint/rules/lexicon.d.ts.map +1 -0
- package/script/lint/rules/lexicon.js +240 -0
- package/script/lint/rules/struct.d.ts +17 -0
- package/script/lint/rules/struct.d.ts.map +1 -0
- package/script/lint/rules/struct.js +59 -0
- package/script/lint/rules/suppression.d.ts +19 -0
- package/script/lint/rules/suppression.d.ts.map +1 -0
- package/script/lint/rules/suppression.js +80 -0
- package/script/lint/runner.d.ts +39 -0
- package/script/lint/runner.d.ts.map +1 -0
- package/script/lint/runner.js +116 -0
- package/script/lint/types.d.ts +19 -0
- package/script/lint/types.d.ts.map +1 -0
- package/script/lint/types.js +10 -0
- package/script/mod.d.ts +19 -6
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +56 -32
- package/script/model/attributes.d.ts.map +1 -1
- package/script/model/attributes.js +163 -2
- package/script/model/discriminating_attr.d.ts +33 -0
- package/script/model/discriminating_attr.d.ts.map +1 -0
- package/script/model/discriminating_attr.js +77 -0
- package/script/model/mod.d.ts +98 -3
- package/script/model/mod.d.ts.map +1 -1
- package/script/model/mod.js +64 -3
- package/script/model/profile.d.ts +33 -27
- package/script/model/profile.d.ts.map +1 -1
- package/script/model/source_introspection.d.ts +26 -0
- package/script/model/source_introspection.d.ts.map +1 -0
- package/script/model/source_introspection.js +80 -0
- package/script/model/type_hierarchy.d.ts +51 -0
- package/script/model/type_hierarchy.d.ts.map +1 -0
- package/script/model/type_hierarchy.js +130 -0
- package/script/model/uri_scheme_map.d.ts +21 -0
- package/script/model/uri_scheme_map.d.ts.map +1 -0
- package/script/model/uri_scheme_map.js +69 -0
- package/script/parser/attributes.d.ts.map +1 -1
- package/script/parser/attributes.js +9 -6
- package/script/parser/entity_refs.d.ts +53 -0
- package/script/parser/entity_refs.d.ts.map +1 -0
- package/script/parser/entity_refs.js +155 -0
- package/script/parser/glossary.d.ts +43 -0
- package/script/parser/glossary.d.ts.map +1 -0
- package/script/parser/glossary.js +221 -0
- package/script/parser/markdown.d.ts.map +1 -1
- package/script/parser/markdown.js +222 -6
- package/script/parser/mod.d.ts +1 -0
- package/script/parser/mod.d.ts.map +1 -1
- package/script/parser/mod.js +5 -1
- package/script/parser/source.d.ts +20 -0
- package/script/parser/source.d.ts.map +1 -1
- package/script/parser/source.js +3 -0
- package/script/profile/chain.js +3 -13
- package/script/profile/colors.js +1 -1
- package/script/profile/introspect.d.ts +135 -0
- package/script/profile/introspect.d.ts.map +1 -0
- package/script/profile/introspect.js +381 -0
- package/script/profile/load.d.ts.map +1 -1
- package/script/profile/load.js +67 -0
- package/script/profile/manifest.d.ts.map +1 -1
- package/script/profile/manifest.js +276 -87
- package/script/profile/merge.js +139 -39
- package/script/profile/mod.d.ts +2 -4
- package/script/profile/mod.d.ts.map +1 -1
- package/script/profile/mod.js +7 -6
- package/script/reporter/mod.js +4 -4
- package/script/util/fence.d.ts +30 -0
- package/script/util/fence.d.ts.map +1 -0
- package/script/util/fence.js +44 -0
- package/script/validator/attributes.d.ts +3 -3
- package/script/validator/attributes.d.ts.map +1 -1
- package/script/validator/attributes.js +1 -18
- package/script/validator/body_blocks.d.ts +38 -0
- package/script/validator/body_blocks.d.ts.map +1 -0
- package/script/validator/body_blocks.js +221 -0
- package/script/validator/caption_convention.d.ts +29 -0
- package/script/validator/caption_convention.d.ts.map +1 -0
- package/script/validator/caption_convention.js +61 -0
- package/script/validator/captions.d.ts +22 -0
- package/script/validator/captions.d.ts.map +1 -0
- package/script/validator/captions.js +140 -0
- package/script/validator/component_schemes.d.ts +73 -0
- package/script/validator/component_schemes.d.ts.map +1 -0
- package/script/validator/component_schemes.js +384 -0
- package/script/validator/feature_ac.d.ts +28 -0
- package/script/validator/feature_ac.d.ts.map +1 -0
- package/script/validator/feature_ac.js +105 -0
- package/script/validator/listing.d.ts +42 -0
- package/script/validator/listing.d.ts.map +1 -0
- package/script/validator/listing.js +298 -0
- package/script/validator/mod.d.ts +2 -0
- package/script/validator/mod.d.ts.map +1 -1
- package/script/validator/mod.js +256 -14
- package/script/validator/modal_keywords.d.ts +23 -0
- package/script/validator/modal_keywords.d.ts.map +1 -0
- package/script/validator/modal_keywords.js +140 -0
- package/script/validator/per_type_attrs.d.ts +29 -0
- package/script/validator/per_type_attrs.d.ts.map +1 -0
- package/script/validator/per_type_attrs.js +78 -0
- package/script/validator/pipeline.d.ts +7 -2
- package/script/validator/pipeline.d.ts.map +1 -1
- package/script/validator/pipeline.js +39 -6
- package/script/validator/trace_types.d.ts +26 -0
- package/script/validator/trace_types.d.ts.map +1 -0
- package/script/validator/trace_types.js +235 -0
- package/script/validator/traceability.d.ts +3 -4
- package/script/validator/traceability.d.ts.map +1 -1
- package/script/validator/traceability.js +5 -10
- package/script/validator/type_resolution.d.ts +67 -0
- package/script/validator/type_resolution.d.ts.map +1 -0
- package/script/validator/type_resolution.js +146 -0
- package/script/validator/types.d.ts +45 -0
- package/script/validator/types.d.ts.map +1 -1
- package/script/validator/types.js +131 -16
- package/script/validator/value_types.d.ts +8 -0
- package/script/validator/value_types.d.ts.map +1 -1
- package/script/validator/value_types.js +10 -2
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/ast/build
|
|
4
|
+
*
|
|
5
|
+
* Body-string → BodyBlock[] builder. Parses the entry body string
|
|
6
|
+
* (post-`splitBodyAndAttributes`) with the shared remark processor and
|
|
7
|
+
* maps each mdast block child to the §2.4-2.6 node taxonomy.
|
|
8
|
+
*
|
|
9
|
+
* Inline markers (modal + $Identifier) are extracted for prose-bearing
|
|
10
|
+
* nodes: Paragraph, List items, Table cells, Note bodies, Blockquotes,
|
|
11
|
+
* and DefinitionList term/definitions. They are NOT extracted inside
|
|
12
|
+
* Code, Feature, or Math blocks (spec §2.5).
|
|
13
|
+
*
|
|
14
|
+
* This module is pure library code: no `Deno.*` APIs.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.extractMarkersFromText = extractMarkersFromText;
|
|
18
|
+
exports.verbatimSlice = verbatimSlice;
|
|
19
|
+
exports.buildBodyAst = buildBodyAst;
|
|
20
|
+
const remark_js_1 = require("../parser/remark.js");
|
|
21
|
+
const entity_refs_js_1 = require("../parser/entity_refs.js");
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Inline marker recognition — modal keywords
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
/**
|
|
26
|
+
* RFC 2119 tokens (lowercase canonical; matched case-insensitively in prose).
|
|
27
|
+
* Multi-word forms listed first so the alternation greedily matches them.
|
|
28
|
+
*/
|
|
29
|
+
const RFC2119_RE = /\b(shall not|should not|must not|shall|should|must|may)\b/gi;
|
|
30
|
+
// EARS keywords recognised: When, While, Where, Unless.
|
|
31
|
+
const EARS_RE = /\b(When|While|Where|Unless)\b/g;
|
|
32
|
+
/** `$Identifier` entity reference — must not be preceded by another `$`. */
|
|
33
|
+
const ENTITY_REF_RE = /\$([A-Za-z][A-Za-z0-9_]*)/g;
|
|
34
|
+
/**
|
|
35
|
+
* Extract all inline markers from a prose text string.
|
|
36
|
+
* `lineOffset` is the 0-based line index of the text within the body
|
|
37
|
+
* (used for SourceRange line numbers).
|
|
38
|
+
*
|
|
39
|
+
* For multi-line text the SourceRange carries the first line's 1-based
|
|
40
|
+
* column; this is best-effort for PR 2 (noted as DONE_WITH_CONCERNS:
|
|
41
|
+
* multi-line paragraph ranges are approximated to the starting line).
|
|
42
|
+
*
|
|
43
|
+
* Exported so the AST-native §3.4.1 normalisation pass
|
|
44
|
+
* (`core/ast/normalize.ts`) re-derives `InlineContent.markers` from the
|
|
45
|
+
* normalised text with the SAME extraction the builder uses — no regex
|
|
46
|
+
* duplication.
|
|
47
|
+
*/
|
|
48
|
+
function extractMarkersFromText(text, startRange) {
|
|
49
|
+
const markers = [];
|
|
50
|
+
const lines = text.split("\n");
|
|
51
|
+
for (let li = 0; li < lines.length; li++) {
|
|
52
|
+
const line = lines[li];
|
|
53
|
+
const lineNo = startRange.start.line + li;
|
|
54
|
+
// ---- RFC 2119 ---------------------------------------------------
|
|
55
|
+
RFC2119_RE.lastIndex = 0;
|
|
56
|
+
let m;
|
|
57
|
+
while ((m = RFC2119_RE.exec(line)) !== null) {
|
|
58
|
+
const raw = m[1];
|
|
59
|
+
const canonical = raw.toLowerCase();
|
|
60
|
+
const col = m.index + 1;
|
|
61
|
+
markers.push({
|
|
62
|
+
kind: "modal",
|
|
63
|
+
cls: "rfc2119",
|
|
64
|
+
canonical,
|
|
65
|
+
raw, // preserve source form for uppercase-keyword detection (MSL-M060)
|
|
66
|
+
range: {
|
|
67
|
+
start: { line: lineNo, column: col },
|
|
68
|
+
end: { line: lineNo, column: col + raw.length },
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// ---- EARS -------------------------------------------------------
|
|
73
|
+
EARS_RE.lastIndex = 0;
|
|
74
|
+
while ((m = EARS_RE.exec(line)) !== null) {
|
|
75
|
+
const raw = m[1];
|
|
76
|
+
const col = m.index + 1;
|
|
77
|
+
markers.push({
|
|
78
|
+
kind: "modal",
|
|
79
|
+
cls: "ears",
|
|
80
|
+
canonical: raw, // EARS: source form is canonical
|
|
81
|
+
raw, // same as canonical for EARS
|
|
82
|
+
range: {
|
|
83
|
+
start: { line: lineNo, column: col },
|
|
84
|
+
end: { line: lineNo, column: col + raw.length },
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// ---- $Identifier ------------------------------------------------
|
|
89
|
+
ENTITY_REF_RE.lastIndex = 0;
|
|
90
|
+
while ((m = ENTITY_REF_RE.exec(line)) !== null) {
|
|
91
|
+
// Discard if preceded by another `$` (math fence `$$…$$`)
|
|
92
|
+
if (m.index > 0 && line[m.index - 1] === "$")
|
|
93
|
+
continue;
|
|
94
|
+
// Discard if preceded by `\` (escaped)
|
|
95
|
+
if (m.index > 0 && line[m.index - 1] === "\\")
|
|
96
|
+
continue;
|
|
97
|
+
const ident = m[0]; // includes leading `$`
|
|
98
|
+
const bare = m[1];
|
|
99
|
+
const col = m.index + 1;
|
|
100
|
+
markers.push({
|
|
101
|
+
kind: "entity",
|
|
102
|
+
ident,
|
|
103
|
+
convention: (0, entity_refs_js_1.classifyConvention)(bare),
|
|
104
|
+
range: {
|
|
105
|
+
start: { line: lineNo, column: col },
|
|
106
|
+
end: { line: lineNo, column: col + ident.length },
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return markers;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Build an InlineContent. `storedText` is the verbatim source prose that
|
|
115
|
+
* `render` emits (§5.1 faithful); `recognitionText` is the flattened
|
|
116
|
+
* projection that modal / $Identifier recognition runs on (so `\bshall\b`
|
|
117
|
+
* still matches inside `_shall_`). For nodes whose text carries no inline
|
|
118
|
+
* markup the two are identical and behaviour is unchanged.
|
|
119
|
+
*/
|
|
120
|
+
function inlineContent(storedText, recognitionText, range) {
|
|
121
|
+
const markers = extractMarkersFromText(recognitionText, range);
|
|
122
|
+
return { text: storedText, markers };
|
|
123
|
+
}
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// mdast position → SourceRange
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
function positionToRange(pos) {
|
|
128
|
+
if (!pos) {
|
|
129
|
+
return { start: { line: 1, column: 1 }, end: { line: 1, column: 1 } };
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
start: { line: pos.start.line, column: pos.start.column },
|
|
133
|
+
end: { line: pos.end.line, column: pos.end.column },
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
// verbatimSlice — faithful capture helper (§5.1)
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
/**
|
|
140
|
+
* Return the exact source substring for an mdast node `position`, with
|
|
141
|
+
* list-continuation indentation normalised to column 0 so the slice is a
|
|
142
|
+
* self-contained, column-0-anchored string. This is the load-bearing
|
|
143
|
+
* mechanism for §5.1 faithful capture (ADR-014; spec §5.1): remark
|
|
144
|
+
* populates byte `offset` when a string is passed to `.parse()`; a
|
|
145
|
+
* line/column reconstruction is the defensive fallback. Extracted from
|
|
146
|
+
* the original inline `TableNode` logic — behaviour is identical.
|
|
147
|
+
*/
|
|
148
|
+
function verbatimSlice(body, pos) {
|
|
149
|
+
if (!pos)
|
|
150
|
+
return "";
|
|
151
|
+
let raw;
|
|
152
|
+
if (pos.start.offset !== undefined && pos.end.offset !== undefined) {
|
|
153
|
+
raw = body.slice(pos.start.offset, pos.end.offset);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const bodyLines = body.split("\n");
|
|
157
|
+
const startLine = pos.start.line - 1;
|
|
158
|
+
const endLine = pos.end.line - 1;
|
|
159
|
+
const startCol = pos.start.column - 1;
|
|
160
|
+
const endCol = pos.end.column - 1;
|
|
161
|
+
if (startLine === endLine) {
|
|
162
|
+
raw = bodyLines[startLine]?.slice(startCol, endCol) ?? "";
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const firstPart = bodyLines[startLine]?.slice(startCol) ?? "";
|
|
166
|
+
const middleParts = bodyLines.slice(startLine + 1, endLine);
|
|
167
|
+
const lastPart = bodyLines[endLine]?.slice(0, endCol) ?? "";
|
|
168
|
+
raw = [firstPart, ...middleParts, lastPart].join("\n");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const listIndent = pos.start.column - 1; // 0 for top-level nodes
|
|
172
|
+
if (listIndent > 0) {
|
|
173
|
+
const prefix = " ".repeat(listIndent);
|
|
174
|
+
const rawLines = raw.split("\n");
|
|
175
|
+
raw = [
|
|
176
|
+
rawLines[0],
|
|
177
|
+
...rawLines.slice(1).map((line) => line.startsWith(prefix) ? line.slice(listIndent) : line),
|
|
178
|
+
].join("\n");
|
|
179
|
+
}
|
|
180
|
+
return raw;
|
|
181
|
+
}
|
|
182
|
+
// ---------------------------------------------------------------------------
|
|
183
|
+
// Caption detection
|
|
184
|
+
// ---------------------------------------------------------------------------
|
|
185
|
+
/** Caption keywords from spec §2.6. */
|
|
186
|
+
const CAPTION_KEYWORDS = [
|
|
187
|
+
"Figure",
|
|
188
|
+
"Table",
|
|
189
|
+
"Listing",
|
|
190
|
+
"Feature",
|
|
191
|
+
"Equation",
|
|
192
|
+
"List",
|
|
193
|
+
];
|
|
194
|
+
const CAPTION_RE = /^(Figure|Table|Listing|Feature|Equation|List):\s+(\S.*)/;
|
|
195
|
+
function tryCaptionParagraph(text) {
|
|
196
|
+
const m = CAPTION_RE.exec(text.trim());
|
|
197
|
+
if (!m)
|
|
198
|
+
return undefined;
|
|
199
|
+
return { keyword: m[1], text: m[2].trim() };
|
|
200
|
+
}
|
|
201
|
+
// ---------------------------------------------------------------------------
|
|
202
|
+
// Math detection — `$$` delimited paragraphs
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
const MATH_BLOCK_RE = /^\$\$([\s\S]*?)\$\$$/;
|
|
205
|
+
function tryMathParagraph(text) {
|
|
206
|
+
// Plain text that is exactly `$$ ... $$` → math block
|
|
207
|
+
const m = MATH_BLOCK_RE.exec(text.trim());
|
|
208
|
+
if (m)
|
|
209
|
+
return m[1];
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
// Admonition detection
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
const ADMONITION_FIRST_LINE_RE = /^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]/;
|
|
216
|
+
// ---------------------------------------------------------------------------
|
|
217
|
+
// Definition-list detection (GLFM `Term\n: def` pattern)
|
|
218
|
+
//
|
|
219
|
+
// remark-gfm does NOT parse GLFM definition lists; they come through as
|
|
220
|
+
// Paragraph nodes. We detect the pattern in the body string before parsing
|
|
221
|
+
// and handle them via our pre-pass.
|
|
222
|
+
//
|
|
223
|
+
// DONE_WITH_CONCERNS: single-item best-effort as documented in the PR brief.
|
|
224
|
+
// ---------------------------------------------------------------------------
|
|
225
|
+
const DEFLIST_RE = /^([^\n:][^\n]*)\n:\s+(.+)$/m;
|
|
226
|
+
function tryDefinitionList(text) {
|
|
227
|
+
const m = DEFLIST_RE.exec(text.trim());
|
|
228
|
+
if (!m)
|
|
229
|
+
return undefined;
|
|
230
|
+
return { term: m[1].trim(), definition: m[2].trim() };
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Deterministically split a verbatim definition-list slice into its
|
|
234
|
+
* term and definition substrings.
|
|
235
|
+
*
|
|
236
|
+
* Detection still runs on the flattened text via {@linkcode
|
|
237
|
+
* tryDefinitionList} (markup-stripped recognition, mirroring caption /
|
|
238
|
+
* math detection). This function only governs what is *stored*: it
|
|
239
|
+
* returns the byte-exact verbatim term and definition so inline markup
|
|
240
|
+
* on either side survives.
|
|
241
|
+
*
|
|
242
|
+
* The split mirrors `renderDefinitionList` in `render.ts` exactly. That
|
|
243
|
+
* renderer emits `${term.text}\n: ${definition.text}` — one newline,
|
|
244
|
+
* then `: ` (colon + single space). The inverse is therefore: split on
|
|
245
|
+
* the first `\n:`, take everything before as the term, then consume the
|
|
246
|
+
* leading whitespace after the colon (the `\s+` that `DEFLIST_RE` and
|
|
247
|
+
* the canonical `: ` collapse). The remainder is the definition.
|
|
248
|
+
*
|
|
249
|
+
* Why this replaces `DEFLIST_RE.exec(verbatim.trim())`: that regex's
|
|
250
|
+
* `(.+)$` under the `/m` flag stops at the first newline, so a verbatim
|
|
251
|
+
* slice spanning multiple source lines silently lost everything after
|
|
252
|
+
* the first definition line and fell back to the flattened (markup-
|
|
253
|
+
* stripped) form. A deterministic first-`\n:` split never misses.
|
|
254
|
+
*
|
|
255
|
+
* Returns `undefined` only when the verbatim slice contains no `\n:`
|
|
256
|
+
* separator (cannot happen for a canonical single-item deflist that
|
|
257
|
+
* flattened-detection accepted, but kept total for safety).
|
|
258
|
+
*/
|
|
259
|
+
function splitVerbatimDeflist(verbatim) {
|
|
260
|
+
const sepIndex = verbatim.indexOf("\n:");
|
|
261
|
+
if (sepIndex < 0)
|
|
262
|
+
return undefined;
|
|
263
|
+
const term = verbatim.slice(0, sepIndex);
|
|
264
|
+
// Skip the `\n:` then the leading whitespace the renderer re-emits
|
|
265
|
+
// as the single space in `: ` (same whitespace `DEFLIST_RE`'s `\s+`
|
|
266
|
+
// would have consumed).
|
|
267
|
+
let defStart = sepIndex + 2;
|
|
268
|
+
while (defStart < verbatim.length && /\s/.test(verbatim[defStart])) {
|
|
269
|
+
defStart++;
|
|
270
|
+
}
|
|
271
|
+
const definition = verbatim.slice(defStart);
|
|
272
|
+
return { term, definition };
|
|
273
|
+
}
|
|
274
|
+
// ---------------------------------------------------------------------------
|
|
275
|
+
// mdast text extraction helper
|
|
276
|
+
// ---------------------------------------------------------------------------
|
|
277
|
+
// deno-lint-ignore no-explicit-any
|
|
278
|
+
function extractMdastText(node) {
|
|
279
|
+
if (!node)
|
|
280
|
+
return "";
|
|
281
|
+
// Inline code nodes carry their value without delimiters in mdast;
|
|
282
|
+
// re-add the backtick delimiters so the round-trip is byte-identical.
|
|
283
|
+
if (node.type === "inlineCode")
|
|
284
|
+
return `\`${node.value}\``;
|
|
285
|
+
if (typeof node.value === "string")
|
|
286
|
+
return node.value;
|
|
287
|
+
if (Array.isArray(node.children)) {
|
|
288
|
+
return node.children.map(extractMdastText).join("");
|
|
289
|
+
}
|
|
290
|
+
return "";
|
|
291
|
+
}
|
|
292
|
+
// ---------------------------------------------------------------------------
|
|
293
|
+
// Caption position computation
|
|
294
|
+
// ---------------------------------------------------------------------------
|
|
295
|
+
/**
|
|
296
|
+
* Compute caption positions: "above" or "below" relative to adjacent blocks.
|
|
297
|
+
* This is a post-processing pass that examines caption nodes relative to their
|
|
298
|
+
* neighbours.
|
|
299
|
+
*
|
|
300
|
+
* DONE_WITH_CONCERNS: position is determined by source order heuristic —
|
|
301
|
+
* if the block *after* the caption is a non-caption, non-paragraph block,
|
|
302
|
+
* caption is "above"; if the block *before* is such a block, it's "below".
|
|
303
|
+
* For PR 2, defaults to "below" when adjacent block type is unclear.
|
|
304
|
+
*/
|
|
305
|
+
function assignCaptionPositions(blocks) {
|
|
306
|
+
const result = [];
|
|
307
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
308
|
+
if (blocks[i].kind !== "caption") {
|
|
309
|
+
result.push(blocks[i]);
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const cap = blocks[i];
|
|
313
|
+
// Look ahead for a non-caption, non-paragraph block
|
|
314
|
+
const nextBlock = blocks[i + 1];
|
|
315
|
+
const prevBlock = result[result.length - 1];
|
|
316
|
+
const isCaptionable = (b) => {
|
|
317
|
+
if (!b)
|
|
318
|
+
return false;
|
|
319
|
+
return (b.kind === "figure" ||
|
|
320
|
+
b.kind === "table" ||
|
|
321
|
+
b.kind === "code" ||
|
|
322
|
+
b.kind === "feature" ||
|
|
323
|
+
b.kind === "math" ||
|
|
324
|
+
b.kind === "list");
|
|
325
|
+
};
|
|
326
|
+
let position;
|
|
327
|
+
if (isCaptionable(nextBlock)) {
|
|
328
|
+
position = "above";
|
|
329
|
+
}
|
|
330
|
+
else if (isCaptionable(prevBlock)) {
|
|
331
|
+
position = "below";
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
// Default: below (conservative)
|
|
335
|
+
position = "below";
|
|
336
|
+
}
|
|
337
|
+
result.push({ ...cap, position });
|
|
338
|
+
}
|
|
339
|
+
return result;
|
|
340
|
+
}
|
|
341
|
+
// ---------------------------------------------------------------------------
|
|
342
|
+
// Blockquote de-quote (§5.1 faithful)
|
|
343
|
+
// ---------------------------------------------------------------------------
|
|
344
|
+
/**
|
|
345
|
+
* De-quote a verbatim blockquote slice: strip the per-line `> ` (or bare
|
|
346
|
+
* `>` for blank quoted lines) marker, preserving inline markup and the
|
|
347
|
+
* interior-blank-line convention. CommonMark canonical quoting is `> `
|
|
348
|
+
* on content lines and `>` alone on blank lines; a defensive `>`-without
|
|
349
|
+
* -space strip handles non-canonical input.
|
|
350
|
+
*/
|
|
351
|
+
function deQuote(rawBlockquote) {
|
|
352
|
+
return rawBlockquote
|
|
353
|
+
.split("\n")
|
|
354
|
+
.map((line) => {
|
|
355
|
+
if (line.startsWith("> "))
|
|
356
|
+
return line.slice(2);
|
|
357
|
+
if (line === ">")
|
|
358
|
+
return "";
|
|
359
|
+
if (line.startsWith(">"))
|
|
360
|
+
return line.slice(1);
|
|
361
|
+
return line;
|
|
362
|
+
})
|
|
363
|
+
.join("\n");
|
|
364
|
+
}
|
|
365
|
+
// ---------------------------------------------------------------------------
|
|
366
|
+
// Main builder — mdast node → BodyBlock
|
|
367
|
+
// ---------------------------------------------------------------------------
|
|
368
|
+
// deno-lint-ignore no-explicit-any
|
|
369
|
+
function mapMdastNode(node, body) {
|
|
370
|
+
const range = positionToRange(node.position);
|
|
371
|
+
switch (node.type) {
|
|
372
|
+
case "paragraph": {
|
|
373
|
+
const text = extractMdastText(node); // flattened — detection + recognition
|
|
374
|
+
const verbatim = verbatimSlice(body, node.position);
|
|
375
|
+
// Check for lone image → FigureNode
|
|
376
|
+
if (node.children.length === 1 &&
|
|
377
|
+
node.children[0].type === "image") {
|
|
378
|
+
const img = node.children[0];
|
|
379
|
+
return {
|
|
380
|
+
kind: "figure",
|
|
381
|
+
alt: img.alt ?? "",
|
|
382
|
+
path: img.url ?? "",
|
|
383
|
+
range,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
// Check for math `$$ ... $$` paragraph
|
|
387
|
+
const mathTex = tryMathParagraph(text);
|
|
388
|
+
if (mathTex !== undefined) {
|
|
389
|
+
return { kind: "math", tex: mathTex, range };
|
|
390
|
+
}
|
|
391
|
+
// Check for definition-list pattern `Term\n: def`
|
|
392
|
+
const defList = tryDefinitionList(text);
|
|
393
|
+
if (defList) {
|
|
394
|
+
// Detection ran on the flattened text (markup-stripped, like
|
|
395
|
+
// caption / math detection). The *stored* term and definition
|
|
396
|
+
// are the byte-exact verbatim substrings so inline markup on
|
|
397
|
+
// either side survives. The split is deterministic (first
|
|
398
|
+
// `\n:`) and mirrors `renderDefinitionList` exactly — it can
|
|
399
|
+
// never miss a multi-line verbatim slice the way the old
|
|
400
|
+
// `DEFLIST_RE.exec(verbatim.trim())` could, so there is no
|
|
401
|
+
// flattened fallback. `splitVerbatimDeflist` only returns
|
|
402
|
+
// `undefined` when there is no `\n:` at all (impossible here,
|
|
403
|
+
// since flattened detection already matched `\n:`); the
|
|
404
|
+
// `?? defList` keeps the expression total.
|
|
405
|
+
const split = splitVerbatimDeflist(verbatim) ?? defList;
|
|
406
|
+
const vTerm = split.term;
|
|
407
|
+
const vDef = split.definition;
|
|
408
|
+
const termRange = {
|
|
409
|
+
start: range.start,
|
|
410
|
+
end: range.start,
|
|
411
|
+
};
|
|
412
|
+
const defRange = {
|
|
413
|
+
start: range.start,
|
|
414
|
+
end: range.end,
|
|
415
|
+
};
|
|
416
|
+
return {
|
|
417
|
+
kind: "definition-list",
|
|
418
|
+
items: [
|
|
419
|
+
{
|
|
420
|
+
term: inlineContent(vTerm, defList.term, termRange),
|
|
421
|
+
definition: inlineContent(vDef, defList.definition, defRange),
|
|
422
|
+
},
|
|
423
|
+
],
|
|
424
|
+
range,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
// Check for caption `Figure: text` etc.
|
|
428
|
+
const caption = tryCaptionParagraph(text);
|
|
429
|
+
if (caption) {
|
|
430
|
+
// Position is resolved in a post-pass; default "below" for now
|
|
431
|
+
return {
|
|
432
|
+
kind: "caption",
|
|
433
|
+
keyword: caption.keyword,
|
|
434
|
+
text: caption.text,
|
|
435
|
+
position: "below",
|
|
436
|
+
range,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
// Plain paragraph: store verbatim source, recognise on flattened text.
|
|
440
|
+
return {
|
|
441
|
+
kind: "paragraph",
|
|
442
|
+
content: inlineContent(verbatim, text, range),
|
|
443
|
+
range,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
case "list": {
|
|
447
|
+
// Detect GFM task-list items (remark-gfm sets `checked` to true/false).
|
|
448
|
+
// deno-lint-ignore no-explicit-any
|
|
449
|
+
const hasTaskItems = node.children.some((item) => item.checked != null);
|
|
450
|
+
const items = node.children.map(
|
|
451
|
+
// deno-lint-ignore no-explicit-any
|
|
452
|
+
(item) => {
|
|
453
|
+
const itemRange = positionToRange(item.position);
|
|
454
|
+
const subBlocks = (item.children ?? []).map(
|
|
455
|
+
// deno-lint-ignore no-explicit-any
|
|
456
|
+
(child) => mapMdastNode(child, body));
|
|
457
|
+
return {
|
|
458
|
+
blocks: subBlocks,
|
|
459
|
+
...(item.checked != null ? { checked: item.checked } : {}),
|
|
460
|
+
...(item.spread != null ? { spread: item.spread } : {}),
|
|
461
|
+
range: itemRange,
|
|
462
|
+
};
|
|
463
|
+
});
|
|
464
|
+
return {
|
|
465
|
+
kind: "list",
|
|
466
|
+
ordered: node.ordered ?? false,
|
|
467
|
+
spread: node.spread ?? false,
|
|
468
|
+
items,
|
|
469
|
+
...(hasTaskItems ? { hasTaskItems: true } : {}),
|
|
470
|
+
range,
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
case "table": {
|
|
474
|
+
// deno-lint-ignore no-explicit-any
|
|
475
|
+
const rows = node.children.map((row) =>
|
|
476
|
+
// deno-lint-ignore no-explicit-any
|
|
477
|
+
(row.children ?? []).map((cell) => {
|
|
478
|
+
const cellText = extractMdastText(cell);
|
|
479
|
+
const cellRange = positionToRange(cell.position);
|
|
480
|
+
// stored == recognition (table cells render via TableNode.raw; Task 5 confirms)
|
|
481
|
+
return inlineContent(cellText, cellText, cellRange);
|
|
482
|
+
}));
|
|
483
|
+
const [header = [], ...dataRows] = rows;
|
|
484
|
+
const raw = verbatimSlice(body, node.position);
|
|
485
|
+
return {
|
|
486
|
+
kind: "table",
|
|
487
|
+
header,
|
|
488
|
+
rows: dataRows,
|
|
489
|
+
raw,
|
|
490
|
+
range,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
case "code": {
|
|
494
|
+
const lang = node.lang ?? undefined; // empty string → undefined
|
|
495
|
+
if (lang === "gherkin") {
|
|
496
|
+
return {
|
|
497
|
+
kind: "feature",
|
|
498
|
+
source: node.value ?? "",
|
|
499
|
+
range,
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
return {
|
|
503
|
+
kind: "code",
|
|
504
|
+
lang: lang || undefined,
|
|
505
|
+
text: node.value ?? "",
|
|
506
|
+
range,
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
case "blockquote": {
|
|
510
|
+
const verbatim = deQuote(verbatimSlice(body, node.position));
|
|
511
|
+
const firstChild = node.children?.[0];
|
|
512
|
+
if (firstChild?.type === "paragraph") {
|
|
513
|
+
const paraText = extractMdastText(firstChild);
|
|
514
|
+
const admonMatch = ADMONITION_FIRST_LINE_RE.exec(paraText.trim());
|
|
515
|
+
if (admonMatch) {
|
|
516
|
+
const kind = admonMatch[1];
|
|
517
|
+
// Flattened recognition text (unchanged from prior behaviour):
|
|
518
|
+
// marker-stripped first paragraph + remaining paragraphs.
|
|
519
|
+
const rest = paraText.replace(ADMONITION_FIRST_LINE_RE, "").trim();
|
|
520
|
+
const otherText = node.children
|
|
521
|
+
.slice(1)
|
|
522
|
+
// deno-lint-ignore no-explicit-any
|
|
523
|
+
.map((c) => extractMdastText(c))
|
|
524
|
+
.join("\n\n");
|
|
525
|
+
const flattened = [rest, otherText].filter(Boolean).join("\n\n");
|
|
526
|
+
// Verbatim stored text: de-quoted slice with the `[!KIND]`
|
|
527
|
+
// token removed from the first line. Anything the author put
|
|
528
|
+
// after the marker on the same line is kept verbatim.
|
|
529
|
+
const vLines = verbatim.split("\n");
|
|
530
|
+
// `kind` is enum-constrained (NOTE|TIP|IMPORTANT|WARNING|CAUTION,
|
|
531
|
+
// captured by ADMONITION_FIRST_LINE_RE) — no regex metacharacters,
|
|
532
|
+
// so this dynamic RegExp is injection-safe (no escaping needed).
|
|
533
|
+
const markerRe = new RegExp(`^\\[!${kind}\\]`);
|
|
534
|
+
const afterMarker = (vLines[0] ?? "").replace(markerRe, "");
|
|
535
|
+
const bodyLines = vLines.slice(1);
|
|
536
|
+
// A non-empty `afterMarker` means the body began on the marker
|
|
537
|
+
// line (`> [!KIND] text`). Record it so the renderer reproduces
|
|
538
|
+
// the same-line form rather than rewriting to the own-line form.
|
|
539
|
+
const markerInline = afterMarker.trim().length > 0;
|
|
540
|
+
const storedText = markerInline
|
|
541
|
+
? [afterMarker.trimStart(), ...bodyLines].join("\n")
|
|
542
|
+
: bodyLines.join("\n");
|
|
543
|
+
return {
|
|
544
|
+
kind: "note",
|
|
545
|
+
admonition: kind,
|
|
546
|
+
content: inlineContent(storedText, flattened, range),
|
|
547
|
+
...(markerInline ? { markerInline: true } : {}),
|
|
548
|
+
range,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
const bqFlattened = node.children
|
|
553
|
+
// deno-lint-ignore no-explicit-any
|
|
554
|
+
.map((c) => extractMdastText(c))
|
|
555
|
+
.join("\n\n");
|
|
556
|
+
return {
|
|
557
|
+
kind: "blockquote",
|
|
558
|
+
content: inlineContent(verbatim, bqFlattened, range),
|
|
559
|
+
range,
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
default: {
|
|
563
|
+
let subkind;
|
|
564
|
+
if (node.type === "heading" ||
|
|
565
|
+
node.type === "setextHeading") {
|
|
566
|
+
subkind = "heading";
|
|
567
|
+
}
|
|
568
|
+
else if (node.type === "thematicBreak") {
|
|
569
|
+
subkind = "thematic-break";
|
|
570
|
+
}
|
|
571
|
+
else if (node.type === "html") {
|
|
572
|
+
subkind = "html";
|
|
573
|
+
}
|
|
574
|
+
return {
|
|
575
|
+
kind: "unknown",
|
|
576
|
+
raw: verbatimSlice(body, node.position),
|
|
577
|
+
...(subkind !== undefined ? { subkind } : {}),
|
|
578
|
+
range,
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
// ---------------------------------------------------------------------------
|
|
584
|
+
// Public API
|
|
585
|
+
// ---------------------------------------------------------------------------
|
|
586
|
+
/**
|
|
587
|
+
* Build the canonical body AST from an entry body string.
|
|
588
|
+
*
|
|
589
|
+
* Re-parses `body` via the shared remark processor (CommonMark+GFM) and
|
|
590
|
+
* maps each block-level mdast node to a `BodyBlock`. SourceRange positions
|
|
591
|
+
* are body-relative (1-based line/column) matching the mdast output directly.
|
|
592
|
+
*
|
|
593
|
+
* DONE_WITH_CONCERNS notes:
|
|
594
|
+
* - DefinitionList: single-item best-effort. `Term\n: def` patterns in
|
|
595
|
+
* multi-item lists are parsed as one DefinitionListNode per paragraph
|
|
596
|
+
* block; the validator would need to coalesce them (deferred).
|
|
597
|
+
* - Caption position: assigned by adjacent-block heuristic (post-pass).
|
|
598
|
+
* `block` (resolved owner) is `undefined` for PR 2 per spec.
|
|
599
|
+
* - Multi-line paragraph marker ranges: SourceRange is approximated to
|
|
600
|
+
* the paragraph start line; intra-paragraph column tracking is correct
|
|
601
|
+
* only for single-line paragraphs.
|
|
602
|
+
*/
|
|
603
|
+
function buildBodyAst(body) {
|
|
604
|
+
if (!body.trim())
|
|
605
|
+
return [];
|
|
606
|
+
const tree = remark_js_1.processor.parse(body);
|
|
607
|
+
const blocks = tree.children.map((node) => mapMdastNode(node, body));
|
|
608
|
+
// Post-pass: assign caption positions
|
|
609
|
+
return assignCaptionPositions(blocks);
|
|
610
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/ast/equivalence
|
|
3
|
+
*
|
|
4
|
+
* The formal §5 AST-equivalence relation (ADR-015). Two `BodyBlock[]` are
|
|
5
|
+
* equivalent iff structurally deep-equal after eliding every `range`
|
|
6
|
+
* (`SourceRange`) key at any depth. Adopted UNCHANGED from SP1's
|
|
7
|
+
* provisional relation — SP3 ratifies, it does not redefine. All §5.2
|
|
8
|
+
* normalization is explicit in `normalizeBodyAst`, never in this
|
|
9
|
+
* comparator (Formalization A).
|
|
10
|
+
*
|
|
11
|
+
* Load-bearing: consumed by the formatter guard (`emitBodyViaAst`) and
|
|
12
|
+
* the SP1 fidelity harness. Pure library code: no `Deno.*`.
|
|
13
|
+
*/
|
|
14
|
+
import type { BodyBlock } from "./nodes.js";
|
|
15
|
+
/** Formal §5 AST-equivalence: strict structural deep-equality of
|
|
16
|
+
* `BodyBlock[]` ignoring every `range`. */
|
|
17
|
+
export declare function astEquivalent(a: readonly BodyBlock[], b: readonly BodyBlock[]): boolean;
|
|
18
|
+
//# sourceMappingURL=equivalence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"equivalence.d.ts","sourceRoot":"","sources":["../../src/ast/equivalence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;2CAC2C;AAC3C,wBAAgB,aAAa,CAC3B,CAAC,EAAE,SAAS,SAAS,EAAE,EACvB,CAAC,EAAE,SAAS,SAAS,EAAE,GACtB,OAAO,CAET"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @module core/ast/equivalence
|
|
4
|
+
*
|
|
5
|
+
* The formal §5 AST-equivalence relation (ADR-015). Two `BodyBlock[]` are
|
|
6
|
+
* equivalent iff structurally deep-equal after eliding every `range`
|
|
7
|
+
* (`SourceRange`) key at any depth. Adopted UNCHANGED from SP1's
|
|
8
|
+
* provisional relation — SP3 ratifies, it does not redefine. All §5.2
|
|
9
|
+
* normalization is explicit in `normalizeBodyAst`, never in this
|
|
10
|
+
* comparator (Formalization A).
|
|
11
|
+
*
|
|
12
|
+
* Load-bearing: consumed by the formatter guard (`emitBodyViaAst`) and
|
|
13
|
+
* the SP1 fidelity harness. Pure library code: no `Deno.*`.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.astEquivalent = astEquivalent;
|
|
17
|
+
/** Formal §5 AST-equivalence: strict structural deep-equality of
|
|
18
|
+
* `BodyBlock[]` ignoring every `range`. */
|
|
19
|
+
function astEquivalent(a, b) {
|
|
20
|
+
return deepEqualIgnoringRanges(a, b);
|
|
21
|
+
}
|
|
22
|
+
/** Deep structural equality with every `range` key elided at any depth. */
|
|
23
|
+
function deepEqualIgnoringRanges(a, b) {
|
|
24
|
+
if (a === b)
|
|
25
|
+
return true;
|
|
26
|
+
if (typeof a !== typeof b)
|
|
27
|
+
return false;
|
|
28
|
+
if (a === null || b === null)
|
|
29
|
+
return a === b;
|
|
30
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
31
|
+
if (!Array.isArray(a) || !Array.isArray(b))
|
|
32
|
+
return false;
|
|
33
|
+
if (a.length !== b.length)
|
|
34
|
+
return false;
|
|
35
|
+
for (let i = 0; i < a.length; i++) {
|
|
36
|
+
if (!deepEqualIgnoringRanges(a[i], b[i]))
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
42
|
+
const ao = a;
|
|
43
|
+
const bo = b;
|
|
44
|
+
const ak = Object.keys(ao).filter((k) => k !== "range").sort();
|
|
45
|
+
const bk = Object.keys(bo).filter((k) => k !== "range").sort();
|
|
46
|
+
if (ak.length !== bk.length)
|
|
47
|
+
return false;
|
|
48
|
+
for (let i = 0; i < ak.length; i++) {
|
|
49
|
+
if (ak[i] !== bk[i])
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
for (const k of ak) {
|
|
53
|
+
if (!deepEqualIgnoringRanges(ao[k], bo[k]))
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|