@driftsys/markspec 0.11.0 → 0.12.1

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 (176) 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 +5 -3
  11. package/esm/config/markspec.d.ts.map +1 -1
  12. package/esm/config/mod.d.ts.map +1 -1
  13. package/esm/config/mod.js +47 -5
  14. package/esm/discovery/mod.d.ts +24 -8
  15. package/esm/discovery/mod.d.ts.map +1 -1
  16. package/esm/discovery/mod.js +57 -21
  17. package/esm/discovery/projects.d.ts +111 -0
  18. package/esm/discovery/projects.d.ts.map +1 -0
  19. package/esm/discovery/projects.js +242 -0
  20. package/esm/formatter/entry_body.d.ts +84 -0
  21. package/esm/formatter/entry_body.d.ts.map +1 -0
  22. package/esm/formatter/entry_body.js +291 -0
  23. package/esm/formatter/md_equiv.d.ts +6 -5
  24. package/esm/formatter/md_equiv.d.ts.map +1 -1
  25. package/esm/formatter/md_equiv.js +6 -5
  26. package/esm/formatter/mod.d.ts +16 -9
  27. package/esm/formatter/mod.d.ts.map +1 -1
  28. package/esm/formatter/mod.js +327 -53
  29. package/esm/formatter/tab_markers.d.ts +15 -0
  30. package/esm/formatter/tab_markers.d.ts.map +1 -0
  31. package/esm/formatter/tab_markers.js +133 -0
  32. package/esm/gates/mod.d.ts.map +1 -1
  33. package/esm/gates/mod.js +6 -5
  34. package/esm/lint/runner.d.ts.map +1 -1
  35. package/esm/lint/runner.js +4 -4
  36. package/esm/lock/check.d.ts.map +1 -1
  37. package/esm/lock/check.js +2 -1
  38. package/esm/lock/edge_drift.d.ts +2 -0
  39. package/esm/lock/edge_drift.d.ts.map +1 -1
  40. package/esm/lock/edge_drift.js +4 -0
  41. package/esm/lock/mod.d.ts +1 -1
  42. package/esm/lock/mod.d.ts.map +1 -1
  43. package/esm/lock/mod.js +1 -1
  44. package/esm/lock/upstream_deps.js +1 -1
  45. package/esm/mod.d.ts +11 -6
  46. package/esm/mod.d.ts.map +1 -1
  47. package/esm/mod.js +9 -6
  48. package/esm/model/mod.d.ts +22 -1
  49. package/esm/model/mod.d.ts.map +1 -1
  50. package/esm/model/mod.js +10 -0
  51. package/esm/parser/code_regions.d.ts +29 -0
  52. package/esm/parser/code_regions.d.ts.map +1 -0
  53. package/esm/parser/code_regions.js +38 -0
  54. package/esm/parser/markdown.d.ts.map +1 -1
  55. package/esm/parser/markdown.js +103 -40
  56. package/esm/parser/mod.d.ts.map +1 -1
  57. package/esm/parser/mod.js +7 -1
  58. package/esm/parser/translate.d.ts.map +1 -1
  59. package/esm/parser/translate.js +5 -0
  60. package/esm/refs/mod.d.ts +6 -2
  61. package/esm/refs/mod.d.ts.map +1 -1
  62. package/esm/refs/mod.js +15 -21
  63. package/esm/reporter/mod.d.ts.map +1 -1
  64. package/esm/reporter/mod.js +2 -2
  65. package/esm/sync/mapping.d.ts +4 -3
  66. package/esm/sync/mapping.d.ts.map +1 -1
  67. package/esm/sync/mapping.js +52 -9
  68. package/esm/util/display_id.d.ts +20 -0
  69. package/esm/util/display_id.d.ts.map +1 -0
  70. package/esm/util/display_id.js +19 -0
  71. package/esm/util/fence.d.ts +20 -29
  72. package/esm/util/fence.d.ts.map +1 -1
  73. package/esm/util/fence.js +42 -50
  74. package/esm/util/modals.d.ts +6 -0
  75. package/esm/util/modals.d.ts.map +1 -1
  76. package/esm/util/modals.js +37 -0
  77. package/esm/validator/body_blocks.d.ts +2 -1
  78. package/esm/validator/body_blocks.d.ts.map +1 -1
  79. package/esm/validator/body_blocks.js +80 -2
  80. package/esm/validator/corpus.d.ts +6 -0
  81. package/esm/validator/corpus.d.ts.map +1 -1
  82. package/esm/validator/corpus.js +16 -4
  83. package/esm/validator/mod.d.ts +1 -1
  84. package/esm/validator/mod.d.ts.map +1 -1
  85. package/esm/validator/mod.js +1 -1
  86. package/esm/validator/pipeline.d.ts +6 -4
  87. package/esm/validator/pipeline.d.ts.map +1 -1
  88. package/esm/validator/pipeline.js +24 -19
  89. package/package.json +1 -1
  90. package/script/ast/normalize.d.ts +4 -5
  91. package/script/ast/normalize.d.ts.map +1 -1
  92. package/script/ast/normalize.js +5 -36
  93. package/script/collect/mod.d.ts +29 -9
  94. package/script/collect/mod.d.ts.map +1 -1
  95. package/script/collect/mod.js +38 -10
  96. package/script/compiler/mod.d.ts.map +1 -1
  97. package/script/compiler/mod.js +1 -5
  98. package/script/config/markspec.d.ts +5 -3
  99. package/script/config/markspec.d.ts.map +1 -1
  100. package/script/config/mod.d.ts.map +1 -1
  101. package/script/config/mod.js +47 -5
  102. package/script/discovery/mod.d.ts +24 -8
  103. package/script/discovery/mod.d.ts.map +1 -1
  104. package/script/discovery/mod.js +56 -20
  105. package/script/discovery/projects.d.ts +111 -0
  106. package/script/discovery/projects.d.ts.map +1 -0
  107. package/script/discovery/projects.js +250 -0
  108. package/script/formatter/entry_body.d.ts +84 -0
  109. package/script/formatter/entry_body.d.ts.map +1 -0
  110. package/script/formatter/entry_body.js +296 -0
  111. package/script/formatter/md_equiv.d.ts +6 -5
  112. package/script/formatter/md_equiv.d.ts.map +1 -1
  113. package/script/formatter/md_equiv.js +6 -5
  114. package/script/formatter/mod.d.ts +16 -9
  115. package/script/formatter/mod.d.ts.map +1 -1
  116. package/script/formatter/mod.js +324 -50
  117. package/script/formatter/tab_markers.d.ts +15 -0
  118. package/script/formatter/tab_markers.d.ts.map +1 -0
  119. package/script/formatter/tab_markers.js +141 -0
  120. package/script/gates/mod.d.ts.map +1 -1
  121. package/script/gates/mod.js +15 -14
  122. package/script/lint/runner.d.ts.map +1 -1
  123. package/script/lint/runner.js +3 -3
  124. package/script/lock/check.d.ts.map +1 -1
  125. package/script/lock/check.js +2 -1
  126. package/script/lock/edge_drift.d.ts +2 -0
  127. package/script/lock/edge_drift.d.ts.map +1 -1
  128. package/script/lock/edge_drift.js +5 -0
  129. package/script/lock/mod.d.ts +1 -1
  130. package/script/lock/mod.d.ts.map +1 -1
  131. package/script/lock/mod.js +2 -1
  132. package/script/lock/upstream_deps.js +1 -1
  133. package/script/mod.d.ts +11 -6
  134. package/script/mod.d.ts.map +1 -1
  135. package/script/mod.js +23 -5
  136. package/script/model/mod.d.ts +22 -1
  137. package/script/model/mod.d.ts.map +1 -1
  138. package/script/model/mod.js +11 -0
  139. package/script/parser/code_regions.d.ts +29 -0
  140. package/script/parser/code_regions.d.ts.map +1 -0
  141. package/script/parser/code_regions.js +41 -0
  142. package/script/parser/markdown.d.ts.map +1 -1
  143. package/script/parser/markdown.js +102 -39
  144. package/script/parser/mod.d.ts.map +1 -1
  145. package/script/parser/mod.js +7 -1
  146. package/script/parser/translate.d.ts.map +1 -1
  147. package/script/parser/translate.js +5 -0
  148. package/script/refs/mod.d.ts +6 -2
  149. package/script/refs/mod.d.ts.map +1 -1
  150. package/script/refs/mod.js +14 -20
  151. package/script/reporter/mod.d.ts.map +1 -1
  152. package/script/reporter/mod.js +1 -1
  153. package/script/sync/mapping.d.ts +4 -3
  154. package/script/sync/mapping.d.ts.map +1 -1
  155. package/script/sync/mapping.js +52 -9
  156. package/script/util/display_id.d.ts +20 -0
  157. package/script/util/display_id.d.ts.map +1 -0
  158. package/script/util/display_id.js +22 -0
  159. package/script/util/fence.d.ts +20 -29
  160. package/script/util/fence.d.ts.map +1 -1
  161. package/script/util/fence.js +47 -54
  162. package/script/util/modals.d.ts +6 -0
  163. package/script/util/modals.d.ts.map +1 -1
  164. package/script/util/modals.js +38 -0
  165. package/script/validator/body_blocks.d.ts +2 -1
  166. package/script/validator/body_blocks.d.ts.map +1 -1
  167. package/script/validator/body_blocks.js +80 -2
  168. package/script/validator/corpus.d.ts +6 -0
  169. package/script/validator/corpus.d.ts.map +1 -1
  170. package/script/validator/corpus.js +16 -3
  171. package/script/validator/mod.d.ts +1 -1
  172. package/script/validator/mod.d.ts.map +1 -1
  173. package/script/validator/mod.js +2 -1
  174. package/script/validator/pipeline.d.ts +6 -4
  175. package/script/validator/pipeline.d.ts.map +1 -1
  176. package/script/validator/pipeline.js +24 -19
