Skip to content

Commit adfdcb6

Browse files
SoroushRFclaude
andauthored
fix(web): copied task lists keep their nested items and code blocks (pingdotgg#14778)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent ddafde5 commit adfdcb6

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎apps/web/src/markdown-clipboard.test.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ describe("serializeRenderedMarkdownFragment", () => {
167167
parentChecked: false,
168168
childChecked: true,
169169
parent: "- [ ] Parent",
170-
child: " - [x] Child",
170+
child: " - [x] Child",
171171
},
172172
{
173173
parentChecked: true,
174174
childChecked: false,
175175
parent: "- [x] Parent",
176-
child: " - [ ] Child",
176+
child: " - [ ] Child",
177177
},
178178
])("copies $parent with $child", ({ parentChecked, childChecked, parent, child }) => {
179179
const parentContent = parentLayout === "loose" ? new FakeElement("P") : new FakeElement("LI");
@@ -206,6 +206,20 @@ describe("serializeRenderedMarkdownFragment", () => {
206206
});
207207
});
208208

209+
it("indents a code block under a numbered task item by the number width only", () => {
210+
const checkbox = new FakeElement("INPUT", [], { type: "checkbox" });
211+
checkbox.checked = true;
212+
const item = new FakeElement("LI").append(
213+
new FakeElement("P").append(checkbox, new FakeText(" Run the tests")),
214+
renderedCodeBlock(["pnpm test"]),
215+
);
216+
const container = new FakeElement("DIV").append(new FakeElement("OL").append(item));
217+
218+
expect(serializeRenderedMarkdownFragment(asNode(container))).toBe(
219+
"1. [x] Run the tests\n\n ```\n pnpm test\n ```",
220+
);
221+
});
222+
209223
it("copies the complete quote, source, and comment instead of the comment-only chip label", () => {
210224
const citation = {
211225
version: 1 as const,

‎apps/web/src/markdown-clipboard.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,17 @@ function serializeListItem(item: Element, ordered: boolean, index: number): stri
112112
':scope > input[type="checkbox"], :scope > p > input[type="checkbox"]',
113113
);
114114
const task = checkbox ? `[${(checkbox as HTMLInputElement).checked ? "x" : " "}] ` : "";
115-
const marker = ordered ? `${index}. ${task}` : `- ${task}`;
115+
const bullet = ordered ? `${index}. ` : "- ";
116+
const marker = `${bullet}${task}`;
116117
let content = serializeChildren(item)
117118
.replace(/\n{3,}/g, "\n\n")
118119
.trim();
119120
if (!item.querySelector(":scope > p")) {
120121
content = content.replace(/\n{2,}/g, "\n");
121122
}
122-
const continuationIndent = " ".repeat(marker.length);
123+
// Nested content lines up with the item text, which starts after the bullet;
124+
// a task box is part of that text, not of the list marker.
125+
const continuationIndent = " ".repeat(bullet.length);
123126
const [first = "", ...rest] = content.split("\n");
124127
return [
125128
`${marker}${first}`,

0 commit comments

Comments
 (0)