@driftsys/markspec 0.12.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.
- package/esm/config/markspec.d.ts +2 -2
- package/esm/config/mod.d.ts.map +1 -1
- package/esm/config/mod.js +47 -5
- package/esm/discovery/projects.d.ts +6 -4
- package/esm/discovery/projects.d.ts.map +1 -1
- package/esm/discovery/projects.js +27 -17
- package/esm/formatter/entry_body.d.ts +5 -7
- package/esm/formatter/entry_body.d.ts.map +1 -1
- package/esm/formatter/entry_body.js +13 -9
- package/esm/formatter/md_equiv.d.ts +6 -5
- package/esm/formatter/md_equiv.d.ts.map +1 -1
- package/esm/formatter/md_equiv.js +6 -5
- package/esm/formatter/mod.d.ts +4 -1
- package/esm/formatter/mod.d.ts.map +1 -1
- package/esm/formatter/mod.js +206 -8
- package/esm/formatter/tab_markers.d.ts +15 -0
- package/esm/formatter/tab_markers.d.ts.map +1 -0
- package/esm/formatter/tab_markers.js +133 -0
- package/esm/gates/mod.d.ts.map +1 -1
- package/esm/gates/mod.js +1 -1
- package/esm/lock/upstream_deps.js +1 -1
- package/esm/mod.d.ts +2 -1
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -1
- package/esm/model/mod.d.ts +1 -1
- package/esm/refs/mod.d.ts +6 -2
- package/esm/refs/mod.d.ts.map +1 -1
- package/esm/refs/mod.js +8 -3
- package/esm/sync/mapping.d.ts +4 -3
- package/esm/sync/mapping.d.ts.map +1 -1
- package/esm/sync/mapping.js +52 -9
- package/esm/util/display_id.d.ts +20 -0
- package/esm/util/display_id.d.ts.map +1 -0
- package/esm/util/display_id.js +19 -0
- package/esm/validator/pipeline.d.ts +6 -4
- package/esm/validator/pipeline.d.ts.map +1 -1
- package/esm/validator/pipeline.js +13 -11
- package/package.json +1 -1
- package/script/config/markspec.d.ts +2 -2
- package/script/config/mod.d.ts.map +1 -1
- package/script/config/mod.js +47 -5
- package/script/discovery/projects.d.ts +6 -4
- package/script/discovery/projects.d.ts.map +1 -1
- package/script/discovery/projects.js +27 -17
- package/script/formatter/entry_body.d.ts +5 -7
- package/script/formatter/entry_body.d.ts.map +1 -1
- package/script/formatter/entry_body.js +13 -9
- package/script/formatter/md_equiv.d.ts +6 -5
- package/script/formatter/md_equiv.d.ts.map +1 -1
- package/script/formatter/md_equiv.js +6 -5
- package/script/formatter/mod.d.ts +4 -1
- package/script/formatter/mod.d.ts.map +1 -1
- package/script/formatter/mod.js +205 -7
- package/script/formatter/tab_markers.d.ts +15 -0
- package/script/formatter/tab_markers.d.ts.map +1 -0
- package/script/formatter/tab_markers.js +141 -0
- package/script/gates/mod.d.ts.map +1 -1
- package/script/gates/mod.js +1 -1
- package/script/lock/upstream_deps.js +1 -1
- package/script/mod.d.ts +2 -1
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +8 -5
- package/script/model/mod.d.ts +1 -1
- package/script/refs/mod.d.ts +6 -2
- package/script/refs/mod.d.ts.map +1 -1
- package/script/refs/mod.js +8 -3
- package/script/sync/mapping.d.ts +4 -3
- package/script/sync/mapping.d.ts.map +1 -1
- package/script/sync/mapping.js +52 -9
- package/script/util/display_id.d.ts +20 -0
- package/script/util/display_id.d.ts.map +1 -0
- package/script/util/display_id.js +22 -0
- package/script/validator/pipeline.d.ts +6 -4
- package/script/validator/pipeline.d.ts.map +1 -1
- package/script/validator/pipeline.js +13 -11
package/esm/formatter/mod.js
CHANGED
|
@@ -10,7 +10,7 @@ import { ulid as defaultUlid } from "@std/ulid";
|
|
|
10
10
|
import { stringify as stringifyYaml } from "@std/yaml";
|
|
11
11
|
import { attributeSpec, CSV_SPLITTABLE_TYPES, IDENTITY_KEY, } from "../model/mod.js";
|
|
12
12
|
import { MARKDOWN_EXTENSIONS } from "../discovery/mod.js";
|
|
13
|
-
import { ATTR_LINE_RE } from "../parser/attributes.js";
|
|
13
|
+
import { ATTR_LINE_RE, parseAttributes } from "../parser/attributes.js";
|
|
14
14
|
import { extractFrontMatter } from "../parser/frontmatter.js";
|
|
15
15
|
import { parseMarkdown } from "../parser/markdown.js";
|
|
16
16
|
import { fencedCodeLines } from "../util/fence.js";
|
|
@@ -23,6 +23,7 @@ import { normalizeBodyAst } from "../ast/normalize.js";
|
|
|
23
23
|
import { astEquivalent } from "../ast/equivalence.js";
|
|
24
24
|
import { formatProseSegments } from "./prose.js";
|
|
25
25
|
import { contentColumn } from "./entry_body.js";
|
|
26
|
+
import { entryListItems, protectedTabRanges, tabMarkers, } from "./tab_markers.js";
|
|
26
27
|
import { MARKSPEC_MARKDOWN_GLOBAL_CONFIG, } from "./dprint.js";
|
|
27
28
|
import { markdownSemanticallyEquivalent } from "./md_equiv.js";
|
|
28
29
|
/**
|
|
@@ -209,10 +210,60 @@ function emitBodyViaAst(lines, file, diagnostics, cachedEntries, proseFormat) {
|
|
|
209
210
|
// Process bottom-to-top so splices don't shift earlier entry positions.
|
|
210
211
|
const sorted = [...entries].sort((a, b) => b.location.line - a.location.line);
|
|
211
212
|
for (const entry of sorted) {
|
|
213
|
+
const protectedRanges = protectedTabRanges(lines);
|
|
214
|
+
const start = entry.location.line - 1;
|
|
215
|
+
if (protectedRanges.some((range) => start >= range.start && start < range.end))
|
|
216
|
+
continue;
|
|
217
|
+
const children = protectedRanges.filter((range, index) => range.start > start && range.start < (entry.endLine ?? start) &&
|
|
218
|
+
!protectedRanges.some((outer, other) => other !== index &&
|
|
219
|
+
outer.start < range.start && outer.end >= range.end));
|
|
220
|
+
if (children.length > 0) {
|
|
221
|
+
// Format the parent's prose with each refused child represented by a
|
|
222
|
+
// verbatim block, then restore the original child lines.
|
|
223
|
+
const end = entry.endLine;
|
|
224
|
+
const fragment = lines.slice(start, end);
|
|
225
|
+
const indent = contentColumn(lines[start], entry.location.column - 1);
|
|
226
|
+
const replacements = [];
|
|
227
|
+
for (const child of children.toReversed()) {
|
|
228
|
+
const childEnd = Math.min(child.end, end);
|
|
229
|
+
let token = "<!-- markspec-preserved-child -->";
|
|
230
|
+
while (lines.some((line) => line.includes(token)) ||
|
|
231
|
+
replacements.some((r) => r.token === token))
|
|
232
|
+
token = token.replace(" -->", "- -->");
|
|
233
|
+
replacements.push({
|
|
234
|
+
token,
|
|
235
|
+
original: lines.slice(child.start, childEnd),
|
|
236
|
+
});
|
|
237
|
+
fragment.splice(child.start - start, childEnd - child.start, " ".repeat(indent) + token, "");
|
|
238
|
+
}
|
|
239
|
+
const nestedDiagnostics = [];
|
|
240
|
+
emitBodyViaAst(fragment, file, nestedDiagnostics, undefined, proseFormat);
|
|
241
|
+
for (const { token, original } of replacements) {
|
|
242
|
+
const at = fragment.findIndex((line) => line.trim() === token);
|
|
243
|
+
if (at < 0)
|
|
244
|
+
throw new Error("Preserved child placeholder was lost");
|
|
245
|
+
let after = at + 1;
|
|
246
|
+
while (after < fragment.length && fragment[after].trim() === "") {
|
|
247
|
+
after++;
|
|
248
|
+
}
|
|
249
|
+
fragment.splice(at, after - at, ...original);
|
|
250
|
+
}
|
|
251
|
+
diagnostics.push(...nestedDiagnostics.map((d) => ({
|
|
252
|
+
...d,
|
|
253
|
+
location: d.location
|
|
254
|
+
? { ...d.location, line: d.location.line + start }
|
|
255
|
+
: undefined,
|
|
256
|
+
})));
|
|
257
|
+
if (fragment.join("\n") !== lines.slice(start, end).join("\n")) {
|
|
258
|
+
lines.splice(start, end - start, ...fragment);
|
|
259
|
+
bodyChanged = true;
|
|
260
|
+
}
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
212
263
|
if (!entry.body.trim())
|
|
213
264
|
continue; // empty or whitespace-only body
|
|
214
265
|
// List-item continuation indent: the item's content column, which
|
|
215
|
-
//
|
|
266
|
+
// counts every space and tab after the marker (#865).
|
|
216
267
|
const indent = contentColumn(lines[entry.location.line - 1] ?? "", entry.location.column - 1);
|
|
217
268
|
const indentStr = " ".repeat(indent);
|
|
218
269
|
const titleLineIdx = entry.location.line - 1; // 0-based
|
|
@@ -354,6 +405,97 @@ function stampDisciplineFrozen(value, today) {
|
|
|
354
405
|
}
|
|
355
406
|
return value;
|
|
356
407
|
}
|
|
408
|
+
/**
|
|
409
|
+
* Normalize tab markers before any pass can stamp or splice their entries.
|
|
410
|
+
* Compare whole documents so a neighbouring list cannot become a child.
|
|
411
|
+
*/
|
|
412
|
+
function normalizeTabMarkers(markdown, options, diagnostics) {
|
|
413
|
+
const lines = markdown.split("\n");
|
|
414
|
+
const original = [...lines];
|
|
415
|
+
const markers = tabMarkers(lines).sort((a, b) => b.start - a.start);
|
|
416
|
+
if (markers.length === 0)
|
|
417
|
+
return markdown;
|
|
418
|
+
const accepted = new Set();
|
|
419
|
+
const refused = new Set();
|
|
420
|
+
for (const marker of markers) {
|
|
421
|
+
const before = lines.join("\n");
|
|
422
|
+
const candidate = [...lines];
|
|
423
|
+
const title = lines[marker.start];
|
|
424
|
+
const indent = contentColumn(title, marker.column);
|
|
425
|
+
const delta = indent - (marker.column + 2);
|
|
426
|
+
candidate[marker.start] = title.slice(0, marker.column) + "- " +
|
|
427
|
+
title.slice(marker.column + 1 + marker.whitespace.length);
|
|
428
|
+
for (let i = marker.start + 1; i < marker.end; i++) {
|
|
429
|
+
if (candidate[i].startsWith(" ".repeat(indent))) {
|
|
430
|
+
candidate[i] = candidate[i].slice(delta);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
const after = candidate.join("\n");
|
|
434
|
+
const beforeEntries = parseMarkdown(before).entries;
|
|
435
|
+
const afterEntries = parseMarkdown(after).entries;
|
|
436
|
+
const identitiesKept = beforeEntries.length === afterEntries.length &&
|
|
437
|
+
beforeEntries.every((entry, i) => entry.displayId === afterEntries[i].displayId &&
|
|
438
|
+
entry.id === afterEntries[i].id);
|
|
439
|
+
const containsRefused = [...refused].some((start) => start > marker.start && start < marker.end);
|
|
440
|
+
if (containsRefused || !markdownSemanticallyEquivalent(before, after) ||
|
|
441
|
+
!identitiesKept) {
|
|
442
|
+
// Refusing an enclosing entry must also undo admitted changes to its
|
|
443
|
+
// descendants. No identities have been stamped at this point.
|
|
444
|
+
lines.splice(marker.start, marker.end - marker.start, ...original.slice(marker.start, marker.end));
|
|
445
|
+
for (const start of accepted) {
|
|
446
|
+
if (start >= marker.start && start < marker.end)
|
|
447
|
+
accepted.delete(start);
|
|
448
|
+
}
|
|
449
|
+
refused.add(marker.start);
|
|
450
|
+
diagnostics.push({
|
|
451
|
+
code: "MSL-F013",
|
|
452
|
+
severity: "warning",
|
|
453
|
+
message: "Tab-separated entry marker cannot be normalized without " +
|
|
454
|
+
"changing CommonMark structure; kept the entry unchanged",
|
|
455
|
+
location: {
|
|
456
|
+
file: options?.file ?? "<unknown>",
|
|
457
|
+
line: marker.start + 1,
|
|
458
|
+
column: marker.column + 1,
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
lines.splice(0, lines.length, ...candidate);
|
|
464
|
+
accepted.add(marker.start);
|
|
465
|
+
}
|
|
466
|
+
const indexedStarts = new Set(parseMarkdown(lines.join("\n")).entries.map((entry) => entry.location.line - 1));
|
|
467
|
+
for (const start of [...accepted].sort((a, b) => b - a)) {
|
|
468
|
+
// Re-read extents after each nested splice. Admission itself never
|
|
469
|
+
// changes line counts, so earlier title positions remain valid.
|
|
470
|
+
const marker = entryListItems(lines).find((item) => item.start === start);
|
|
471
|
+
// Nested entries are outside the parser's top-level entry index. Format
|
|
472
|
+
// their normalized item separately, then restore the enclosing indent.
|
|
473
|
+
if (marker.container.start !== marker.start &&
|
|
474
|
+
!indexedStarts.has(marker.container.start)) {
|
|
475
|
+
const prefix = " ".repeat(marker.column);
|
|
476
|
+
const fragment = lines.slice(marker.start, marker.end)
|
|
477
|
+
.map((line) => line.startsWith(prefix) ? line.slice(prefix.length) : line)
|
|
478
|
+
.join("\n");
|
|
479
|
+
const nested = formatEntries(fragment, options);
|
|
480
|
+
const replacement = nested.output.split("\n")
|
|
481
|
+
.map((line) => line === "" ? "" : prefix + line);
|
|
482
|
+
lines.splice(marker.start, marker.end - marker.start, ...replacement);
|
|
483
|
+
diagnostics.push(...nested.diagnostics.map((diagnostic) => ({
|
|
484
|
+
...diagnostic,
|
|
485
|
+
...(diagnostic.location
|
|
486
|
+
? {
|
|
487
|
+
location: {
|
|
488
|
+
...diagnostic.location,
|
|
489
|
+
line: diagnostic.location.line + marker.start,
|
|
490
|
+
column: diagnostic.location.column + marker.column,
|
|
491
|
+
},
|
|
492
|
+
}
|
|
493
|
+
: {}),
|
|
494
|
+
})));
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return lines.join("\n");
|
|
498
|
+
}
|
|
357
499
|
/**
|
|
358
500
|
* Format a Markdown string — normalize attribute blocks,
|
|
359
501
|
* fix indentation, enforce canonical ordering.
|
|
@@ -363,6 +505,20 @@ function stampDisciplineFrozen(value, today) {
|
|
|
363
505
|
* @returns Format result with output text and diagnostics
|
|
364
506
|
*/
|
|
365
507
|
export function format(markdown, options) {
|
|
508
|
+
const diagnostics = [];
|
|
509
|
+
const ending = detectLineEnding(markdown);
|
|
510
|
+
const prepared = normalizeTabMarkers(normalizeLineEndings(markdown), options, diagnostics);
|
|
511
|
+
const result = formatEntries(prepared, options);
|
|
512
|
+
const output = applyLineEnding(result.output, ending);
|
|
513
|
+
return {
|
|
514
|
+
output,
|
|
515
|
+
diagnostics: [...diagnostics, ...result.diagnostics],
|
|
516
|
+
changed: output !== markdown,
|
|
517
|
+
preservedRanges: protectedTabRanges(normalizeLineEndings(output).split("\n")),
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
/** Run the entry and prose passes after tab-marker admission. */
|
|
521
|
+
function formatEntries(markdown, options) {
|
|
366
522
|
const file = options?.file ?? "<unknown>";
|
|
367
523
|
// Detect the source file's line-ending convention up front so we can
|
|
368
524
|
// restore it on write-back. The rest of the formatter operates on a
|
|
@@ -407,7 +563,11 @@ export function format(markdown, options) {
|
|
|
407
563
|
// Process bottom-to-top so line splicing doesn't shift earlier entries.
|
|
408
564
|
const sorted = [...entries].sort((a, b) => b.location.line - a.location.line);
|
|
409
565
|
const genUlid = options?.generateUlid ?? defaultUlid;
|
|
566
|
+
const protectedRanges = protectedTabRanges(lines);
|
|
410
567
|
for (const entry of sorted) {
|
|
568
|
+
if (protectedRanges.some((range) => entry.location.line - 1 >= range.start &&
|
|
569
|
+
entry.location.line - 1 < range.end))
|
|
570
|
+
continue;
|
|
411
571
|
const indent = contentColumn(lines[entry.location.line - 1] ?? "", entry.location.column - 1);
|
|
412
572
|
// `entry.endLine` comes from the parse of the unedited buffer. Entries
|
|
413
573
|
// are processed bottom to top, so only this entry's own edits move its
|
|
@@ -416,7 +576,14 @@ export function format(markdown, options) {
|
|
|
416
576
|
const itemEndFloor = () => entry.endLine === undefined
|
|
417
577
|
? 0
|
|
418
578
|
: entry.endLine + (lines.length - lengthAtStart);
|
|
419
|
-
|
|
579
|
+
const existingTrailer = protectedRanges.length > 0
|
|
580
|
+
? findAttributeBlockRange(lines, entry.location.line, indent, itemEndFloor(), protectedRanges)
|
|
581
|
+
: undefined;
|
|
582
|
+
let attrs = protectedRanges.length > 0
|
|
583
|
+
? existingTrailer
|
|
584
|
+
? parseAttributes(lines.slice(existingTrailer.start, existingTrailer.end))
|
|
585
|
+
: []
|
|
586
|
+
: [...entry.rawAttributes];
|
|
420
587
|
const titleLineIdx = entry.location.line - 1;
|
|
421
588
|
// #686: a title that soft-wraps onto extra physical lines is a single
|
|
422
589
|
// Markdown paragraph, but the line-based passes here and in
|
|
@@ -512,7 +679,7 @@ export function format(markdown, options) {
|
|
|
512
679
|
if (attrs.length === 0)
|
|
513
680
|
continue;
|
|
514
681
|
const normalized = sortAttributes(expandCsvValues(attrs));
|
|
515
|
-
const range = findAttributeBlockRange(lines, entry.location.line, indent, itemEndFloor());
|
|
682
|
+
const range = findAttributeBlockRange(lines, entry.location.line, indent, itemEndFloor(), protectedRanges);
|
|
516
683
|
if (range) {
|
|
517
684
|
// Replace existing attribute block.
|
|
518
685
|
const newBlock = renderAttributeBlock(normalized, indent);
|
|
@@ -571,7 +738,26 @@ export function format(markdown, options) {
|
|
|
571
738
|
end: findItemEnd(collapsedLines, start, entryIndent, e.endLine ?? 0),
|
|
572
739
|
};
|
|
573
740
|
});
|
|
574
|
-
|
|
741
|
+
if (tabMarkers(collapsedLines).length > 0) {
|
|
742
|
+
// Title-only entry items are outside the entry index. Keep their list
|
|
743
|
+
// context too: isolated prose formatting can move adjacent entries.
|
|
744
|
+
const indexedStarts = new Set(proseEntries.map((entry) => entry.location.line - 1));
|
|
745
|
+
extents.push(...entryListItems(collapsedLines)
|
|
746
|
+
.filter((item) => !indexedStarts.has(item.start))
|
|
747
|
+
.map((item) => item.listContext));
|
|
748
|
+
extents.push(...protectedTabRanges(collapsedLines, true));
|
|
749
|
+
}
|
|
750
|
+
extents.sort((a, b) => a.start - b.start);
|
|
751
|
+
const merged = [];
|
|
752
|
+
for (const extent of extents) {
|
|
753
|
+
const previous = merged.at(-1);
|
|
754
|
+
if (previous && extent.start <= previous.end) {
|
|
755
|
+
previous.end = Math.max(previous.end, extent.end);
|
|
756
|
+
}
|
|
757
|
+
else
|
|
758
|
+
merged.push({ ...extent });
|
|
759
|
+
}
|
|
760
|
+
const prose = formatProseSegments(collapsedLines, merged, proseFormat);
|
|
575
761
|
if (prose.changed)
|
|
576
762
|
changed = true;
|
|
577
763
|
for (const fallback of prose.fallbacks) {
|
|
@@ -635,9 +821,11 @@ function renderFrontMatter(attrs) {
|
|
|
635
821
|
function collapseBlankLines(lines) {
|
|
636
822
|
const out = [];
|
|
637
823
|
const fencedLines = fencedCodeLines(lines.join("\n"));
|
|
824
|
+
const protectedRanges = protectedTabRanges(lines, true);
|
|
638
825
|
let prevBlank = false;
|
|
639
826
|
for (const [i, line] of lines.entries()) {
|
|
640
|
-
if (fencedLines.has(i)
|
|
827
|
+
if (fencedLines.has(i) ||
|
|
828
|
+
protectedRanges.some((range) => i >= range.start && i < range.end)) {
|
|
641
829
|
out.push(line);
|
|
642
830
|
prevBlank = false;
|
|
643
831
|
continue;
|
|
@@ -798,19 +986,26 @@ function removeEmptyTrailerLines(body, entries, diagnostics) {
|
|
|
798
986
|
const lines = body.split("\n");
|
|
799
987
|
let removedAny = false;
|
|
800
988
|
const sorted = [...entries].sort((a, b) => b.location.line - a.location.line);
|
|
989
|
+
const protectedRanges = protectedTabRanges(lines);
|
|
801
990
|
for (const entry of sorted) {
|
|
991
|
+
if (protectedRanges.some((range) => entry.location.line - 1 >= range.start &&
|
|
992
|
+
entry.location.line - 1 < range.end))
|
|
993
|
+
continue;
|
|
802
994
|
const indent = contentColumn(lines[entry.location.line - 1] ?? "", entry.location.column - 1);
|
|
803
995
|
const startIdx = entry.location.line - 1;
|
|
804
996
|
let end = findItemEnd(lines, startIdx, indent, entry.endLine ?? 0);
|
|
805
997
|
while (end > startIdx && lines[end - 1].trim() === "")
|
|
806
998
|
end--;
|
|
807
999
|
let start = end;
|
|
808
|
-
while (start - 1 > startIdx && lines[start - 1].trim() !== ""
|
|
1000
|
+
while (start - 1 > startIdx && lines[start - 1].trim() !== "" &&
|
|
1001
|
+
!protectedRanges.some((range) => start - 1 >= range.start && start - 1 < range.end))
|
|
809
1002
|
start--;
|
|
810
1003
|
if (start >= end || start - 1 <= startIdx)
|
|
811
1004
|
continue;
|
|
812
1005
|
const trailerIndent = " ".repeat(indent + 4);
|
|
813
1006
|
const block = lines.slice(start, end);
|
|
1007
|
+
if (protectedRanges.some((range) => range.start > startIdx && start < range.end && end > range.start))
|
|
1008
|
+
continue;
|
|
814
1009
|
const isTrailerBlock = block.every((l) => l.startsWith(trailerIndent) && TRAILER_SHAPED_RE.test(l.trim()));
|
|
815
1010
|
if (!isTrailerBlock)
|
|
816
1011
|
continue;
|
|
@@ -847,7 +1042,7 @@ function removeEmptyTrailerLines(body, entries, diagnostics) {
|
|
|
847
1042
|
* Scans forward from the entry start to find the list item boundary,
|
|
848
1043
|
* then walks backwards to find the contiguous trailing attribute block.
|
|
849
1044
|
*/
|
|
850
|
-
export function findAttributeBlockRange(lines, entryStartLine, indent, itemEndFloor = 0) {
|
|
1045
|
+
export function findAttributeBlockRange(lines, entryStartLine, indent, itemEndFloor = 0, preservedRanges = []) {
|
|
851
1046
|
const startIdx = entryStartLine - 1;
|
|
852
1047
|
const itemEnd = findItemEnd(lines, startIdx, indent, itemEndFloor);
|
|
853
1048
|
// Walk backwards from itemEnd, skip trailing blank lines.
|
|
@@ -860,6 +1055,9 @@ export function findAttributeBlockRange(lines, entryStartLine, indent, itemEndFl
|
|
|
860
1055
|
// Walk backwards collecting attribute lines.
|
|
861
1056
|
let attrStart = scanEnd;
|
|
862
1057
|
for (let i = scanEnd - 1; i > startIdx; i--) {
|
|
1058
|
+
if (preservedRanges.some((range) => i >= range.start && i < range.end)) {
|
|
1059
|
+
break;
|
|
1060
|
+
}
|
|
863
1061
|
const trimmed = lines[i].trim();
|
|
864
1062
|
if (trimmed === "")
|
|
865
1063
|
break;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { EntryExtent } from "./prose.js";
|
|
2
|
+
/** An entry title and the list context that controls its indentation. */
|
|
3
|
+
export interface EntryListItem extends EntryExtent {
|
|
4
|
+
readonly column: number;
|
|
5
|
+
readonly whitespace: string;
|
|
6
|
+
readonly container: EntryExtent;
|
|
7
|
+
readonly listContext: EntryExtent;
|
|
8
|
+
}
|
|
9
|
+
/** Find actual unordered list items, excluding code, HTML, and task lists. */
|
|
10
|
+
export declare function entryListItems(lines: readonly string[]): EntryListItem[];
|
|
11
|
+
/** Find entry list items with a tab in the whitespace after the marker. */
|
|
12
|
+
export declare function tabMarkers(lines: readonly string[]): EntryListItem[];
|
|
13
|
+
/** Ranges kept out of every formatter pass after a tab rewrite is refused. */
|
|
14
|
+
export declare function protectedTabRanges(lines: readonly string[], preserveListContext?: boolean): EntryExtent[];
|
|
15
|
+
//# sourceMappingURL=tab_markers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tab_markers.d.ts","sourceRoot":"","sources":["../../src/formatter/tab_markers.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,yEAAyE;AACzE,MAAM,WAAW,aAAc,SAAQ,WAAW;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;CACnC;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,aAAa,EAAE,CAoFxE;AAED,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,aAAa,EAAE,CAKpE;AAED,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,mBAAmB,UAAQ,GAC1B,WAAW,EAAE,CA4Cf"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { unified } from "unified";
|
|
2
|
+
import remarkParse from "remark-parse";
|
|
3
|
+
import remarkGfm from "remark-gfm";
|
|
4
|
+
import { contentColumn } from "./entry_body.js";
|
|
5
|
+
const parser = unified().use(remarkParse).use(remarkGfm);
|
|
6
|
+
/** Find actual unordered list items, excluding code, HTML, and task lists. */
|
|
7
|
+
export function entryListItems(lines) {
|
|
8
|
+
const markers = [];
|
|
9
|
+
const visit = (node, container, enclosingList) => {
|
|
10
|
+
if (node.type === "list") {
|
|
11
|
+
for (const item of node.children) {
|
|
12
|
+
const outer = container ?? item;
|
|
13
|
+
const start = (item.position?.start.line ?? 1) - 1;
|
|
14
|
+
const column = (item.position?.start.column ?? 1) - 1;
|
|
15
|
+
const match = /^[-*+]([ \t]+)\[[^\]\s]+\](?:\s|$)/.exec((lines[start] ?? "").slice(column));
|
|
16
|
+
if (!node.ordered && item.checked == null && match &&
|
|
17
|
+
item.children[0]?.type === "paragraph") {
|
|
18
|
+
markers.push({
|
|
19
|
+
start,
|
|
20
|
+
end: item.position?.end.line ?? start + 1,
|
|
21
|
+
column,
|
|
22
|
+
whitespace: match[1],
|
|
23
|
+
container: {
|
|
24
|
+
start: (outer.position?.start.line ?? 1) - 1,
|
|
25
|
+
end: outer.position?.end.line ?? lines.length,
|
|
26
|
+
},
|
|
27
|
+
listContext: enclosingList ?? {
|
|
28
|
+
start: (node.position?.start.line ?? 1) - 1,
|
|
29
|
+
end: node.position?.end.line ?? lines.length,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
for (const child of item.children) {
|
|
34
|
+
visit(child, outer, enclosingList ?? {
|
|
35
|
+
start: (node.position?.start.line ?? 1) - 1,
|
|
36
|
+
end: node.position?.end.line ?? lines.length,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if ("children" in node) {
|
|
42
|
+
for (const [index, child] of node.children.entries()) {
|
|
43
|
+
let context = enclosingList;
|
|
44
|
+
if (!context && child.type === "list") {
|
|
45
|
+
// A marker change (for example `*` to `-`) splits adjacent
|
|
46
|
+
// items into separate mdast lists. Their indentation still
|
|
47
|
+
// affects admission of a tab rewrite across that boundary.
|
|
48
|
+
let first = index;
|
|
49
|
+
let last = index;
|
|
50
|
+
while (first > 0 && node.children[first - 1].type === "list")
|
|
51
|
+
first--;
|
|
52
|
+
while (node.children[last + 1]?.type === "list")
|
|
53
|
+
last++;
|
|
54
|
+
// Indented blocks after the list can move into an entry when its
|
|
55
|
+
// content column shrinks. Formatting them in isolation can remove
|
|
56
|
+
// that indentation and admit a refused rewrite on the next run.
|
|
57
|
+
// Keep complete blocks, including unindented lazy continuations.
|
|
58
|
+
const contentColumn = Math.min(...node.children.slice(first, last + 1).flatMap((sibling) => sibling.type === "list"
|
|
59
|
+
? sibling.children.map((item) => (item.position?.start.column ?? 1) + 1)
|
|
60
|
+
: []));
|
|
61
|
+
while ((node.children[last + 1]?.position?.start.column ?? 0) >=
|
|
62
|
+
contentColumn)
|
|
63
|
+
last++;
|
|
64
|
+
context = {
|
|
65
|
+
start: (node.children[first].position?.start.line ?? 1) - 1,
|
|
66
|
+
end: node.children[last].position?.end.line ?? lines.length,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
visit(child, container, context);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
visit(parser.parse(lines.join("\n")));
|
|
74
|
+
return markers;
|
|
75
|
+
}
|
|
76
|
+
/** Find entry list items with a tab in the whitespace after the marker. */
|
|
77
|
+
export function tabMarkers(lines) {
|
|
78
|
+
if (!lines.some((line) => /[-*+][ \t]*\t[ \t]*\[/.test(line)))
|
|
79
|
+
return [];
|
|
80
|
+
return entryListItems(lines).filter((marker) => marker.whitespace.includes("\t"));
|
|
81
|
+
}
|
|
82
|
+
/** Ranges kept out of every formatter pass after a tab rewrite is refused. */
|
|
83
|
+
export function protectedTabRanges(lines, preserveListContext = false) {
|
|
84
|
+
const markers = tabMarkers(lines);
|
|
85
|
+
const items = markers.length > 0 ? entryListItems(lines) : [];
|
|
86
|
+
const ranges = markers.map((marker) => {
|
|
87
|
+
// A prose rewrite of a neighbouring item can make a refused marker
|
|
88
|
+
// eligible on the next run. Keep the containing list and the following
|
|
89
|
+
// indented blocks stable, even when CommonMark puts them outside it.
|
|
90
|
+
const range = preserveListContext ? marker.listContext : marker;
|
|
91
|
+
let start = range.start;
|
|
92
|
+
if (!preserveListContext && marker.column > 0) {
|
|
93
|
+
for (let i = start - 1; i >= marker.container.start; i--) {
|
|
94
|
+
if (lines[i].trim() === "")
|
|
95
|
+
continue;
|
|
96
|
+
if (!lines[i].startsWith(" ".repeat(marker.column)))
|
|
97
|
+
break;
|
|
98
|
+
if (/^[-*+][ \t]/.test(lines[i].slice(marker.column)))
|
|
99
|
+
start = i;
|
|
100
|
+
else if (!lines[i].startsWith(" ".repeat(marker.column + 2)))
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
let end = range.end;
|
|
105
|
+
const nextEntry = items.find((item) => item.start > marker.start)?.start ??
|
|
106
|
+
lines.length;
|
|
107
|
+
const trailerIndent = " ".repeat(contentColumn(lines[marker.start], marker.column) + 4);
|
|
108
|
+
for (let i = end; i < nextEntry; i++) {
|
|
109
|
+
if (lines[i].trim() === "")
|
|
110
|
+
continue;
|
|
111
|
+
if (!lines[i].startsWith(" ".repeat(marker.column + 2)))
|
|
112
|
+
break;
|
|
113
|
+
// A less-indented trailer belongs to an enclosing space-marker entry.
|
|
114
|
+
if (/^[A-Z][A-Za-z-]*:(?:\s|$)/.test(lines[i].trim()) &&
|
|
115
|
+
!lines[i].startsWith(trailerIndent))
|
|
116
|
+
break;
|
|
117
|
+
end = i + 1;
|
|
118
|
+
}
|
|
119
|
+
while (end < lines.length && lines[end].trim() === "")
|
|
120
|
+
end++;
|
|
121
|
+
return { start, end };
|
|
122
|
+
});
|
|
123
|
+
const merged = [];
|
|
124
|
+
for (const range of ranges.sort((a, b) => a.start - b.start)) {
|
|
125
|
+
const previous = merged.at(-1);
|
|
126
|
+
if (previous && range.start <= previous.end) {
|
|
127
|
+
previous.end = Math.max(previous.end, range.end);
|
|
128
|
+
}
|
|
129
|
+
else
|
|
130
|
+
merged.push({ ...range });
|
|
131
|
+
}
|
|
132
|
+
return merged;
|
|
133
|
+
}
|
package/esm/gates/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/gates/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,mBAAmB,E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OAAO,CAAC,UAAU,EAAE,CAAC,CAuCvB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,OAAO,EAAE,gBAAgB,GAAG,SAAS,GACpC,OAAO,CAAC,UAAU,EAAE,CAAC,CAQvB"}
|
package/esm/gates/mod.js
CHANGED
|
@@ -68,7 +68,7 @@ export async function fmtDriftGate(mdContents, entries, ledger, formatMarkdownPr
|
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
const parsed = await parseFile(formatted.output, { file: filePath });
|
|
71
|
-
const refResult = canonicalizeRefs(formatted.output, parsed.entries, refIndex, ledger);
|
|
71
|
+
const refResult = canonicalizeRefs(formatted.output, parsed.entries, refIndex, ledger, formatted.preservedRanges);
|
|
72
72
|
if (refResult.changed) {
|
|
73
73
|
diagnostics.push({
|
|
74
74
|
code: "MSL-F011",
|
|
@@ -157,7 +157,7 @@ export async function resolveProjectDependencies(opts) {
|
|
|
157
157
|
continue;
|
|
158
158
|
}
|
|
159
159
|
// FIRST-LOCK or UPDATE.
|
|
160
|
-
const intent = ref.version
|
|
160
|
+
const intent = ref.version || "auto";
|
|
161
161
|
const outcome = await firstLockOrUpdate(ref, id, dir, intent, opts.io, opts.lockedAt);
|
|
162
162
|
if ("code" in outcome) {
|
|
163
163
|
diagnostics.push(outcome);
|
package/esm/mod.d.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* from core/mod.ts, never from internal paths.
|
|
9
9
|
*/
|
|
10
10
|
import "./_dnt.polyfills.js";
|
|
11
|
-
export declare const VERSION = "0.12.
|
|
11
|
+
export declare const VERSION = "0.12.1";
|
|
12
|
+
export { DISPLAY_ID_CHAR_RE, DISPLAY_ID_TOKEN_RE } from "./util/display_id.js";
|
|
12
13
|
export { ConfigError, CORE_DISCIPLINE_REGISTRY, CORE_KINDS, CORE_RELATIONS, CORE_SCHEMA_VERSION, DEFAULT_PROJECT_CONFIG, descendantsOf, emittableEntries, formatEntryOrigin, isCorpusEntry, isUpstreamEntry, KNOWN_LINK_KINDS, LOCK_EXTRA_INVERSE_KEYS, makeDisplayId, makeUlid, MIXED_DISCIPLINE, PALETTE_HUES, sameOriginSource, } from "./model/mod.js";
|
|
13
14
|
export type { Attribute, BodyToken, BodyTokenKind, Caption, CaptionConventions, CaptionPosition, ConfigFieldError, DeliveredDocument, Diagnostic, Directive, Discipline, DisciplineRegistry, DisplayId, EarsTrigger, EffectiveProfile, EffectiveTypeDef, EntityRefConvention, Entry, EntryOrigin, EntryShape, EntrySource, ExtractorRule, InlineRef, KindDecl, LabelConcern, LabelConcernKind, LabelValue, Link, LinkKind, LoadedProfile, ModalCase, PaletteHue, ProfileChain, ProfileConvention, ProjectConfig, ProjectRef, ProvenancedMap, ProvenancedMapEntry, ProvenancedValue, RelationDef, Severity, SourceLocation, Ulid, } from "./model/mod.js";
|
|
14
15
|
export { astEquivalent } from "./ast/equivalence.js";
|
package/esm/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,qBAAqB,CAAC;AAG7B,eAAO,MAAM,OAAO,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,qBAAqB,CAAC;AAG7B,eAAO,MAAM,OAAO,WAAW,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAG/E,OAAO,EACL,WAAW,EACX,wBAAwB,EACxB,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,QAAQ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BAAwB,EAAE,MAAM,oBAAoB,CAAC;AAG9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/esm/mod.js
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* from core/mod.ts, never from internal paths.
|
|
9
9
|
*/
|
|
10
10
|
import "./_dnt.polyfills.js";
|
|
11
|
-
export const VERSION = "0.12.
|
|
11
|
+
export const VERSION = "0.12.1";
|
|
12
|
+
export { DISPLAY_ID_CHAR_RE, DISPLAY_ID_TOKEN_RE } from "./util/display_id.js";
|
|
12
13
|
// Model types
|
|
13
14
|
export { ConfigError, CORE_DISCIPLINE_REGISTRY, CORE_KINDS, CORE_RELATIONS, CORE_SCHEMA_VERSION, DEFAULT_PROJECT_CONFIG, descendantsOf, emittableEntries, formatEntryOrigin, isCorpusEntry, isUpstreamEntry, KNOWN_LINK_KINDS, LOCK_EXTRA_INVERSE_KEYS, makeDisplayId, makeUlid, MIXED_DISCIPLINE, PALETTE_HUES, sameOriginSource, } from "./model/mod.js";
|
|
14
15
|
// AST (canonical body-AST — spec docs/specs/markspec-core-data-model.md §2)
|
package/esm/model/mod.d.ts
CHANGED
|
@@ -543,7 +543,7 @@ export type CaptionConventions = Readonly<Partial<Record<string, CaptionPosition
|
|
|
543
543
|
* `driftsys/schemas` `project/v1.json` `$defs/projectRef`). Used by the
|
|
544
544
|
* `dependencies:` (git repositories) and `references:` (published sites)
|
|
545
545
|
* lists. `version` carries intent: an exact tag is a frozen baseline, a
|
|
546
|
-
* branch name tracks its head, absent means auto (latest semver release
|
|
546
|
+
* branch name tracks its head, absent or empty means auto (latest semver release
|
|
547
547
|
* tag, else default-branch head). `name` is the upstream id used for the
|
|
548
548
|
* cache directory, lockfile rows, and origin badges; derived from the URL
|
|
549
549
|
* when absent.
|
package/esm/refs/mod.d.ts
CHANGED
|
@@ -34,9 +34,13 @@ export declare function buildRefIndex(entries: readonly Entry[]): RefIndex;
|
|
|
34
34
|
* Rewrite trace-attribute values in `content` per the canonicalise/heal rules.
|
|
35
35
|
* `entries` MUST be the parse of `content` (used to map each trailer line to its
|
|
36
36
|
* source entry's stable ULID). Returns the rewritten text and whether anything
|
|
37
|
-
* changed. Lossless: only resolvable value tokens are replaced.
|
|
37
|
+
* changed. Lossless: only resolvable value tokens are replaced. Optional
|
|
38
|
+
* `preservedRanges` exclude 0-based, end-exclusive line spans from rewriting.
|
|
38
39
|
*/
|
|
39
|
-
export declare function canonicalizeRefs(content: string, entries: readonly Entry[], index: RefIndex, ledger: readonly LockEdge[]
|
|
40
|
+
export declare function canonicalizeRefs(content: string, entries: readonly Entry[], index: RefIndex, ledger: readonly LockEdge[], preservedRanges?: readonly {
|
|
41
|
+
readonly start: number;
|
|
42
|
+
readonly end: number;
|
|
43
|
+
}[]): {
|
|
40
44
|
output: string;
|
|
41
45
|
changed: boolean;
|
|
42
46
|
};
|
package/esm/refs/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/refs/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAO7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAGnD,CAAC;AAEH,iFAAiF;AACjF,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtD,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,QAAQ,CAajE;AAcD
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/refs/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAO7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAGnD,CAAC;AAEH,iFAAiF;AACjF,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtD,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,KAAK,EAAE,GAAG,QAAQ,CAajE;AAcD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,SAAS,KAAK,EAAE,EACzB,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,SAAS,QAAQ,EAAE,EAC3B,eAAe,GAAE,SAAS;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACtE,GACH;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAwGtC"}
|
package/esm/refs/mod.js
CHANGED
|
@@ -55,9 +55,10 @@ const VALUE_TOKEN_RE = /[^\s,]+/g;
|
|
|
55
55
|
* Rewrite trace-attribute values in `content` per the canonicalise/heal rules.
|
|
56
56
|
* `entries` MUST be the parse of `content` (used to map each trailer line to its
|
|
57
57
|
* source entry's stable ULID). Returns the rewritten text and whether anything
|
|
58
|
-
* changed. Lossless: only resolvable value tokens are replaced.
|
|
58
|
+
* changed. Lossless: only resolvable value tokens are replaced. Optional
|
|
59
|
+
* `preservedRanges` exclude 0-based, end-exclusive line spans from rewriting.
|
|
59
60
|
*/
|
|
60
|
-
export function canonicalizeRefs(content, entries, index, ledger) {
|
|
61
|
+
export function canonicalizeRefs(content, entries, index, ledger, preservedRanges = []) {
|
|
61
62
|
const ledgerByKey = new Map();
|
|
62
63
|
for (const e of ledger) {
|
|
63
64
|
if (e.targetUlid === undefined)
|
|
@@ -87,7 +88,11 @@ export function canonicalizeRefs(content, entries, index, ledger) {
|
|
|
87
88
|
let changed = false;
|
|
88
89
|
// Share CommonMark fence boundaries with other prose passes. Compute them
|
|
89
90
|
// once so both the main loop and continuation loop remain linear (#705).
|
|
90
|
-
const fencedLines = fencedCodeLines(content);
|
|
91
|
+
const fencedLines = new Set(fencedCodeLines(content));
|
|
92
|
+
for (const range of preservedRanges) {
|
|
93
|
+
for (let i = range.start; i < range.end; i++)
|
|
94
|
+
fencedLines.add(i);
|
|
95
|
+
}
|
|
91
96
|
for (let i = 0; i < lines.length; i++) {
|
|
92
97
|
if (fencedLines.has(i))
|
|
93
98
|
continue;
|
package/esm/sync/mapping.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* cache TTL.
|
|
8
8
|
*
|
|
9
9
|
* Diagnostic family is `MSL-S###`:
|
|
10
|
-
* - MSL-S001 — malformed YAML / unsupported schema
|
|
10
|
+
* - MSL-S001 — malformed YAML / invalid structure / unsupported schema
|
|
11
11
|
* - MSL-S002 — locked + outbound contradiction
|
|
12
12
|
* - MSL-S003 — unknown conflict policy (newest-wins removed pre-1.0)
|
|
13
13
|
* - MSL-S004 — system ≠ identity.external-id-scheme
|
|
@@ -52,8 +52,9 @@ export interface ParseMappingResult {
|
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Parse and validate one mapping.yaml. Returns the model when valid, or
|
|
55
|
-
* an MSL-S### diagnostic when not.
|
|
56
|
-
*
|
|
55
|
+
* an MSL-S### diagnostic when not. Never throws on invalid YAML or invalid
|
|
56
|
+
* field shapes. Single-shot — stops at the first integrity failure to keep
|
|
57
|
+
* the repair signal clear.
|
|
57
58
|
*/
|
|
58
59
|
export declare function parseMapping(yaml: string, sourcePath: string): ParseMappingResult;
|
|
59
60
|
/**
|