@@ -0,0 +1,296 @@
1
+ "use strict";
2
+ /**
3
+ * @module formatter/entry_body
4
+ *
5
+ * Read and replace the body of one entry in a Markdown file text.
6
+ *
7
+ * Splice-only contract: {@linkcode replaceEntryBody} changes only the
8
+ * lines of the target entry's body. Every other line of the file (other
9
+ * entries, prose, front matter, the title, the trailer block, and each
10
+ * line's own line ending) stays byte-for-byte unchanged. After the splice
11
+ * the text is parsed again; when the set of entries differs (a new entry,
12
+ * a lost entry, a changed title or trailer) or the target's body is not
13
+ * the proposal, the edit is refused.
14
+ *
15
+ * The body range starts after the title paragraph (up to the first blank
16
+ * line after the title line, so a soft-wrapped title is skipped) and the
17
+ * blank lines after it. It has as many lines as the parser's
18
+ * `entry.body`, so lazy continuation lines are included, and it must
19
+ * match that body line for line. The body indent is the content column of
20
+ * the list item: the marker column, plus the marker width, plus the spaces
21
+ * after the marker. Lines are split on `\r\n`, a
22
+ * lone `\r`, or `\n`, as in the parser.
23
+ *
24
+ * Pure: no I/O, Node-compatible.
25
+ */
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.contentColumn = contentColumn;
28
+ exports.readEntryBody = readEntryBody;
29
+ exports.replaceEntryBody = replaceEntryBody;
30
+ const mod_js_1 = require("../parser/mod.js");
31
+ /**
32
+ * Split `text` into lines on `\r\n`, a lone `\r`, or `\n`, the same rule
33
+ * the parser uses to normalize line endings, so line indexes agree with
34
+ * parser line numbers. Each line keeps its own ending.
35
+ */
36
+ function splitText(text) {
37
+ const lines = [];
38
+ const endings = [];
39
+ const re = /\r\n|\r|\n/g;
40
+ let from = 0;
41
+ for (let m = re.exec(text); m !== null; m = re.exec(text)) {
42
+ lines.push(text.slice(from, m.index));
43
+ endings.push(m[0]);
44
+ from = m.index + m[0].length;
45
+ }
46
+ lines.push(text.slice(from));
47
+ endings.push("");
48
+ return { lines, endings };
49
+ }
50
+ /** Lines of `text` with trailing whitespace removed, for comparisons. */
51
+ function trimmedLines(text) {
52
+ return text.split("\n").map((l) => l.trimEnd());
53
+ }
54
+ /**
55
+ * Locate the body of `entry` in `lines`. `start === end` when the entry
56
+ * has no body.
57
+ *
58
+ * The body starts after the title paragraph and the blank lines that
59
+ * follow it. Its length is the line count of the parser's `entry.body`,
60
+ * so a lazy continuation line (a body line indented less than the body
61
+ * indent) is part of the span. `exact` is false when the dedented span,
62
+ * trimmed as a whole like the parser's body, does not match `entry.body`
63
+ * line for line (trailing whitespace ignored); the span is then not
64
+ * reliable and must not be edited.
65
+ */
66
+ function bodySpan(lines, entry) {
67
+ const titleIdx = entry.location.line - 1;
68
+ const indent = contentColumn(lines[titleIdx] ?? "", entry.location.column - 1);
69
+ const isBlank = (i) => lines[i].trim() === "";
70
+ let start = titleIdx + 1;
71
+ // Skip the rest of the title paragraph (a soft-wrapped title).
72
+ while (start < lines.length && !isBlank(start))
73
+ start++;
74
+ while (start < lines.length && isBlank(start))
75
+ start++;
76
+ if (entry.body === "")
77
+ return { start, end: start, indent, exact: true };
78
+ const expected = trimmedLines(entry.body);
79
+ const end = Math.min(start + expected.length, lines.length);
80
+ const actual = spanText(lines, { start, end, indent, exact: true });
81
+ // The parser trims its body as a whole, which drops the leading
82
+ // whitespace of the first line (an indented code block); trim the span
83
+ // the same way before comparing.
84
+ const exact = actual.join("\n").trim() === expected.join("\n");
85
+ return { start, end, indent, exact };
86
+ }
87
+ /**
88
+ * 0-based content column of the list item whose marker starts at `marker`
89
+ * on `line`: the marker column, plus 1 for the bullet, plus the whitespace
90
+ * after it. Tabs advance to the next four-column CommonMark tab stop.
91
+ * So `- [ID]` gives 2, `- [ID]` gives 4, and `-\t[ID]` gives 4 at
92
+ * column zero. Ordered lists never hold entries. When there is no bullet
93
+ * followed by whitespace at `marker`, use the marker column plus 2.
94
+ */
95
+ function contentColumn(line, marker) {
96
+ const m = /^[-*+]([ \t]+)/.exec(line.slice(marker));
97
+ if (!m)
98
+ return marker + 2;
99
+ let column = marker + 1;
100
+ for (const character of m[1]) {
101
+ column += character === "\t" ? 4 - column % 4 : 1;
102
+ }
103
+ return column;
104
+ }
105
+ /** Dedented span lines, trailing whitespace removed. */
106
+ function spanText(lines, span) {
107
+ return lines.slice(span.start, span.end)
108
+ .map((l) => l.trim() === "" ? "" : dedent(l, span.indent).trimEnd());
109
+ }
110
+ /** Parse `text` and find the entry named `displayId`. */
111
+ async function locate(text, file, displayId) {
112
+ const { entries, diagnostics } = await (0, mod_js_1.parseFile)(text, { file });
113
+ const entry = entries.find((e) => e.displayId === displayId);
114
+ const trailerInvalid = diagnostics.some((d) => TRAILER_PARSE_CODES.has(d.code) && d.message.startsWith(`${displayId}:`));
115
+ return {
116
+ entries,
117
+ entry,
118
+ diagnosticCodes: diagnostics.map((d) => d.code),
119
+ trailerInvalid,
120
+ };
121
+ }
122
+ /** Parse codes that mean an entry's trailer block did not parse. */
123
+ const TRAILER_PARSE_CODES = new Set([
124
+ "MSL-P020",
125
+ "MSL-P021",
126
+ "MSL-P022",
127
+ ]);
128
+ /**
129
+ * Body of the entry `displayId` as written in `text`: dedented, LF line
130
+ * endings, no surrounding blank lines. Returns `""` when the entry has no
131
+ * body and `undefined` when no entry has `displayId`. `file` names a
132
+ * `.md` file. When the body lines cannot be located exactly in `text`,
133
+ * the parser's body is returned (and {@linkcode replaceEntryBody}
134
+ * refuses to edit that entry).
135
+ */
136
+ async function readEntryBody(text, file, displayId) {
137
+ const { entry } = await locate(text, file, displayId);
138
+ if (!entry)
139
+ return undefined;
140
+ const { lines } = splitText(text);
141
+ const span = bodySpan(lines, entry);
142
+ if (!span.exact)
143
+ return entry.body;
144
+ return lines.slice(span.start, span.end)
145
+ .map((l) => l.trim() === "" ? "" : dedent(l, span.indent))
146
+ .join("\n");
147
+ }
148
+ /** Remove up to `indent` leading spaces. */
149
+ function dedent(line, indent) {
150
+ let i = 0;
151
+ while (i < indent && line[i] === " ")
152
+ i++;
153
+ return line.slice(i);
154
+ }
155
+ /**
156
+ * Return `text` with the body of entry `displayId` replaced by `body`,
157
+ * re-indented to the body indent. Every other line stays byte-for-byte
158
+ * unchanged. Inserted lines take the line ending of the title line. In
159
+ * `body`, `\r\n` and a lone `\r` count as line breaks.
160
+ *
161
+ * Refusals: `entry-not-found` (no such entry), `trailer-invalid` (the
162
+ * entry's trailer block did not parse, see below), `body-empty` (the entry
163
+ * has no body), `proposal-empty` (`body` is blank), `entries-changed`
164
+ * (two entries in `text` have `displayId`; or the body lines cannot be
165
+ * located exactly in `text`; or the edited
166
+ * text no longer parses to the same entries, with the same title and
167
+ * trailer for the target, and with the proposal as the target's body;
168
+ * or the parse raises more structural diagnostics of some code, such as
169
+ * MSL-P020, than the original text).
170
+ *
171
+ * `trailer-invalid`: when a trailer line is malformed (for example an
172
+ * empty `Labels:`, a key without a colon, or a lowercase key), the parser
173
+ * reads the whole trailer block, the `Id:` line included, as body. A
174
+ * splice would then delete the `Id:` and trailer lines, and the identity
175
+ * check cannot see it, because the entry has no `id` and no attributes
176
+ * before or after the edit. So the edit is refused when an `MSL-P020`,
177
+ * `MSL-P021` or `MSL-P022` names the entry (the message starts with
178
+ * `<displayId>:`). This is broader than that case: `MSL-P020` also fires
179
+ * when a body paragraph starts with a recognized trailer key, so such an
180
+ * entry is refused too. The file already fails `markspec check` there.
181
+ * An entry whose trailer-looking lines use only unrecognized keys, and
182
+ * that the parser reads as body without a diagnostic, is edited as the
183
+ * parser sees it: those lines are body.
184
+ */
185
+ async function replaceEntryBody(text, file, displayId, body) {
186
+ const before = await locate(text, file, displayId);
187
+ const entry = before.entry;
188
+ if (!entry)
189
+ return { ok: false, refusal: "entry-not-found" };
190
+ if (before.trailerInvalid)
191
+ return { ok: false, refusal: "trailer-invalid" };
192
+ // Two entries with the same display ID make the target ambiguous (and
193
+ // `markspec check` already rejects the file), so do not edit either.
194
+ if (before.entries.filter((e) => e.displayId === displayId).length > 1) {
195
+ return { ok: false, refusal: "entries-changed" };
196
+ }
197
+ const { lines, endings } = splitText(text);
198
+ const span = bodySpan(lines, entry);
199
+ if (span.start === span.end)
200
+ return { ok: false, refusal: "body-empty" };
201
+ if (!span.exact)
202
+ return { ok: false, refusal: "entries-changed" };
203
+ const proposal = body.replace(/\r\n?/g, "\n").split("\n");
204
+ while (proposal.length > 0 && proposal[0].trim() === "")
205
+ proposal.shift();
206
+ while (proposal.length > 0 && proposal[proposal.length - 1].trim() === "") {
207
+ proposal.pop();
208
+ }
209
+ if (proposal.length === 0)
210
+ return { ok: false, refusal: "proposal-empty" };
211
+ const titleIdx = entry.location.line - 1;
212
+ const eol = endings[titleIdx];
213
+ const indentStr = " ".repeat(span.indent);
214
+ const inserted = proposal.map((l) => (l.trim() === "" ? "" : indentStr + l) + eol);
215
+ // The final line of the file has no ending after it; keep the old
216
+ // ending of the last body line when the body reaches the file end.
217
+ if (span.end === lines.length) {
218
+ const last = inserted.length - 1;
219
+ inserted[last] = indentStr + proposal[last] + endings[span.end - 1];
220
+ }
221
+ const keep = (from, to) => {
222
+ let out = "";
223
+ for (let i = from; i < to; i++)
224
+ out += lines[i] + endings[i];
225
+ return out;
226
+ };
227
+ const edited = keep(0, span.start) + inserted.join("") +
228
+ keep(span.end, lines.length);
229
+ const after = await locate(edited, file, displayId);
230
+ if (!sameEntries(before.entries, after.entries, entry, after.entry) ||
231
+ addsParseDiagnostic(before.diagnosticCodes, after.diagnosticCodes) ||
232
+ trimmedLines(after.entry?.body ?? "").join("\n") !==
233
+ proposal.map((l) => l.trimEnd()).join("\n").trim()) {
234
+ return { ok: false, refusal: "entries-changed" };
235
+ }
236
+ return { ok: true, text: edited };
237
+ }
238
+ /**
239
+ * Identity check: same entry count; per index, same display ID and Id;
240
+ * for the target, also the same title and the same trailer attributes.
241
+ * An unclosed fence or HTML block in the proposal (for example a final
242
+ * line of three backticks) can swallow the target's trailer without any
243
+ * parse diagnostic; this comparison and the body-equality check in
244
+ * {@linkcode replaceEntryBody} are what refuse such an edit. No input is
245
+ * known that only one of the two refuses: the splice changes only body
246
+ * lines, so another entry, or the target's title or trailer, can change
247
+ * only through a block in the proposal that also changes the target body.
248
+ * (A link reference definition named like a later display ID does not
249
+ * remove that entry: the parser reads definitions only at the top level.)
250
+ * So the tests pin the pair, not either check by itself, and each check is
251
+ * a backstop for the other.
252
+ */
253
+ function sameEntries(before, after, target, targetAfter) {
254
+ if (before.length !== after.length || !targetAfter)
255
+ return false;
256
+ for (let i = 0; i < before.length; i++) {
257
+ if (before[i].displayId !== after[i].displayId)
258
+ return false;
259
+ if (before[i].id !== after[i].id)
260
+ return false;
261
+ }
262
+ if (target.title !== targetAfter.title)
263
+ return false;
264
+ const a = target.rawAttributes;
265
+ const b = targetAfter.rawAttributes;
266
+ if (a.length !== b.length)
267
+ return false;
268
+ return a.every((attr, i) => attr.key === b[i].key && attr.value === b[i].value);
269
+ }
270
+ /**
271
+ * True when `after` holds more diagnostics of some code than `before`.
272
+ * Counts per code, not messages, so diagnostics whose location moved with
273
+ * the splice do not count as new. This catches a body with a trailer-like
274
+ * line or an entry-shaped list item after a blank line (MSL-P020), which
275
+ * the parser keeps as body text and the entry comparison alone cannot
276
+ * see. An entry-shaped item directly after a paragraph line, with no
277
+ * blank line between them, raises no diagnostic; the parser keeps it as
278
+ * body text and adds no entry, so the edit is accepted.
279
+ *
280
+ * Known limit: the parser raises at most one MSL-P020 per entry, so when
281
+ * the target body already has a trailer-like line, a proposal that adds
282
+ * more such lines raises no new MSL-P020 and is accepted. The lines stay
283
+ * body text; no trailer or entry changes.
284
+ */
285
+ function addsParseDiagnostic(before, after) {
286
+ const counts = new Map();
287
+ for (const code of before)
288
+ counts.set(code, (counts.get(code) ?? 0) + 1);
289
+ for (const code of after) {
290
+ const left = (counts.get(code) ?? 0) - 1;
291
+ if (left < 0)
292
+ return true;
293
+ counts.set(code, left);
294
+ }
295
+ return false;
296
+ }
@@ -2,8 +2,9 @@
2
2
  * @module formatter/md_equiv
