fix(tui): separate list items with blank lines in loose lists
This commit is contained in:
@@ -572,6 +572,7 @@ export class Markdown implements Component {
|
|||||||
|
|
||||||
for (let i = 0; i < token.items.length; i++) {
|
for (let i = 0; i < token.items.length; i++) {
|
||||||
const item = token.items[i];
|
const item = token.items[i];
|
||||||
|
const isLastItem = i === token.items.length - 1;
|
||||||
const bullet = token.ordered
|
const bullet = token.ordered
|
||||||
? this.options.preserveOrderedListMarkers
|
? this.options.preserveOrderedListMarkers
|
||||||
? (this.getOrderedListMarker(item) ?? `${startNumber + i}. `)
|
? (this.getOrderedListMarker(item) ?? `${startNumber + i}. `)
|
||||||
@@ -604,6 +605,10 @@ export class Markdown implements Component {
|
|||||||
if (!renderedAnyLine) {
|
if (!renderedAnyLine) {
|
||||||
lines.push(firstPrefix);
|
lines.push(firstPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (token.loose && !isLastItem) {
|
||||||
|
lines.push("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
|
|||||||
@@ -149,6 +149,37 @@ describe("Markdown component", () => {
|
|||||||
assert.ok(plainLines.some((line) => line.includes("2. Second ordered")));
|
assert.ok(plainLines.some((line) => line.includes("2. Second ordered")));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should render blank lines between loose list items", () => {
|
||||||
|
const markdown = new Markdown(
|
||||||
|
`1. Lorem ipsum dolor sit amet.
|
||||||
|
|
||||||
|
Ut enim ad minim veniam.
|
||||||
|
|
||||||
|
2. Duis aute irure dolor.
|
||||||
|
|
||||||
|
Excepteur sint occaecat cupidatat.
|
||||||
|
|
||||||
|
3. Beep boop`,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
defaultMarkdownTheme,
|
||||||
|
);
|
||||||
|
|
||||||
|
const lines = markdown.render(80).map((line) => stripAnsi(line).trimEnd());
|
||||||
|
|
||||||
|
assert.deepStrictEqual(lines, [
|
||||||
|
"1. Lorem ipsum dolor sit amet.",
|
||||||
|
"",
|
||||||
|
" Ut enim ad minim veniam.",
|
||||||
|
"",
|
||||||
|
"2. Duis aute irure dolor.",
|
||||||
|
"",
|
||||||
|
" Excepteur sint occaecat cupidatat.",
|
||||||
|
"",
|
||||||
|
"3. Beep boop",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it("should render task list markers", () => {
|
it("should render task list markers", () => {
|
||||||
const markdown = new Markdown("- [ ] beep\n- [x] boop", 0, 0, defaultMarkdownTheme);
|
const markdown = new Markdown("- [ ] beep\n- [x] boop", 0, 0, defaultMarkdownTheme);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user