Tighten markdown list spacing

This commit is contained in:
Mohamed Boudra
2026-05-26 22:27:18 +07:00
parent 6d205f8853
commit 153fa42a95
3 changed files with 96 additions and 33 deletions
+47 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { getMarkdownListMarker } from "./markdown-list";
import { getMarkdownListMarker, getMarkdownListSpacing } from "./markdown-list";
describe("getMarkdownListMarker", () => {
it("returns a bullet marker for unordered list items", () => {
@@ -39,3 +39,49 @@ describe("getMarkdownListMarker", () => {
});
});
});
describe("getMarkdownListSpacing", () => {
it("keeps top-level list spacing as a section boundary", () => {
const paragraph = { type: "paragraph" };
const list = { type: "bullet_list" };
const body = { type: "body", children: [list, paragraph] };
expect(getMarkdownListSpacing(list, [body])).toEqual({
marginTop: 4,
marginBottom: 16,
});
});
it("does not add bottom spacing after a list at the end of a markdown block", () => {
const list = { type: "bullet_list" };
const body = { type: "body", children: [list] };
expect(getMarkdownListSpacing(list, [body])).toEqual({
marginTop: 4,
marginBottom: 0,
});
});
it("uses a smaller gap between adjacent top-level lists", () => {
const list = { type: "bullet_list" };
const body = { type: "body", children: [list, { type: "ordered_list" }] };
expect(getMarkdownListSpacing(list, [body])).toEqual({
marginTop: 4,
marginBottom: 8,
});
});
it("does not add section spacing after a nested list", () => {
expect(
getMarkdownListSpacing({ type: "bullet_list" }, [
{ type: "list_item" },
{ type: "bullet_list" },
{ type: "body" },
]),
).toEqual({
marginTop: 4,
marginBottom: 0,
});
});
});