3
3
  *
4
4
  * CommonMark-semantic Markdown equivalence — the gate for the ADR-029
5
- * dprint pass. Two fragments are equivalent when they parse to the
6
- * same mdast structure after eliding source `position`s and collapsing
5
+ * dprint pass and entry tab-marker normalization. Two fragments are equivalent
6
+ * when they parse to the same mdast structure after eliding source `position`s
7
+ * and collapsing
7
8
  * ASCII whitespace runs inside `text` node values. Only ASCII
8
9
  * whitespace is collapsed — NBSP (U+00A0) and Unicode spaces are
9
10
  * content, not wrap artifacts, and must not compare equal to a plain
@@ -15,9 +16,9 @@
15
16
  * and definition `url`s stay byte-exact.
16
17
  *
17
18
  * DELIBERATELY weaker than ADR-015's `astEquivalent` (byte-verbatim on
18
- * inline markup). Used ONLY to accept/reject dprint output; the
19
- * ADR-015 relation still guards §5.2 body emission (MSL-F900) and must
20
- * not be modified.
19
+ * inline markup). Used to accept/reject dprint output and tab-marker rewrites.
20
+ * The ADR-015 relation still guards §5.2 body emission (MSL-F900) and must not
21
+ * be modified.
21
22
  */
22
23
  /** True when `a` and `b` are the same Markdown, modulo presentation. */
