@driftsys/markspec 0.11.0 → 0.12.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.
Files changed (142) hide show
  1. package/README.md +9 -0
  2. package/esm/ast/normalize.d.ts +4 -5
  3. package/esm/ast/normalize.d.ts.map +1 -1
  4. package/esm/ast/normalize.js +6 -37
  5. package/esm/collect/mod.d.ts +29 -9
  6. package/esm/collect/mod.d.ts.map +1 -1
  7. package/esm/collect/mod.js +36 -10
  8. package/esm/compiler/mod.d.ts.map +1 -1
  9. package/esm/compiler/mod.js +2 -6
  10. package/esm/config/markspec.d.ts +4 -2
  11. package/esm/config/markspec.d.ts.map +1 -1
  12. package/esm/discovery/mod.d.ts +24 -8
  13. package/esm/discovery/mod.d.ts.map +1 -1
  14. package/esm/discovery/mod.js +57 -21
  15. package/esm/discovery/projects.d.ts +109 -0
  16. package/esm/discovery/projects.d.ts.map +1 -0
  17. package/esm/discovery/projects.js +232 -0
  18. package/esm/formatter/entry_body.d.ts +86 -0
  19. package/esm/formatter/entry_body.d.ts.map +1 -0
  20. package/esm/formatter/entry_body.js +287 -0
  21. package/esm/formatter/mod.d.ts +13 -9
  22. package/esm/formatter/mod.d.ts.map +1 -1
  23. package/esm/formatter/mod.js +126 -50
  24. package/esm/gates/mod.d.ts.map +1 -1
  25. package/esm/gates/mod.js +5 -4
  26. package/esm/lint/runner.d.ts.map +1 -1
  27. package/esm/lint/runner.js +4 -4
  28. package/esm/lock/check.d.ts.map +1 -1
  29. package/esm/lock/check.js +2 -1
  30. package/esm/lock/edge_drift.d.ts +2 -0
  31. package/esm/lock/edge_drift.d.ts.map +1 -1
  32. package/esm/lock/edge_drift.js +4 -0
  33. package/esm/lock/mod.d.ts +1 -1
  34. package/esm/lock/mod.d.ts.map +1 -1
  35. package/esm/lock/mod.js +1 -1
  36. package/esm/mod.d.ts +10 -6
  37. package/esm/mod.d.ts.map +1 -1
  38. package/esm/mod.js +8 -6
  39. package/esm/model/mod.d.ts +21 -0
  40. package/esm/model/mod.d.ts.map +1 -1
  41. package/esm/model/mod.js +10 -0
  42. package/esm/parser/code_regions.d.ts +29 -0
  43. package/esm/parser/code_regions.d.ts.map +1 -0
  44. package/esm/parser/code_regions.js +38 -0
  45. package/esm/parser/markdown.d.ts.map +1 -1
  46. package/esm/parser/markdown.js +103 -40
  47. package/esm/parser/mod.d.ts.map +1 -1
  48. package/esm/parser/mod.js +7 -1
  49. package/esm/parser/translate.d.ts.map +1 -1
  50. package/esm/parser/translate.js +5 -0
  51. package/esm/refs/mod.d.ts.map +1 -1
  52. package/esm/refs/mod.js +8 -19
  53. package/esm/reporter/mod.d.ts.map +1 -1
  54. package/esm/reporter/mod.js +2 -2
  55. package/esm/util/fence.d.ts +20 -29
  56. package/esm/util/fence.d.ts.map +1 -1
  57. package/esm/util/fence.js +42 -50
  58. package/esm/util/modals.d.ts +6 -0
  59. package/esm/util/modals.d.ts.map +1 -1
  60. package/esm/util/modals.js +37 -0
  61. package/esm/validator/body_blocks.d.ts +2 -1
  62. package/esm/validator/body_blocks.d.ts.map +1 -1
  63. package/esm/validator/body_blocks.js +80 -2
  64. package/esm/validator/corpus.d.ts +6 -0
  65. package/esm/validator/corpus.d.ts.map +1 -1
  66. package/esm/validator/corpus.js +16 -4
  67. package/esm/validator/mod.d.ts +1 -1
  68. package/esm/validator/mod.d.ts.map +1 -1
  69. package/esm/validator/mod.js +1 -1
  70. package/esm/validator/pipeline.d.ts.map +1 -1
  71. package/esm/validator/pipeline.js +11 -8
  72. package/package.json +1 -1
  73. package/script/ast/normalize.d.ts +4 -5
  74. package/script/ast/normalize.d.ts.map +1 -1
  75. package/script/ast/normalize.js +5 -36
  76. package/script/collect/mod.d.ts +29 -9
  77. package/script/collect/mod.d.ts.map +1 -1
  78. package/script/collect/mod.js +38 -10
  79. package/script/compiler/mod.d.ts.map +1 -1
  80. package/script/compiler/mod.js +1 -5
  81. package/script/config/markspec.d.ts +4 -2
  82. package/script/config/markspec.d.ts.map +1 -1
  83. package/script/discovery/mod.d.ts +24 -8
  84. package/script/discovery/mod.d.ts.map +1 -1
  85. package/script/discovery/mod.js +56 -20
  86. package/script/discovery/projects.d.ts +109 -0
  87. package/script/discovery/projects.d.ts.map +1 -0
  88. package/script/discovery/projects.js +240 -0
  89. package/script/formatter/entry_body.d.ts +86 -0
  90. package/script/formatter/entry_body.d.ts.map +1 -0
  91. package/script/formatter/entry_body.js +292 -0
  92. package/script/formatter/mod.d.ts +13 -9
  93. package/script/formatter/mod.d.ts.map +1 -1
  94. package/script/formatter/mod.js +124 -48
  95. package/script/gates/mod.d.ts.map +1 -1
  96. package/script/gates/mod.js +15 -14
  97. package/script/lint/runner.d.ts.map +1 -1
  98. package/script/lint/runner.js +3 -3
  99. package/script/lock/check.d.ts.map +1 -1
  100. package/script/lock/check.js +2 -1
  101. package/script/lock/edge_drift.d.ts +2 -0
  102. package/script/lock/edge_drift.d.ts.map +1 -1
  103. package/script/lock/edge_drift.js +5 -0
  104. package/script/lock/mod.d.ts +1 -1
  105. package/script/lock/mod.d.ts.map +1 -1
  106. package/script/lock/mod.js +2 -1
  107. package/script/mod.d.ts +10 -6
  108. package/script/mod.d.ts.map +1 -1
  109. package/script/mod.js +20 -5
  110. package/script/model/mod.d.ts +21 -0
  111. package/script/model/mod.d.ts.map +1 -1
  112. package/script/model/mod.js +11 -0
  113. package/script/parser/code_regions.d.ts +29 -0
  114. package/script/parser/code_regions.d.ts.map +1 -0
  115. package/script/parser/code_regions.js +41 -0
  116. package/script/parser/markdown.d.ts.map +1 -1
  117. package/script/parser/markdown.js +102 -39
  118. package/script/parser/mod.d.ts.map +1 -1
  119. package/script/parser/mod.js +7 -1
  120. package/script/parser/translate.d.ts.map +1 -1
  121. package/script/parser/translate.js +5 -0
  122. package/script/refs/mod.d.ts.map +1 -1
  123. package/script/refs/mod.js +7 -18
  124. package/script/reporter/mod.d.ts.map +1 -1
  125. package/script/reporter/mod.js +1 -1
  126. package/script/util/fence.d.ts +20 -29
  127. package/script/util/fence.d.ts.map +1 -1
  128. package/script/util/fence.js +47 -54
  129. package/script/util/modals.d.ts +6 -0
  130. package/script/util/modals.d.ts.map +1 -1
  131. package/script/util/modals.js +38 -0
  132. package/script/validator/body_blocks.d.ts +2 -1
  133. package/script/validator/body_blocks.d.ts.map +1 -1
  134. package/script/validator/body_blocks.js +80 -2
  135. package/script/validator/corpus.d.ts +6 -0
  136. package/script/validator/corpus.d.ts.map +1 -1
  137. package/script/validator/corpus.js +16 -3
  138. package/script/validator/mod.d.ts +1 -1
  139. package/script/validator/mod.d.ts.map +1 -1
  140. package/script/validator/mod.js +2 -1
  141. package/script/validator/pipeline.d.ts.map +1 -1
  142. package/script/validator/pipeline.js +11 -8
