Skip to content

Commit d9e8091

Browse files
authored
Merge pull request #1128 from rscharfe/format-checkboxes
Format checkboxes
2 parents 820e13b + dca8bc6 commit d9e8091

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/markdown-renderer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export function md2text(markdown: string, columns = 76): string {
3636
.replace(/(^|\n)(\n)(?!$)/g, "$1>$2"); // quote empty
3737
}});
3838
},
39+
checkBoxFormatter: (elem, _walk, builder) => {
40+
const attribs = elem.attribs as { checked?: string };
41+
builder.addInline(attribs.checked === undefined ? "[ ]" : "[x]");
42+
},
3943
},
4044
selectors: [
4145
{
@@ -72,6 +76,10 @@ export function md2text(markdown: string, columns = 76): string {
7276
},
7377
format: "blockFormatter"
7478
},
79+
{
80+
selector: "input[type=checkbox]",
81+
format: "checkBoxFormatter"
82+
},
7583
],
7684
};
7785

tests/markdown-renderer.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,13 @@ const bq7 = `Over 56 levels still has 20 char (exact):
109109
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3 5 7 9 1 3 5 7 9 1
110110
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3 5 7`);
111111
});
112+
113+
test("task lists are rendered correctly", () => {
114+
const taskList = `This is a task list:
115+
* [x] done item
116+
* [ ] item still to do`;
117+
expect(md2text(taskList)).toEqual(`This is a task list:
118+
119+
* [x] done item
120+
* [ ] item still to do`);
121+
});

0 commit comments

Comments
 (0)