23
24
  export declare function markdownSemanticallyEquivalent(a: string, b: string): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"md_equiv.d.ts","sourceRoot":"","sources":["../../src/formatter/md_equiv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAQH,wEAAwE;AACxE,wBAAgB,8BAA8B,CAC5C,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,OAAO,CAMT"}
1
+ {"version":3,"file":"md_equiv.d.ts","sourceRoot":"","sources":["../../src/formatter/md_equiv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH,wEAAwE;AACxE,wBAAgB,8BAA8B,CAC5C,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,OAAO,CAMT"}
@@ -3,8 +3,9 @@
3
3
  * @module formatter/md_equiv
4
4
  *
5
5
  * CommonMark-semantic Markdown equivalence — the gate for the ADR-029
6
- * dprint pass. Two fragments are equivalent when they parse to the
7
- * same mdast structure after eliding source `position`s and collapsing
6
+ * dprint pass and entry tab-marker normalization. Two fragments are equivalent
7
+ * when they parse to the same mdast structure after eliding source `position`s
8
+ * and collapsing
8
9
  * ASCII whitespace runs inside `text` node values. Only ASCII
9
10
  * whitespace is collapsed — NBSP (U+00A0) and Unicode spaces are
10
11
  * content, not wrap artifacts, and must not compare equal to a plain
@@ -16,9 +17,9 @@
16
17
  * and definition `url`s stay byte-exact.
17
18
  *
18
19
  * DELIBERATELY weaker than ADR-015's `astEquivalent` (byte-verbatim on
19
- * inline markup). Used ONLY to accept/reject dprint output; the
20
- * ADR-015 relation still guards §5.2 body emission (MSL-F900) and must
21
- * not be modified.
20
+ * inline markup). Used to accept/reject dprint output and tab-marker rewrites.
21
+ * The ADR-015 relation still guards §5.2 body emission (MSL-F900) and must not
22
+ * be modified.
22
23
  */