@@ -4,7 +4,7 @@
4
4
  * Output reporters. Transforms compiled traceability graph into
5
5
  * traceability matrices and coverage reports in md, json, or csv format.
6
6
  */
7
- import { formatEntryOrigin, isUpstreamEntry } from "../model/mod.js";
7
+ import { formatEntryOrigin, isCorpusEntry, isUpstreamEntry, } from "../model/mod.js";
8
8
  /**
9
9
  * Generate a report from compiled traceability graph.
10
10
  *
@@ -50,7 +50,7 @@ function filterEntries(result, scope, label) {
50
50
  * Markdown, and JSON rows all agree on the same value.
51
51
  */
52
52
  function originCell(entry) {
53
- return entry.origin ? formatEntryOrigin(entry.origin) : "project";
53
+ return isCorpusEntry(entry) ? formatEntryOrigin(entry.origin) : "project";
54
54
  }
55
55
  function buildTraceRows(result, entries) {
56
56
  return entries.map((entry) => {
@@ -1,38 +1,29 @@
1
1
  /**
2
- * @module core/util/fence
3
- *
4
- * Prose-line walker that skips lines inside fenced code blocks.
5
- * Several validator and formatter passes (body-block exclusions,
6
- * caption adjacency, `$Identifier` extraction, modal-keyword
7
- * normalisation) all needed to walk an entry body line-by-line while
8
- * treating fenced code as verbatim. This helper centralises that
9
- * pattern so the fence-toggle semantics stay consistent.
10
- *
11
- * Fence detection follows CommonMark §4.5 — a line whose first
12
- * non-whitespace content is three or more backticks or tildes opens
13
- * (or closes) a fenced block. The language tag that may follow the
14
- * opening fence does not affect detection: we toggle on every fence
15
- * marker regardless. (Mismatched marker types — ``` opener / ~~~
16
- * closer — are accepted by the walker because real Markdown parsers
17
- * already reject those upstream.)
2
+ * Legacy fence-prefix candidate used by the LSP source-file scanner.
3
+ * Markdown fence membership uses the AST-backed helpers below.
18
4
  */
19
- /** Three or more backticks or tildes at the start of a line. */
20
5
  export declare const FENCE_RE: RegExp;
21
- /** Callback for {@linkcode walkProseLines}. Receives one line + its 0-based index. */
6
+ /**
7
+ * Compute zero-based fenced-code lines, including opening and closing lines.
8
+ * Cache the sets for the 64 most recently queried exact document texts. Each
9
+ * call returns a new copy, so a caller that changes it cannot alter the cache.
10
+ * Callers making multiple membership queries should compute this set once and
11
+ * pass it to {@linkcode isLineFenced} or {@linkcode walkProseLines}.
12
+ */
13
+ export declare function fencedCodeLines(body: string): ReadonlySet<number>;
14
+ /**
15
+ * Callback for {@linkcode walkProseLines}. Receives a line and its 0-based index.
16
+ * The LF delimiter is excluded; a CR from a CRLF delimiter is preserved.
17
+ */
22
18
  export type ProseLineCallback = (line: string, index: number) => void;
23
19
  /**
24
- * Walk `body` line by line, invoking `cb` for every line that's NOT
25
- * inside a fenced code block. The first fence marker opens the block;
26
- * the next closes it. The fence-marker lines themselves are also
27
- * skipped (they're structural, not prose).
20
+ * Walk lines outside fenced code, using the cached CommonMark line set unless
21
+ * a precomputed set for this exact text is supplied. Indented code is yielded.
28
22
  */
29
- export declare function walkProseLines(body: string, cb: ProseLineCallback): void;
23
+ export declare function walkProseLines(body: string, cb: ProseLineCallback, fencedLines?: ReadonlySet<number>): void;
30
24
  /**
31
- * Return whether `lineIndex` (0-based) is a line {@linkcode walkProseLines}
32
- * would skip — either a fence-marker line itself, or content inside a
33
- * fenced block. Single-line-membership counterpart to `walkProseLines`'s
34
- * full-body callback walk, for callers that only need a yes/no answer for
35
- * one position (e.g. an LSP request gating a cursor position, #680).
25
+ * Return whether a zero-based document line belongs to the fenced-line set.
26
+ * Supply the set for this exact text when querying multiple positions.
36
27
  */
37
- export declare function isLineFenced(body: string, lineIndex: number): boolean;
28
+ export declare function isLineFenced(body: string, lineIndex: number, fencedLines?: ReadonlySet<number>): boolean;
38
29
  //# sourceMappingURL=fence.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../../src/util/fence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,gEAAgE;AAChE,eAAO,MAAM,QAAQ,QAAkB,CAAC;AAExC,sFAAsF;AACtF,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAEtE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,iBAAiB,GAAG,IAAI,CAYxE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAYrE"}
1
+ {"version":3,"file":"fence.d.ts","sourceRoot":"","sources":["../../src/util/fence.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAkB,CAAC;AAKxC;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,CAajE;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAEtE;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,iBAAiB,EACrB,WAAW,GAAE,WAAW,CAAC,MAAM,CAAyB,GACvD,IAAI,CAIN;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,WAAW,GAAE,WAAW,CAAC,MAAM,CAAyB,GACvD,OAAO,CAET"}
package/esm/util/fence.js CHANGED
@@ -1,62 +1,54 @@
1
1
  /**
2
2
  * @module core/util/fence
3
3
  *
4
- * Prose-line walker that skips lines inside fenced code blocks.
5
- * Several validator and formatter passes (body-block exclusions,
6
- * caption adjacency, `$Identifier` extraction, modal-keyword
7
- * normalisation) all needed to walk an entry body line-by-line while
8
- * treating fenced code as verbatim. This helper centralises that
9
- * pattern so the fence-toggle semantics stay consistent.
10
- *
11
- * Fence detection follows CommonMark §4.5 — a line whose first
12
- * non-whitespace content is three or more backticks or tildes opens
13
- * (or closes) a fenced block. The language tag that may follow the
14
- * opening fence does not affect detection: we toggle on every fence
15
- * marker regardless. (Mismatched marker types — ``` opener / ~~~
16
- * closer — are accepted by the walker because real Markdown parsers
17
- * already reject those upstream.)
4
+ * Prose-line helpers using fenced-code boundaries from the CommonMark AST.
5
+ * Containers, matching delimiters and implicit container endings are handled
6
+ * by remark. Indented code is not fenced code: MarkSpec trailers must remain
7
+ * available to reference and validation passes.
8
+ */
9
+ import { parseCodeRegions } from "../parser/code_regions.js";
10
+ /**
11
+ * Legacy fence-prefix candidate used by the LSP source-file scanner.
12
+ * Markdown fence membership uses the AST-backed helpers below.
18
13
  */
19
- /** Three or more backticks or tildes at the start of a line. */
20
14
  export const FENCE_RE = /^\s*(```|~~~)/;
15
+ const FENCE_CACHE_CAPACITY = 64;
16
+ const fencedLineCache = new Map();
21
17
  /**
22
- * Walk `body` line by line, invoking `cb` for every line that's NOT
23
- * inside a fenced code block. The first fence marker opens the block;
24
- * the next closes it. The fence-marker lines themselves are also
25
- * skipped (they're structural, not prose).
18
+ * Compute zero-based fenced-code lines, including opening and closing lines.
19
+ * Cache the sets for the 64 most recently queried exact document texts. Each
20
+ * call returns a new copy, so a caller that changes it cannot alter the cache.
21
+ * Callers making multiple membership queries should compute this set once and
22
+ * pass it to {@linkcode isLineFenced} or {@linkcode walkProseLines}.
26
23
  */
27
- export function walkProseLines(body, cb) {
28
- const lines = body.split("\n");
29
- let inFence = false;
30
- for (let i = 0; i < lines.length; i++) {
31
- const line = lines[i];
32
- if (FENCE_RE.test(line)) {
33
- inFence = !inFence;
34
- continue;
35
- }
36
- if (inFence)
37
- continue;
38
- cb(line, i);
24
+ export function fencedCodeLines(body) {
25
+ const cached = fencedLineCache.get(body);
26
+ if (cached !== undefined) {
27
+ fencedLineCache.delete(body);
28
+ fencedLineCache.set(body, cached);
29
+ return new Set(cached);
30
+ }
31
+ const lines = parseCodeRegions(body).fencedLines;
32
+ fencedLineCache.set(body, lines);
33
+ if (fencedLineCache.size > FENCE_CACHE_CAPACITY) {
34
+ fencedLineCache.delete(fencedLineCache.keys().next().value);
39
35
  }
36
+ return new Set(lines);
40
37
  }
41
38
  /**
42
- * Return whether `lineIndex` (0-based) is a line {@linkcode walkProseLines}
43
- * would skip — either a fence-marker line itself, or content inside a
44
- * fenced block. Single-line-membership counterpart to `walkProseLines`'s
45
- * full-body callback walk, for callers that only need a yes/no answer for
46
- * one position (e.g. an LSP request gating a cursor position, #680).
39
+ * Walk lines outside fenced code, using the cached CommonMark line set unless
40
+ * a precomputed set for this exact text is supplied. Indented code is yielded.
47
41
  */
48
- export function isLineFenced(body, lineIndex) {
49
- const lines = body.split("\n");
50
- let inFence = false;
51
- for (let i = 0; i <= lineIndex && i < lines.length; i++) {
52
- if (FENCE_RE.test(lines[i])) {
53
- inFence = !inFence;
54
- if (i === lineIndex)
55
- return true;
56
- continue;
57
- }
58
- if (i === lineIndex)
59
- return inFence;
60
- }
61
- return false;
42
+ export function walkProseLines(body, cb, fencedLines = fencedCodeLines(body)) {
43
+ body.split("\n").forEach((line, index) => {
44
+ if (!fencedLines.has(index))
45
+ cb(line, index);
46
+ });
47
+ }
48
+ /**
49
+ * Return whether a zero-based document line belongs to the fenced-line set.
50
+ * Supply the set for this exact text when querying multiple positions.
51
+ */
52
+ export function isLineFenced(body, lineIndex, fencedLines = fencedCodeLines(body)) {
53
+ return fencedLines.has(lineIndex);
62
54
  }
@@ -26,4 +26,10 @@ export declare const EARS_KEYWORD_RE: RegExp;
26
26
  * punctuation character (`.`, `!`, `?`).
27
27
  */
28
28
  export declare function isSentenceInitial(line: string, offset: number): boolean;
29
+ /**
30
+ * Normalize modal keywords in prose while preserving CommonMark fenced and
31
+ * inline code. Four-space and tab-indented lines remain verbatim as before.
32
+ * The document is parsed once; both code exclusions use that same AST.
33
+ */
34
+ export declare function normalizeProseModals(text: string): string;
29
35
  //# sourceMappingURL=modals.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"modals.d.ts","sourceRoot":"","sources":["../../src/util/modals.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAA0C,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAmC,CAAC;AAEhE;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAOvE"}
1
+ {"version":3,"file":"modals.d.ts","sourceRoot":"","sources":["../../src/util/modals.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAA0C,CAAC;AAExE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,QAAmC,CAAC;AAEhE;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAOvE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA4CzD"}
@@ -6,6 +6,8 @@
6
6
  * `ast/` is a dependency of `formatter/`, so `formatter → ast` is OK but
7
7
  * `ast → formatter` is not.
8
8
  */
9
+ import { parseCodeRegions } from "../parser/code_regions.js";
10
+ import { walkProseLines } from "./fence.js";
9
11
  /**
10
12
  * RFC 2119 modal keywords in uppercase form, with optional ` NOT` suffix.
11
13
  * Captured for canonical-form normalisation per spec §3.4.1: uppercase
@@ -36,3 +38,38 @@ export function isSentenceInitial(line, offset) {
36
38
  const prev = line[i];
37
39
  return prev === "." || prev === "!" || prev === "?";
38
40
  }
41
+ /**
42
+ * Normalize modal keywords in prose while preserving CommonMark fenced and
43
+ * inline code. Four-space and tab-indented lines remain verbatim as before.
44
+ * The document is parsed once; both code exclusions use that same AST.
45
+ */
46
+ export function normalizeProseModals(text) {
47
+ const { fencedLines, inlineCode } = parseCodeRegions(text);
48
+ const lines = text.split("\n");
49
+ let lineOffset = 0;
50
+ let rangeIndex = 0;
51
+ // Record offsets before walking: the callback skips fenced lines.
52
+ const offsets = lines.map((line) => {
53
+ const offset = lineOffset;
54
+ lineOffset += line.length + 1;
55
+ return offset;
56
+ });
57
+ walkProseLines(text, (line, i) => {
58
+ if (/^( {4}|\t)/.test(line))
59
+ return;
60
+ const start = offsets[i];
61
+ while (rangeIndex < inlineCode.length && inlineCode[rangeIndex].end <= start)
62
+ rangeIndex++;
63
+ const protectedRanges = [];
64
+ for (let j = rangeIndex; j < inlineCode.length && inlineCode[j].start < start + line.length; j++) {
65
+ protectedRanges.push(inlineCode[j]);
66
+ }
67
+ const isCode = (offset, length) => protectedRanges.some((range) => range.start < start + offset + length && range.end > start + offset);
68
+ let normalized = line.replace(RFC2119_MODAL_RE, (match, _keyword, _not, offset) => isCode(offset, match.length) ? match : match.toLowerCase());
69
+ normalized = normalized.replace(EARS_KEYWORD_RE, (match, _keyword, offset) => isCode(offset, match.length) || isSentenceInitial(normalized, offset)
70
+ ? match
71
+ : match.toLowerCase());
72
+ lines[i] = normalized;
73
+ }, fencedLines);
74
+ return lines.join("\n");
75
+ }
@@ -20,7 +20,8 @@
20
20
  * - Inline HTML — remains inside `ParagraphNode.content.text` (remark
21
21
  * does not extract inline HTML nodes into block-level nodes); each
22
22
  * paragraph's text is scanned line-by-line using the same regex
23
- * approach as the old walkProseLines path, but bounded to prose-only
23
+ * approach as the old walkProseLines path (with inline code spans
24
+ * masked out first — they are literal text, never HTML), bounded to prose-only
24
25
  * nodes (code/feature/math blocks are automatically excluded because
25
26
  * the builder does not emit prose-bearing nodes for verbatim content).
26
27
  *
@@ -1 +1 @@
1
- {"version":3,"file":"body_blocks.d.ts","sourceRoot":"","sources":["../../src/validator/body_blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AA2LzD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,UAAU,EAAE,CAsBtE"}
1
+ {"version":3,"file":"body_blocks.d.ts","sourceRoot":"","sources":["../../src/validator/body_blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AA0QzD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,UAAU,EAAE,CAsBtE"}
@@ -20,7 +20,8 @@
20
20
  * - Inline HTML — remains inside `ParagraphNode.content.text` (remark
21
21
  * does not extract inline HTML nodes into block-level nodes); each
22
22
  * paragraph's text is scanned line-by-line using the same regex
23
- * approach as the old walkProseLines path, but bounded to prose-only
23
+ * approach as the old walkProseLines path (with inline code spans
24
+ * masked out first — they are literal text, never HTML), bounded to prose-only
24
25
  * nodes (code/feature/math blocks are automatically excluded because
25
26
  * the builder does not emit prose-bearing nodes for verbatim content).
26
27
  *
@@ -38,6 +39,15 @@ import { isMarkspecDirectiveComment } from "../parser/directives.js";
38
39
  const HTML_TAG_RE = /<\/?[A-Za-z][A-Za-z0-9]*(\s[^>]*)?\/?>/;
39
40
  /** Any HTML comment, `<!--…-->`. */
40
41
  const HTML_COMMENT_RE = /<!--[\s\S]*?-->/;
42
+ /**
43
+ * A CommonMark raw HTML open or closing tag (§6.6) anchored at the scan
44
+ * position. Stricter than {@linkcode HTML_TAG_RE} on purpose: it decides
45
+ * code-span precedence, so `` a<b and `c>` `` must not read as a tag
46
+ * (a backtick cannot start an attribute name) and hide the code span.
47
+ */
48
+ const HTML_TAG_AT_RE = /^(?:<[A-Za-z][A-Za-z0-9-]*(?:\s+[A-Za-z_:][\w.:-]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*\/?>|<\/[A-Za-z][A-Za-z0-9-]*\s*>)/;
49
+ /** {@linkcode HTML_COMMENT_RE} anchored at the scan position. */
50
+ const HTML_COMMENT_AT_RE = new RegExp(`^${HTML_COMMENT_RE.source}`);
41
51
  /**
42
52
  * Return `true` when `line` contains raw HTML the body model forbids:
43
53
  * any tag, or any comment that isn't a standalone markspec directive.
@@ -70,6 +80,74 @@ const RAW_HTML_DIAG = {
70
80
  severity: "error",
71
81
  summary: "raw HTML inside entry body — only `<!-- markspec:* -->` directive comments are permitted (spec §2.4.1)",
72
82
  };
83
+ /**
84
+ * Blank out every CommonMark code span in `text` (delimiters included),
85
+ * keeping newlines so line offsets are preserved. A code span is literal
86
+ * text, never HTML (CommonMark §6.1), so `` `tool --root <ws>` `` must
87
+ * not reach the tag regex.
88
+ *
89
+ * Follows the CommonMark rules the regex scan would otherwise ignore:
90
+ * a backslash-escaped backtick does not open a span; an opening run of N
91
+ * backticks closes only at the next run of exactly N; an unmatched run
92
+ * is literal. Raw HTML and code spans bind left-to-right, so a tag that
93
+ * starts before a backtick run is skipped intact and still flagged.
94
+ */
95
+ function maskCodeSpans(text) {
96
+ const blank = (s) => s.replace(/[^\n]/g, " ");
97
+ let out = "";
98
+ let i = 0;
99
+ while (i < text.length) {
100
+ const ch = text[i];
101
+ if (ch === "\\" && i + 1 < text.length) {
102
+ out += text.slice(i, i + 2);
103
+ i += 2;
104
+ continue;
105
+ }
106
+ if (ch === "<") {
107
+ const rest = text.slice(i);
108
+ const tag = HTML_TAG_AT_RE.exec(rest) ?? HTML_COMMENT_AT_RE.exec(rest);
109
+ if (tag) {
110
+ out += tag[0];
111
+ i += tag[0].length;
112
+ continue;
113
+ }
114
+ }
115
+ if (ch !== "`") {
116
+ out += ch;
117
+ i++;
118
+ continue;
119
+ }
120
+ let runEnd = i;
121
+ while (runEnd < text.length && text[runEnd] === "`")
122
+ runEnd++;
123
+ const runLength = runEnd - i;
124
+ let close = -1;
125
+ let j = runEnd;
126
+ while (j < text.length) {
127
+ if (text[j] !== "`") {
128
+ j++;
129
+ continue;
130
+ }
131
+ let k = j;
132
+ while (k < text.length && text[k] === "`")
133
+ k++;
134
+ if (k - j === runLength) {
135
+ close = k;
136
+ break;
137
+ }
138
+ j = k;
139
+ }
140
+ if (close < 0) {
141
+ // Unmatched opener — the backticks are literal text.
142
+ out += text.slice(i, runEnd);
143
+ i = runEnd;
144
+ continue;
145
+ }
146
+ out += blank(text.slice(i, close));
147
+ i = close;
148
+ }
149
+ return out;
150
+ }
73
151
  /**
74
152
  * Scan `text` line-by-line for forbidden inline HTML, starting at
75
153
  * `startLine` (1-based body-relative). Returns one `{ diag, bodyLine }`
@@ -83,7 +161,7 @@ const RAW_HTML_DIAG = {
83
161
  */
84
162
  function htmlViolations(text, startLine) {
85
163
  const out = [];
86
- const lines = text.split("\n");
164
+ const lines = maskCodeSpans(text).split("\n");
87
165
  for (let li = 0; li < lines.length; li++) {
88
166
  const line = lines[li];
89
167
  if (line.trim() === "")
@@ -14,6 +14,12 @@
14
14
  * collided tokens (MSL-R014 replaces them).
15
15
  */
16
16
  import type { Diagnostic, Entry } from "../model/mod.js";
17
+ /**
18
+ * Attribute corpus findings and replace generic duplicate diagnostics with
19
+ * corpus collisions. Append collisions after attribution so MSL-R014 remains
20
+ * an error even when its location belongs to a read-only corpus.
21
+ */
22
+ export declare function applyCorpusPostPass(diagnostics: readonly Diagnostic[], allEntries: readonly Entry[]): Diagnostic[];
17
23
  /** Result of {@linkcode detectCorpusCollisions}. */
18
24
  export interface CorpusCollisionResult {
19
25
  readonly diagnostics: readonly Diagnostic[];
@@ -1 +1 @@
1
- {"version":3,"file":"corpus.d.ts","sourceRoot":"","sources":["../../src/validator/corpus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAe,MAAM,iBAAiB,CAAC;AA4BtE,oDAAoD;AACpD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,qEAAqE;IACrE,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC9C;AAED,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,SAAS,KAAK,EAAE,GAC3B,qBAAqB,CAsFvB;AAED,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,UAAU,EAAE,SAAS,KAAK,EAAE,EAC5B,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,GAClC,UAAU,EAAE,CAyCd"}
1
+ {"version":3,"file":"corpus.d.ts","sourceRoot":"","sources":["../../src/validator/corpus.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAe,MAAM,iBAAiB,CAAC;AAOtE;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,UAAU,EAAE,SAAS,KAAK,EAAE,GAC3B,UAAU,EAAE,CAUd;AA2BD,oDAAoD;AACpD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,qEAAqE;IACrE,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC9C;AAED,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,SAAS,KAAK,EAAE,GAC3B,qBAAqB,CAsFvB;AAED,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,UAAU,EAAE,SAAS,KAAK,EAAE,EAC5B,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,GAClC,UAAU,EAAE,CAyCd"}
@@ -13,7 +13,19 @@
13
13
  * delivering profile; generic duplicate codes are suppressed for
14
14
  * collided tokens (MSL-R014 replaces them).
15
15
  */
16
- import { formatEntryOrigin, sameOriginSource } from "../model/mod.js";
16
+ import { formatEntryOrigin, isCorpusEntry, sameOriginSource, } from "../model/mod.js";
17
+ /**
18
+ * Attribute corpus findings and replace generic duplicate diagnostics with
19
+ * corpus collisions. Append collisions after attribution so MSL-R014 remains
20
+ * an error even when its location belongs to a read-only corpus.
21
+ */
22
+ export function applyCorpusPostPass(diagnostics, allEntries) {
23
+ const collisions = detectCorpusCollisions(allEntries);
24
+ return [
25
+ ...attributeCorpusDiagnostics(diagnostics, allEntries, collisions.collidedTokens),
26
+ ...collisions.diagnostics,
27
+ ];
28
+ }
17
29
  /**
18
30
  * Remedy clause for an inter-tier MSL-R014 collision — both owners
19
31
  * carry an origin (upstream and/or delivered profile), so the consumer
@@ -40,7 +52,7 @@ export function detectCorpusCollisions(allEntries) {
40
52
  const corpusByDisplayId = new Map();
41
53
  const corpusById = new Map();
42
54
  for (const e of allEntries) {
43
- if (!e.origin)
55
+ if (!isCorpusEntry(e))
44
56
  continue;
45
57
  if (!corpusByDisplayId.has(e.displayId)) {
46
58
  corpusByDisplayId.set(e.displayId, e);
@@ -54,7 +66,7 @@ export function detectCorpusCollisions(allEntries) {
54
66
  const diagnostics = [];
55
67
  const collided = new Set();
56
68
  for (const e of allEntries) {
57
- if (!e.origin) {
69
+ if (!isCorpusEntry(e)) {
58
70
  const displayOwner = corpusByDisplayId.get(e.displayId);
59
71
  if (displayOwner) {
60
72
  collided.add(e.displayId);
@@ -124,7 +136,7 @@ export function detectCorpusCollisions(allEntries) {
124
136
  export function attributeCorpusDiagnostics(diagnostics, allEntries, collidedTokens) {
125
137
  const corpusFiles = new Map();
126
138
  for (const e of allEntries) {
127
- if (e.origin) {
139
+ if (isCorpusEntry(e)) {
128
140
  corpusFiles.set(e.location.file, e.origin);
129
141
  }
130
142
  }
@@ -43,6 +43,6 @@ export { validateValue } from "./value_types.js";
43
43
  export type { ValueValidator } from "./value_types.js";
44
44
  export { normalizeListValues } from "./normalize.js";
45
45
  export { effectiveTraceRules, matchesAnyTarget, validateTraceabilityForEntry, } from "./traceability.js";
46
- export { attributeCorpusDiagnostics, detectCorpusCollisions, } from "./corpus.js";
46
+ export { applyCorpusPostPass, attributeCorpusDiagnostics, detectCorpusCollisions, } from "./corpus.js";
47
47
  export type { CorpusCollisionResult } from "./corpus.js";
48
48
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/validator/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAsCpE,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,cAAc,CAuBlE;AAibD,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,KAAK,EAAE,GACxB,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAM5B;AAGD,wBAAgB,QAAQ,CACtB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,GAAG,EAAE,MAAM,GACV,SAAS,GAAG,SAAS,CAEvB;AAED,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACtE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACjE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7E,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/validator/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAsCpE,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,cAAc,CAuBlE;AAibD,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,SAAS,KAAK,EAAE,GACxB,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAM5B;AAGD,wBAAgB,QAAQ,CACtB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,GAAG,EAAE,MAAM,GACV,SAAS,GAAG,SAAS,CAEvB;AAED,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACtE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACjE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7E,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,4BAA4B,GAC7B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,mBAAmB,EACnB,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC"}
@@ -487,4 +487,4 @@ export { effectiveScope, validateAttributesForEntry } from "./attributes.js";
487
487
  export { validateValue } from "./value_types.js";
488
488
  export { normalizeListValues } from "./normalize.js";
489
489
  export { effectiveTraceRules, matchesAnyTarget, validateTraceabilityForEntry, } from "./traceability.js";
490
- export { attributeCorpusDiagnostics, detectCorpusCollisions, } from "./corpus.js";
490
+ export { applyCorpusPostPass, attributeCorpusDiagnostics, detectCorpusCollisions, } from "./corpus.js";
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/validator/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EACV,gBAAgB,EAChB,KAAK,EACN,MAAM,iBAAiB,CAAC;AAqCzB,qDAAqD;AACrD,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,2CAA2C;AAC3C,MAAM,WAAW,eAAe;IAC9B;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAE/B;;;;;;;OAOG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GAAG,IAAI,EAChC,kBAAkB,GAAE,kBAAuB,EAC3C,IAAI,GAAE,eAAoB,GACzB,cAAc,CA2JhB;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GAAG,IAAI,GAC/B,SAAS,UAAU,EAAE,CASvB"}
1
+ {"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/validator/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EACV,gBAAgB,EAChB,KAAK,EACN,MAAM,iBAAiB,CAAC;AAqCzB,qDAAqD;AACrD,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,CAAC;IACnC,QAAQ,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,CAAC;IAC5C,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAED,2CAA2C;AAC3C,MAAM,WAAW,eAAe;IAC9B;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAE/B;;;;;;;OAOG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GAAG,IAAI,EAChC,kBAAkB,GAAE,kBAAuB,EAC3C,IAAI,GAAE,eAAoB,GACzB,cAAc,CA8JhB;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,SAAS,UAAU,EAAE,EAClC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GAAG,IAAI,GAC/B,SAAS,UAAU,EAAE,CASvB"}
@@ -76,7 +76,6 @@ export function runPipeline(entries, profile, captionConventions = {}, opts = {}
76
76
  diagnostics.push(...validateCaptionConvention(entry, captionConventions));
77
77
  diagnostics.push(...validateBodyBlocks(entry));
78
78
  diagnostics.push(...validateFeatureAc(entry));
79
- diagnostics.push(...validatePerTypeAttributes(entry, profile ?? undefined));
80
79
  diagnostics.push(...validateModalKeywords(entry));
81
80
  }
82
81
  // Stage 1.6 — cross-file trace target-type compatibility (MSL-R083).
@@ -102,15 +101,19 @@ export function runPipeline(entries, profile, captionConventions = {}, opts = {}
102
101
  finalEntries = stage2.entries;
103
102
  diagnostics.push(...stage2.diagnostics);
104
103
  }
105
- // Stage 2.4 — late-stage inference warnings (MSL-T021 for steps 5/6).
106
- // Runs after Stage 2 so that profile-classified `entry.type` suppresses
107
- // the warning correctly. In core-only mode `finalEntries === entries`
108
- // and `entry.type` is always undefined, so this stage produces the same
109
- // diagnostics regardless of mode. Partitions inline: `finalEmittable`
110
- // below is derived from the post-normalization generation, which does
111
- // not exist yet at this point.
104
+ // Stage 2.4 — late-stage inference warnings (MSL-T021 for steps 5/6)
105
+ // and per-type attribute compatibility (MSL-T022 / MSL-T024). Both run
106
+ // after Stage 2 so that a profile-classified `entry.type` (display-ID
107
+ // pattern match, no explicit `Type:`) resolves to its `extends:` core
108
+ // type — run before classification, MSL-T024 fired on every
109
+ // pattern-classified entry carrying `Satisfies:`/`Derived-from:`. In
110
+ // core-only mode `finalEntries === entries` and `entry.type` is always
111
+ // undefined, so this stage produces the same diagnostics regardless of
112
+ // mode. Partitions inline: `finalEmittable` below is derived from the
113
+ // post-normalization generation, which does not exist yet at this point.
112
114
  for (const entry of emittableEntries(finalEntries)) {
113
115
  diagnostics.push(...inferTypeFromLateStageChain(entry));
116
+ diagnostics.push(...validatePerTypeAttributes(entry, profile ?? undefined));
114
117
  }
115
118
  // Stage 2.5 — normalize profile-declared list-value attributes. Splits
116
119
  // comma-separated values for `id-list`/`tag-list` attributes the core parser
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driftsys/markspec",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Markdown flavor and toolchain for traceable industrial documentation",
5
5
  "keywords": [
6
6
  "markdown",
@@ -14,11 +14,10 @@
14
14
  * - EARS (`When`, `While`, `Where`, `Unless`) — lowercased
15
15
  * mid-sentence, capitalisation preserved when sentence-initial.
16
16
  *
17
- * The shared `RFC2119_MODAL_RE`, `EARS_KEYWORD_RE`, and `isSentenceInitial`
18
- * helpers are imported from `core/util/modals.ts` (D11 consolidation).
19
- * They cannot be imported from `formatter/mod.ts` because `formatter/`
20
- * depends on `ast/`, making an `ast → formatter` import a dependency cycle.
21
- * `core/util/` is the base level that both modules can import from.
17
+ * The shared `normalizeProseModals` helper is imported from
18
+ * `core/util/modals.ts`. Importing it from `formatter/mod.ts` would create
19
+ * a cycle because `formatter/` already depends on `ast/`.
20
+ * The helper uses only the standalone remark code-region parser.
22
21
  *
23
22
  * Invariants (HARD — never weaken):
24
23
  * - Pure: no `Deno.*`, no I/O.
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/ast/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAQH,OAAO,KAAK,EAEV,SAAS,EASV,MAAM,YAAY,CAAC;AAiJpB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,SAAS,EAAE,GAC3B,SAAS,EAAE,CAEb"}
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/ast/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,KAAK,EAEV,SAAS,EASV,MAAM,YAAY,CAAC;AA+GpB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,SAAS,EAAE,GAC3B,SAAS,EAAE,CAEb"}
@@ -15,11 +15,10 @@
15
15
  * - EARS (`When`, `While`, `Where`, `Unless`) — lowercased
16
16
  * mid-sentence, capitalisation preserved when sentence-initial.
17
17
  *
18
- * The shared `RFC2119_MODAL_RE`, `EARS_KEYWORD_RE`, and `isSentenceInitial`
19
- * helpers are imported from `core/util/modals.ts` (D11 consolidation).
20
- * They cannot be imported from `formatter/mod.ts` because `formatter/`
21
- * depends on `ast/`, making an `ast → formatter` import a dependency cycle.
22
- * `core/util/` is the base level that both modules can import from.
18
+ * The shared `normalizeProseModals` helper is imported from
19
+ * `core/util/modals.ts`. Importing it from `formatter/mod.ts` would create
20
+ * a cycle because `formatter/` already depends on `ast/`.
21
+ * The helper uses only the standalone remark code-region parser.
23
22
  *
24
23
  * Invariants (HARD — never weaken):
25
24
  * - Pure: no `Deno.*`, no I/O.
@@ -36,38 +35,8 @@
36
35
  */
37
36
  Object.defineProperty(exports, "__esModule", { value: true });
38
37
  exports.normalizeBodyAst = normalizeBodyAst;
39
- const fence_js_1 = require("../util/fence.js");
40
38
  const modals_js_1 = require("../util/modals.js");
41
39
  // ---------------------------------------------------------------------------
42
- // §3.4.1 string helper — uses shared RFC2119_MODAL_RE, EARS_KEYWORD_RE,
43
- // and isSentenceInitial from core/util/modals.ts (D11 consolidation).
44
- // ---------------------------------------------------------------------------
45
- /**
46
- * Apply the §3.4.1 modal-keyword case rule to a prose string.
47
- *
48
- * Faithful port of `normalizeModalKeywords` (`core/formatter/mod.ts`):
49
- * fenced-code lines are skipped (verbatim, §5.1), and lines indented by
50
- * four or more spaces (or a tab) are skipped (conservatively captures
51
- * indented code blocks / attribute trailers — not prose). On every other
52
- * line, RFC 2119 keywords are lowercased unconditionally and EARS
53
- * keywords are lowercased unless sentence-initial.
54
- *
55
- * Pure and total: never throws; a string with no modal keyword is
56
- * returned unchanged.
57
- */
58
- function normalizeModalsInText(text) {
59
- const lines = text.split("\n");
60
- (0, fence_js_1.walkProseLines)(text, (line, i) => {
61
- // Indented-code / attribute-trailer lines aren't prose either.
62
- if (/^( {4}|\t)/.test(line))
63
- return;
64
- let normalized = line.replace(modals_js_1.RFC2119_MODAL_RE, (m) => m.toLowerCase());
65
- normalized = normalized.replace(modals_js_1.EARS_KEYWORD_RE, (m, _g1, offset) => (0, modals_js_1.isSentenceInitial)(normalized, offset) ? m : m.toLowerCase());
66
- lines[i] = normalized;
67
- });
68
- return lines.join("\n");
69
- }
70
- // ---------------------------------------------------------------------------
71
40
  // InlineContent normalisation
72
41
  // ---------------------------------------------------------------------------
73
42
  /**
@@ -78,7 +47,7 @@ function normalizeModalsInText(text) {
78
47
  * returned UNCHANGED (makes the no-op case allocation-free).
79
48
  */
80
49
  function normalizeInline(content) {
81
- const normalizedText = normalizeModalsInText(content.text);
50
+ const normalizedText = (0, modals_js_1.normalizeProseModals)(content.text);
82
51
  if (normalizedText === content.text)
83
52
  return content;
84
53
  return { text: normalizedText };