prettier-plugin-mmd 0.9.0 → 0.9.2
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/lib/index.mjs +162 -111
- package/package.json +4 -4
package/lib/index.mjs
CHANGED
|
@@ -354,6 +354,42 @@ function isCommentLine(text, root, comment) {
|
|
|
354
354
|
return next !== void 0 && next !== "{" && next !== "\r" && next !== "\n";
|
|
355
355
|
}
|
|
356
356
|
/**
|
|
357
|
+
* The diagram types in which a `;` separates statements: a `;` that ends the
|
|
358
|
+
* text stands for no statement there, and the printer drops it unless it is
|
|
359
|
+
* kept for another reason (docs/flowchart.md, Semicolons). In every other type
|
|
360
|
+
* a `;` is text or a statement of its own.
|
|
361
|
+
*/
|
|
362
|
+
const diagramBodiesWithSeparatingSemicolons = /* @__PURE__ */ new Set([
|
|
363
|
+
"FlowchartDiagram",
|
|
364
|
+
"AgentflowDiagram",
|
|
365
|
+
"SequenceDiagram",
|
|
366
|
+
"QuadrantDiagram",
|
|
367
|
+
"XychartDiagram"
|
|
368
|
+
]);
|
|
369
|
+
/** Whether the physical line that starts at `offset` holds a `;`. */
|
|
370
|
+
function holdsSemicolonOnLine(text, offset) {
|
|
371
|
+
const lineEnd = text.indexOf("\n", offset);
|
|
372
|
+
return text.slice(offset, lineEnd === -1 ? text.length : lineEnd).includes(";");
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Where the text that the lexer reads ends: after the last character that is no
|
|
376
|
+
* whitespace and lies in none of the `regions` that mermaid.js removes, and, with
|
|
377
|
+
* `skipsSemicolons`, no `;`.
|
|
378
|
+
*/
|
|
379
|
+
function findReadEnd(text, regions, skipsSemicolons) {
|
|
380
|
+
let offset = text.length;
|
|
381
|
+
while (offset > 0) {
|
|
382
|
+
if (isWhitespace(text[offset - 1]) || skipsSemicolons && text[offset - 1] === ";") {
|
|
383
|
+
offset--;
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
const region = findCoveringRange(regions, offset - 1);
|
|
387
|
+
if (region === void 0) break;
|
|
388
|
+
offset = region[0];
|
|
389
|
+
}
|
|
390
|
+
return offset;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
357
393
|
* Finds the comment regions (see `JoiningRegion`), and those that join lines.
|
|
358
394
|
*
|
|
359
395
|
* The region of a comment starts at the earliest comment start from which
|
|
@@ -390,7 +426,6 @@ function findCommentRegions(text, root, directiveRanges) {
|
|
|
390
426
|
position = directiveEndByStart.get(position) ?? position + 1;
|
|
391
427
|
}
|
|
392
428
|
}
|
|
393
|
-
const contentEnd = text.trimEnd().length;
|
|
394
429
|
const all = [];
|
|
395
430
|
const joining = [];
|
|
396
431
|
let previousEnd = -1;
|
|
@@ -406,9 +441,15 @@ function findCommentRegions(text, root, directiveRanges) {
|
|
|
406
441
|
comment,
|
|
407
442
|
start,
|
|
408
443
|
end,
|
|
409
|
-
hasTextAfter:
|
|
444
|
+
hasTextAfter: false
|
|
410
445
|
});
|
|
411
446
|
}
|
|
447
|
+
const readEnd = findReadEnd(text, all, false);
|
|
448
|
+
const statementEnd = diagramBodiesWithSeparatingSemicolons.has(root.body.type) ? findReadEnd(text, all, true) : readEnd;
|
|
449
|
+
for (const [index, region] of joining.entries()) joining[index] = {
|
|
450
|
+
...region,
|
|
451
|
+
hasTextAfter: region.end < statementEnd || region.end < readEnd && holdsSemicolonOnLine(text, region.end)
|
|
452
|
+
};
|
|
412
453
|
for (let index = joining.length - 2; index >= 0; index--) {
|
|
413
454
|
const [region, next] = [joining[index], joining[index + 1]];
|
|
414
455
|
if (next.start === region.end) joining[index] = {
|
|
@@ -695,7 +736,6 @@ function semicolonRulesOf(source) {
|
|
|
695
736
|
const terminators = new Set(body.body.filter((item) => item.type === "RailroadRule").map((item) => item.range[1] - 1));
|
|
696
737
|
rules = {
|
|
697
738
|
kind: "required",
|
|
698
|
-
movedCommentSemicolons: /* @__PURE__ */ new Set(),
|
|
699
739
|
verbatimStyleLines: "word",
|
|
700
740
|
grammatical: /* @__PURE__ */ new Set([...terminators, ...source.root.comments.filter((comment) => comment.mark === ";").map((comment) => comment.range[0])])
|
|
701
741
|
};
|
|
@@ -711,35 +751,20 @@ function semicolonRulesOf(source) {
|
|
|
711
751
|
rules = {
|
|
712
752
|
kind: "text",
|
|
713
753
|
grammatical,
|
|
714
|
-
movedCommentSemicolons: /* @__PURE__ */ new Set(),
|
|
715
754
|
verbatimStyleLines: "semicolon"
|
|
716
755
|
};
|
|
717
756
|
break;
|
|
718
757
|
}
|
|
719
|
-
case "FlowchartDiagram":
|
|
720
|
-
case "AgentflowDiagram":
|
|
721
|
-
case "SequenceDiagram":
|
|
722
|
-
case "QuadrantDiagram":
|
|
723
|
-
case "XychartDiagram":
|
|
724
|
-
rules = {
|
|
725
|
-
kind: "separators",
|
|
726
|
-
grammatical: /* @__PURE__ */ new Set(),
|
|
727
|
-
movedCommentSemicolons: /* @__PURE__ */ new Set(),
|
|
728
|
-
verbatimStyleLines: false
|
|
729
|
-
};
|
|
730
|
-
break;
|
|
731
758
|
case "ErDiagram":
|
|
732
759
|
rules = {
|
|
733
760
|
kind: "text",
|
|
734
761
|
grammatical: /* @__PURE__ */ new Set(),
|
|
735
|
-
movedCommentSemicolons: findMovedCommentSemicolons(source, body.body),
|
|
736
762
|
verbatimStyleLines: false
|
|
737
763
|
};
|
|
738
764
|
break;
|
|
739
765
|
default: rules = {
|
|
740
|
-
kind: "text",
|
|
766
|
+
kind: diagramBodiesWithSeparatingSemicolons.has(body.type) ? "separators" : "text",
|
|
741
767
|
grammatical: /* @__PURE__ */ new Set(),
|
|
742
|
-
movedCommentSemicolons: /* @__PURE__ */ new Set(),
|
|
743
768
|
verbatimStyleLines: false
|
|
744
769
|
};
|
|
745
770
|
}
|
|
@@ -807,7 +832,7 @@ function visitOwnSemicolons(source, range, isLast, visit) {
|
|
|
807
832
|
}
|
|
808
833
|
/** Visits the `;` characters in a range. */
|
|
809
834
|
function visitSemicolonsIn(from, to) {
|
|
810
|
-
for (let offset = Math.max(from, range[0]); offset < Math.min(to, range[1]); offset++) if (text[offset] === ";" && !rules.grammatical.has(offset) && !
|
|
835
|
+
for (let offset = Math.max(from, range[0]); offset < Math.min(to, range[1]); offset++) if (text[offset] === ";" && !rules.grammatical.has(offset) && !isDroppedSemicolon(source, offset)) visit(offset);
|
|
811
836
|
}
|
|
812
837
|
for (const token of findTokensBetween(source, range[0], range[1])) if (token.value !== ";") visitSemicolonsIn(token.range[0], token.range[1]);
|
|
813
838
|
else if (!rules.grammatical.has(token.range[0]) && (rules.kind === "text" && !isDroppedSemicolon(source, token.range[0]) || source.ignoredSemicolons.has(token.range[0]) && (rules.kind === "required" || !isLast(token.range[0])))) visit(token.range[0]);
|
|
@@ -1267,20 +1292,16 @@ function findSeparatorBeforeTerminator(source, offset) {
|
|
|
1267
1292
|
* style, which runs from `start` to `end`, of an ER `classDef` or `style`
|
|
1268
1293
|
* statement that no `;` ends, or -1: nothing but U+2028, U+2029, spaces, tabs,
|
|
1269
1294
|
* vertical tabs, and form feeds stands between it and the line feed. mermaid.js
|
|
1270
|
-
* keeps the character in the text of the style and
|
|
1295
|
+
* keeps the character in the text of the style, and the figure is the same
|
|
1271
1296
|
* without it, so it is dropped where it ends the style. The line stays as
|
|
1272
|
-
* written where dropping the character could change what mermaid.js reads:
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1277
|
-
*
|
|
1278
|
-
*
|
|
1279
|
-
*
|
|
1280
|
-
* on a line of its own, and a directive that touches the character is read the
|
|
1281
|
-
* same without it. Other whitespace, such as a no-break space, is text of the
|
|
1282
|
-
* style, and so is a `;` that the style holds: the line rule may read it
|
|
1283
|
-
* (docs/er.md, Semicolons at the end of a style statement).
|
|
1297
|
+
* written where dropping the character could change what mermaid.js reads: the
|
|
1298
|
+
* style takes text after the line feed (a comment line with a statement after
|
|
1299
|
+
* it, or whitespace between the character and the line feed, joins the next
|
|
1300
|
+
* line to the style), and where a comment or a directive follows the character
|
|
1301
|
+
* on its line, since the SVG that mermaid.js draws holds the character there.
|
|
1302
|
+
* Other whitespace, such as a no-break space, is text of the style, and so is a
|
|
1303
|
+
* `;` that the style holds: the line rule may read it (docs/er.md, Semicolons
|
|
1304
|
+
* at the end of a style statement).
|
|
1284
1305
|
*/
|
|
1285
1306
|
function findSeparatorEndingStyle(source, start, end) {
|
|
1286
1307
|
if (source.text.slice(start, end).includes(";")) return -1;
|
|
@@ -1292,35 +1313,14 @@ function findSeparatorEndingStyle(source, start, end) {
|
|
|
1292
1313
|
}
|
|
1293
1314
|
/**
|
|
1294
1315
|
* Whether what stands from `end` to the end of the line at `lineEnd` leaves no
|
|
1295
|
-
* text of the style: whitespace
|
|
1296
|
-
*
|
|
1297
|
-
*
|
|
1298
|
-
*
|
|
1299
|
-
*
|
|
1316
|
+
* text of the style: whitespace only. A comment or a directive after the
|
|
1317
|
+
* character stays where it is written, with the character: mermaid.js keeps
|
|
1318
|
+
* the character in the text of the style, and the style attribute of the
|
|
1319
|
+
* figure holds it, which no whitespace of CSS is (docs/er.md, Semicolons at the
|
|
1320
|
+
* end of a style statement).
|
|
1300
1321
|
*/
|
|
1301
1322
|
function leavesNoTextOfTheStyleAfter(source, end, lineEnd) {
|
|
1302
|
-
|
|
1303
|
-
if (rest.trim() === "") return true;
|
|
1304
|
-
if (textRead(source, end, lineEnd).trim() !== "") return false;
|
|
1305
|
-
if (findTriviaBetween(source, end, lineEnd).some((item) => item.type === "Comment")) return [...rest].some(isLineSeparator);
|
|
1306
|
-
return findDirectiveTouchingSeparator(source, end, lineEnd) >= 0;
|
|
1307
|
-
}
|
|
1308
|
-
/**
|
|
1309
|
-
* The offset of the first directive of what stands from `end` to the end of
|
|
1310
|
-
* the line at `lineEnd`, where that is nothing but directives and the first
|
|
1311
|
-
* touches a U+2028 or U+2029 that ends the last style of an ER `classDef` or
|
|
1312
|
-
* `style` statement: nothing but U+2028 and U+2029 stands between `end` and
|
|
1313
|
-
* the directive, and one of them stands right before it. -1 where it is not.
|
|
1314
|
-
* The printer drops the characters and prints the directive right after the
|
|
1315
|
-
* style, as mermaid.js removes the directive before it reads the style
|
|
1316
|
-
* (docs/er.md, Semicolons at the end of a style statement).
|
|
1317
|
-
*/
|
|
1318
|
-
function findDirectiveTouchingSeparator(source, end, lineEnd) {
|
|
1319
|
-
if (textRead(source, end, lineEnd).trim() !== "") return -1;
|
|
1320
|
-
const items = findTriviaBetween(source, end, lineEnd);
|
|
1321
|
-
const first = items[0];
|
|
1322
|
-
if (first === void 0 || !items.every((item) => item.type === "Directive") || ![...source.text.slice(end, first.range[0])].every(isLineSeparator) || !isLineSeparator(source.text[first.range[0] - 1])) return -1;
|
|
1323
|
-
return first.range[0];
|
|
1323
|
+
return source.text.slice(end, lineEnd).trim() === "";
|
|
1324
1324
|
}
|
|
1325
1325
|
/**
|
|
1326
1326
|
* The `;` that ends the ER `classDef` or `style` statement that ends at
|
|
@@ -1333,30 +1333,6 @@ function findStyleTerminator(source, statementEnd) {
|
|
|
1333
1333
|
return source.ignoredSemicolons.has(statementEnd) ? statementEnd : -1;
|
|
1334
1334
|
}
|
|
1335
1335
|
/**
|
|
1336
|
-
* The offsets of the `;` in the comments that the printer moves to a line of
|
|
1337
|
-
* its own with the U+2028 or U+2029 that it drops from the end of an ER
|
|
1338
|
-
* `style` or `classDef` statement that no `;` ends (see
|
|
1339
|
-
* `findSeparatorEndingStyle`). mermaid.js removes such a comment as a comment
|
|
1340
|
-
* line, with its `;`, and it is read the same on a line of its own, so its `;`
|
|
1341
|
-
* is no `;` of the line on which it is written (docs/er.md, Semicolons at the
|
|
1342
|
-
* end of a style statement).
|
|
1343
|
-
*/
|
|
1344
|
-
function findMovedCommentSemicolons(source, statements) {
|
|
1345
|
-
const offsets = /* @__PURE__ */ new Set();
|
|
1346
|
-
for (const statement of statements) {
|
|
1347
|
-
if (statement.type === "ErSubgraphStatement") for (const offset of findMovedCommentSemicolons(source, statement.body)) offsets.add(offset);
|
|
1348
|
-
if (statement.type !== "ErStyleStatement" && statement.type !== "ErClassDefStatement") continue;
|
|
1349
|
-
const last = statement.styles.at(-1);
|
|
1350
|
-
if (last === void 0 || findStyleTerminator(source, statement.range[1]) >= 0 || findSeparatorEndingStyle(source, last.range[0], last.range[1]) < 0) continue;
|
|
1351
|
-
const lineEnd = lineEndOf(source, statement.range[1]);
|
|
1352
|
-
for (const comment of source.root.comments) {
|
|
1353
|
-
if (comment.range[0] < statement.range[1] || comment.range[0] >= lineEnd) continue;
|
|
1354
|
-
for (let offset = comment.range[0]; offset < comment.range[1]; offset++) if (source.text[offset] === ";") offsets.add(offset);
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
return offsets;
|
|
1358
|
-
}
|
|
1359
|
-
/**
|
|
1360
1336
|
* The first U+2028 or U+2029 of the run of U+2028, U+2029, spaces, tabs,
|
|
1361
1337
|
* vertical tabs, and form feeds that ends at `end`, or -1. The last style of
|
|
1362
1338
|
* an ER `classDef` or `style` statement whose `;` the printer drops ends in
|
|
@@ -4775,13 +4751,26 @@ function endsWithDirectives(source, [from, to]) {
|
|
|
4775
4751
|
* The layout of a line that stays as written, apart from the end of its text
|
|
4776
4752
|
* where directives end it: the whitespace after the last directive is left out,
|
|
4777
4753
|
* and each directive keeps whether whitespace precedes it, a run becoming one
|
|
4778
|
-
* space (see `collectTextEndEdits`). The runs inside the text stay.
|
|
4754
|
+
* space (see `collectTextEndEdits`). The runs inside the text stay. The end,
|
|
4755
|
+
* from the first whitespace that an edit replaces, is an atom of its own: an
|
|
4756
|
+
* atom that has a replacement is not formatted further, so the text before it,
|
|
4757
|
+
* which may hold a data block (see `formatDataBlocks`), stays in an atom that
|
|
4758
|
+
* has none (docs/kanban.md, Data blocks).
|
|
4779
4759
|
*/
|
|
4780
4760
|
function keptWithDirectiveEnd(source, start, end) {
|
|
4781
4761
|
const layout = keptAsWritten(start, end);
|
|
4782
4762
|
if (!endsWithDirectives(source, [start, end])) return layout;
|
|
4783
|
-
const
|
|
4784
|
-
|
|
4763
|
+
const edits = collectTextEndEdits(source, start, end, false);
|
|
4764
|
+
if (edits.length === 0) return layout;
|
|
4765
|
+
const endStart = minOf(edits.map((edit) => edit.range[0]));
|
|
4766
|
+
const atoms = [{
|
|
4767
|
+
start,
|
|
4768
|
+
end: endStart
|
|
4769
|
+
}, {
|
|
4770
|
+
start: endStart,
|
|
4771
|
+
end
|
|
4772
|
+
}];
|
|
4773
|
+
replaceInAtoms(source, atoms, edits);
|
|
4785
4774
|
return {
|
|
4786
4775
|
...layout,
|
|
4787
4776
|
atoms
|
|
@@ -5394,19 +5383,50 @@ function layoutErStatement(source, statement, end, preservesDescriptionColumns)
|
|
|
5394
5383
|
};
|
|
5395
5384
|
}
|
|
5396
5385
|
/**
|
|
5386
|
+
* Where the printed text of a `classDef` or `style` statement ends where a
|
|
5387
|
+
* U+2028 or U+2029 stands between the statement and a comment or a directive
|
|
5388
|
+
* on its line: right before that comment or directive. The characters stay
|
|
5389
|
+
* with the style, since mermaid.js keeps them in its text and the style
|
|
5390
|
+
* attribute of the figure holds them, which no whitespace of CSS is, so the
|
|
5391
|
+
* gap that holds them is printed as written with the statement (docs/er.md,
|
|
5392
|
+
* Semicolons at the end of a style statement).
|
|
5393
|
+
*/
|
|
5394
|
+
function endBeforeTriviaAfterSeparators(source, statement) {
|
|
5395
|
+
const from = statement.range[1];
|
|
5396
|
+
const first = findTriviaBetween(source, from, lineEndOf(source, from))[0];
|
|
5397
|
+
if (first === void 0) return from;
|
|
5398
|
+
const gap = [...source.text.slice(from, first.range[0])];
|
|
5399
|
+
return gap.every(isWhitespace) && gap.some(isLineSeparator) ? first.range[0] : from;
|
|
5400
|
+
}
|
|
5401
|
+
/**
|
|
5397
5402
|
* The stretches of a statement that are printed as written: the `;` that
|
|
5398
|
-
* ends a `classDef` or `style` statement, with what lies before it,
|
|
5399
|
-
*
|
|
5403
|
+
* ends a `classDef` or `style` statement, with what lies before it, the gap
|
|
5404
|
+
* between such a statement and the comment or the directive that a U+2028 or
|
|
5405
|
+
* U+2029 in it joins to its line, and the whitespace between the entity `only`
|
|
5406
|
+
* and a cardinality `one`.
|
|
5400
5407
|
*/
|
|
5401
5408
|
function findKeptStretches$1(source, statement) {
|
|
5402
5409
|
switch (statement.type) {
|
|
5403
5410
|
case "ErRelationshipStatement": return findOnlyOneStretches(source, statement);
|
|
5404
5411
|
case "ErClassDefStatement":
|
|
5405
|
-
case "ErStyleStatement": return findEndingSemicolonStretches(source, statement);
|
|
5412
|
+
case "ErStyleStatement": return [...findEndingSemicolonStretches(source, statement), ...findGapBeforeTriviaStretches(source, statement)];
|
|
5406
5413
|
default: return [];
|
|
5407
5414
|
}
|
|
5408
5415
|
}
|
|
5409
5416
|
/**
|
|
5417
|
+
* The gap after a `classDef` or `style` statement that holds a U+2028 or
|
|
5418
|
+
* U+2029 and ends at a comment or a directive of its line, as written (see
|
|
5419
|
+
* `endBeforeTriviaAfterSeparators`).
|
|
5420
|
+
*/
|
|
5421
|
+
function findGapBeforeTriviaStretches(source, statement) {
|
|
5422
|
+
const start = statement.range[1];
|
|
5423
|
+
const end = endBeforeTriviaAfterSeparators(source, statement);
|
|
5424
|
+
return end > start ? [{
|
|
5425
|
+
start,
|
|
5426
|
+
end
|
|
5427
|
+
}] : [];
|
|
5428
|
+
}
|
|
5429
|
+
/**
|
|
5410
5430
|
* The `;` that ends a `classDef` or `style` statement, after the last
|
|
5411
5431
|
* style, as written: it is in the range of the statement, and no token of
|
|
5412
5432
|
* the structure of the statement (docs/er.md, Styles and classes). The `;`
|
|
@@ -5689,6 +5709,31 @@ function hasNoValue(item) {
|
|
|
5689
5709
|
function startsPlainComment(source, offset) {
|
|
5690
5710
|
return source.text.startsWith("%%", offset) && !source.text.startsWith("%%{", offset);
|
|
5691
5711
|
}
|
|
5712
|
+
/**
|
|
5713
|
+
* The diagram type whose `title` the oldest version that counts reads with a
|
|
5714
|
+
* lexer built with jison, which takes a whitespace character that is no space
|
|
5715
|
+
* or tab before a `%%` as a part of the title, where the later versions trim
|
|
5716
|
+
* it (docs/pie.md, Title). That version rejects the `title` of a gitGraph
|
|
5717
|
+
* (docs/gitgraph.md, Title and common values).
|
|
5718
|
+
*/
|
|
5719
|
+
const diagramTypeWithJisonTitle = "pie";
|
|
5720
|
+
/**
|
|
5721
|
+
* Whether a whitespace character that is no space or tab stands between the
|
|
5722
|
+
* text of a value and the `%%` comment at `commentStart`, with or without
|
|
5723
|
+
* directives, which mermaid.js removes first, among the whitespace.
|
|
5724
|
+
*/
|
|
5725
|
+
function holdsOtherWhitespaceBeforeComment(source, valueStart, commentStart) {
|
|
5726
|
+
let position = commentStart;
|
|
5727
|
+
for (;;) {
|
|
5728
|
+
while (position > valueStart && isWhitespace(source.text[position - 1])) {
|
|
5729
|
+
if (!isSpaceOrTab(source.text[position - 1])) return true;
|
|
5730
|
+
position--;
|
|
5731
|
+
}
|
|
5732
|
+
const directive = findDirectiveEndingAt(source, position);
|
|
5733
|
+
if (directive === void 0 || directive.range[0] <= valueStart) return false;
|
|
5734
|
+
position = directive.range[0];
|
|
5735
|
+
}
|
|
5736
|
+
}
|
|
5692
5737
|
/** Whether the statement is an `accTitle:` line. */
|
|
5693
5738
|
function isAccTitle(statement) {
|
|
5694
5739
|
return statement.type.includes("AccTitle");
|
|
@@ -5725,16 +5770,21 @@ function layoutCommonLine(source, statement, isTitle) {
|
|
|
5725
5770
|
const delimiter = isTitle ? keyword : expectToken(findStructuralToken(source, keyword.range[1]), "the accessibility colon");
|
|
5726
5771
|
const value = statement.value;
|
|
5727
5772
|
const hasTrivia = value !== null && findTriviaBetween(source, ...value.range).length > 0;
|
|
5728
|
-
const
|
|
5729
|
-
const
|
|
5773
|
+
const diagramType = source.root.diagramType;
|
|
5774
|
+
const commentStart = value === null ? null : skipRemoved(source, value.range[1]);
|
|
5775
|
+
const commentFollows = commentStart !== null && startsPlainComment(source, commentStart);
|
|
5776
|
+
const accTitleReachesComment = commentFollows && isAccTitle(statement) && diagramTypesWithJisonAccessibilityLines.has(diagramType);
|
|
5777
|
+
const gapReachesComment = value !== null && commentStart !== null && commentFollows && !hasTrivia && !isAccTitle(statement) && (isTitle ? diagramType === diagramTypeWithJisonTitle : diagramTypesWithJisonAccessibilityLines.has(diagramType)) && holdsOtherWhitespaceBeforeComment(source, value.range[0], commentStart);
|
|
5778
|
+
const valueReachesComment = accTitleReachesComment || gapReachesComment;
|
|
5779
|
+
const endsInDirectives = hasTrivia && !valueReachesComment && (statement.textAfter?.length ?? 0) === 0 && endsWithDirectives(source, value.range);
|
|
5730
5780
|
let valueStart = value?.range[0] ?? delimiter.range[1];
|
|
5731
5781
|
let valueEnd = value?.range[1] ?? valueStart;
|
|
5732
5782
|
const valueTextEnd = trimmedTextEnd(source, valueStart, valueEnd, isWhitespace);
|
|
5733
|
-
const trimsEnd = !
|
|
5783
|
+
const trimsEnd = !valueReachesComment && (!hasTrivia || endsInDirectives);
|
|
5734
5784
|
if (trimsEnd) valueEnd = valueTextEnd.end;
|
|
5735
5785
|
if (!hasTrivia) {
|
|
5736
5786
|
while (valueStart < valueEnd && (source.text[valueStart].trim() === "" || source.ignoredSemicolons.has(valueStart))) valueStart++;
|
|
5737
|
-
if (!
|
|
5787
|
+
if (!valueReachesComment) while (valueStart < valueEnd && source.text[valueEnd - 1].trim() === "") valueEnd--;
|
|
5738
5788
|
} else if (endsInDirectives) while (valueStart < valueEnd && source.text[valueStart].trim() === "") valueStart++;
|
|
5739
5789
|
const holdsTrivia = hasTrivia && !endsInDirectives;
|
|
5740
5790
|
if (holdsTrivia) valueStart = delimiter.range[1];
|
|
@@ -15259,11 +15309,14 @@ function printSubgraph$1(path, options, print, source, statement, depth) {
|
|
|
15259
15309
|
* the line. The block consumes exactly what the closing prints, so a following
|
|
15260
15310
|
* written gap cannot print them again. `end` followed by a U+2028 is the
|
|
15261
15311
|
* keyword to the pinned lexer, and one name to a version that counts
|
|
15262
|
-
* (docs/er.md, Line separators).
|
|
15312
|
+
* (docs/er.md, Line separators). A `classDef` or `style` statement ends right
|
|
15313
|
+
* before the comment or the directive that follows it on its line, where the
|
|
15314
|
+
* gap between them holds a U+2028 or a U+2029 (see
|
|
15315
|
+
* `endBeforeTriviaAfterSeparators`).
|
|
15263
15316
|
*/
|
|
15264
15317
|
function printedErEnd(source, statement) {
|
|
15265
15318
|
const from = statement.range[1];
|
|
15266
|
-
if (statement.type === "ErStyleStatement" || statement.type === "ErClassDefStatement") return
|
|
15319
|
+
if (statement.type === "ErStyleStatement" || statement.type === "ErClassDefStatement") return endBeforeTriviaAfterSeparators(source, statement);
|
|
15267
15320
|
if (statement.type !== "ErSubgraphStatement") return from;
|
|
15268
15321
|
const lineEnd = lineEndOf(source, from);
|
|
15269
15322
|
let end = from;
|
|
@@ -15277,21 +15330,6 @@ function printedErEnd(source, statement) {
|
|
|
15277
15330
|
return end;
|
|
15278
15331
|
}
|
|
15279
15332
|
/**
|
|
15280
|
-
* Where the printed text of a `classDef` or `style` statement ends: after the
|
|
15281
|
-
* U+2028 and U+2029 that the printer drops between the last style and a
|
|
15282
|
-
* directive that touches them, which the tree leaves out of the statement
|
|
15283
|
-
* where comment lines follow the line. The block consumes them, so that the
|
|
15284
|
-
* directive is printed right after the style (docs/er.md, Semicolons at the
|
|
15285
|
-
* end of a style statement).
|
|
15286
|
-
*/
|
|
15287
|
-
function endOfSeparatorsBeforeDirective(source, statement) {
|
|
15288
|
-
const from = statement.range[1];
|
|
15289
|
-
const last = statement.styles.at(-1);
|
|
15290
|
-
if (last === void 0 || findDroppedSeparator(source, last, from) < 0) return from;
|
|
15291
|
-
const directive = findDirectiveTouchingSeparator(source, from, lineEndOf(source, from));
|
|
15292
|
-
return directive < 0 ? from : directive;
|
|
15293
|
-
}
|
|
15294
|
-
/**
|
|
15295
15333
|
* Prints an entity statement with its attribute block: the line of the
|
|
15296
15334
|
* entity with its `{`, the attributes one level deeper, one on each line, and
|
|
15297
15335
|
* the `}` (docs/er.md, Attribute blocks). An empty block over several lines,
|
|
@@ -19674,6 +19712,18 @@ function treeviewContentStart(source, item) {
|
|
|
19674
19712
|
return findStructuralToken(source, item.prefix?.range[1] ?? item.range[0]).range[0];
|
|
19675
19713
|
}
|
|
19676
19714
|
/**
|
|
19715
|
+
* Whether the text of a node that ends at `nodeEnd` holds a U+2028 or U+2029 in
|
|
19716
|
+
* the whitespace at its end, and a comment region or a directive follows that
|
|
19717
|
+
* whitespace on its line.
|
|
19718
|
+
*/
|
|
19719
|
+
function endsAtLineSeparatorBeforeTrivia(source, nodeEnd) {
|
|
19720
|
+
let start = nodeEnd;
|
|
19721
|
+
while (start > 0 && source.text[start - 1] !== "\n" && isWhitespace(source.text[start - 1])) start--;
|
|
19722
|
+
let end = nodeEnd;
|
|
19723
|
+
while (end < source.text.length && source.text[end] !== "\n" && isWhitespace(source.text[end])) end++;
|
|
19724
|
+
return [...source.text.slice(start, end)].some(isLineSeparator) && (source.joiningRegions.some((region) => start <= region.start && region.start <= end) || findTriviaBetween(source, end, end + 1).at(0)?.type === "Directive");
|
|
19725
|
+
}
|
|
19726
|
+
/**
|
|
19677
19727
|
* Decisions 3–5, redrawing 1–10 (docs/treeview.md, Branch prefixes): decide
|
|
19678
19728
|
* the whole body's safety once, then supply heads and omitted structure to
|
|
19679
19729
|
* the existing block/atom path. Never parse a candidate output at run time.
|
|
@@ -19766,6 +19816,7 @@ function planTreeviewBox(source, diagram, lines, headerEnd, protectedRows) {
|
|
|
19766
19816
|
const original = physicalLineAt(node.name.range[0]);
|
|
19767
19817
|
if (heads.get(node) === "" && original !== void 0 && original.offsets[0] < node.name.range[0] && node.prefix === null && isWhitespace(source.text[skipRemoved(source, node.name.range[0])] ?? "x")) reasons.add("splitting a logical line exposes leading value whitespace");
|
|
19768
19818
|
if (heads.get(node) === "" || original?.prefix !== null) continue;
|
|
19819
|
+
if (endsAtLineSeparatorBeforeTrivia(source, node.annotations.at(-1)?.range[1] ?? node.name.range[1])) reasons.add("adding a branch changes where a line separator ends the line");
|
|
19769
19820
|
if (original !== void 0 && values.some((value) => {
|
|
19770
19821
|
const from = Math.max(value.range[0], node.name.range[0]);
|
|
19771
19822
|
const to = Math.min(value.range[1], original.range[1]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-plugin-mmd",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "Prettier plugin for the Mermaid diagram syntax (.mmd files and mermaid code blocks in Markdown)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@mmd-toolkit/parser": "^0.4.
|
|
47
|
-
"marked": "18.2.
|
|
46
|
+
"@mmd-toolkit/parser": "^0.4.1",
|
|
47
|
+
"marked": "^18.2.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@mmd-toolkit/ast": "0.4.
|
|
50
|
+
"@mmd-toolkit/ast": "0.4.1",
|
|
51
51
|
"@mmd-toolkit/tests": "0.0.0",
|
|
52
52
|
"prettier": "^3.9.0"
|
|
53
53
|
},
|