23
24
  var __importDefault = (this && this.__importDefault) || function (mod) {
24
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -6,6 +6,7 @@
6
6
  * and requirement block insertion.
7
7
  */
8
8
  import type { Attribute, Diagnostic } from "../model/mod.js";
9
+ import { type EntryExtent } from "./prose.js";
9
10
  import { type ProseFormatter } from "./dprint.js";
10
11
  /**
11
12
  * Decide whether the EARS keyword at `offset` in `line` is at sentence
@@ -24,7 +25,7 @@ export declare function isSentenceInitial(line: string, offset: number): boolean
24
25
  *
25
26
  * The pass skips:
26
27
  *
27
- * - Fenced code blocks (between paired ``` or ~~~ markers) — code is
28
+ * - CommonMark fenced code blocks and inline-code spans — code is
28
29
  * verbatim per round-trip invariants (spec §5.1).
29
30
  * - Lines indented by four or more spaces (or a tab) — conservatively
30
31
  * captures indented code blocks and attribute trailers, both of which
@@ -33,8 +34,8 @@ export declare function isSentenceInitial(line: string, offset: number): boolean
33
34
  * @remarks Not called by `format()` as of SP3 Task 5 — body modal
34
35
  * normalization moved to `normalizeBodyAst` in the AST pass (spec-correct
35
36
  * verbatim-boundary handling). Retained as an exported symbol because
36
- * `mod_test.ts` tests it directly and `core/ast/normalize.ts` documents
37
- * the intentional duplication until a follow-up collapses the two. Do NOT
37
+ * `mod_test.ts` tests it directly. Both entry points delegate to the same
38
+ * AST-backed prose normalizer. Do NOT
38
39
  * delete — external callers may depend on this export.
39
40
  */
40
41
  export declare function normalizeModalKeywords(markdown: string): string;
@@ -76,6 +77,8 @@ export interface FormatResult {
76
77
  readonly diagnostics: readonly Diagnostic[];
77
78
  /** Whether any changes were made. */
78
79
  readonly changed: boolean;
80
+ /** Output line spans (0-based, end exclusive) kept unchanged after refusal. */
81
+ readonly preservedRanges?: readonly EntryExtent[];
79
82
  }
80
83
  /**
81
84
  * Format a Markdown string — normalize attribute blocks,
@@ -121,17 +124,21 @@ export declare function sortAttributes(attributes: Attribute[]): Attribute[];
121
124
  * no trailing line-continuation characters.
122
125
  *
123
126
  * @param attributes - The attributes to render, in canonical order.
124
- * @param indent - Body indent for the entry (2 for list-wrapped entries,
125
- * 0 for entries inside source-file doc comments).
127
+ * @param indent - The 0-based list item content column, or 0 inside
128
+ * source-file doc comments.
126
129
  */
127
130
  export declare function renderAttributeBlock(attributes: Attribute[], indent: number): string;
128
131
  /**
129
132
  * Find the 0-based line index where a list item's content ends.
130
133
  * Exported for the ADR-029 prose pass (entry-extent computation).
131
- * Scans forward from the entry start, stopping at: a sibling list item
132
- * (`- ` at the entry's marker column), a line with less indent, or EOF.
134
+ * Scans forward from the later of the line after the entry start and
135
+ * `itemEndFloor` until a line has less indent than the content column, a
136
+ * conventional sibling marker is found, or EOF. Pass the parser's
137
+ * `Entry.endLine` as `itemEndFloor` so that a lazy continuation line
138
+ * inside the item does not end the scan early; the default `0` keeps
139
+ * the indentation-only scan.
133
140
  */
134
- export declare function findItemEnd(lines: readonly string[], startIdx: number, indent: number): number;
141
+ export declare function findItemEnd(lines: readonly string[], startIdx: number, indent: number, itemEndFloor?: number): number;
135
142
  /**
136
143
  * Find the 0-based line range [start, end) of the attribute block
137
144
  * for an entry starting at the given line.
@@ -139,7 +146,7 @@ export declare function findItemEnd(lines: readonly string[], startIdx: number,
139
146
  * Scans forward from the entry start to find the list item boundary,
140
147
  * then walks backwards to find the contiguous trailing attribute block.
141
148
  */
142
- export declare function findAttributeBlockRange(lines: readonly string[], entryStartLine: number, indent: number): {
149
+ export declare function findAttributeBlockRange(lines: readonly string[], entryStartLine: number, indent: number, itemEndFloor?: number, preservedRanges?: readonly EntryExtent[]): {
143
150
  start: number;
144
151
  end: number;
145
152
  } | undefined;
@@ -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;C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