Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 2edaa2c

Browse files
committed
feat(export/markdown): add support for todos
1 parent ea8b513 commit 2edaa2c

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

docs/Release Notes/Release Notes/v0.93.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
* Basic Touch Bar support for macOS.
3838
* [Support Bearer Token](https://github.com/TriliumNext/Notes/issues/1701)
3939
* The tab bar is now scrollable when there are many tabs by @SiriusXT
40+
* Markdown export: support todo lists
4041

4142
## 🌍 Internationalization
4243

src/services/export/markdown.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,25 @@ describe("Markdown export", () => {
321321
expect(markdownExportService.toMarkdown(html)).toBe(expected);
322322
});
323323

324+
it("exports todo lists properly", () => {
325+
const html = trimIndentation/*html*/`\
326+
<ul class="todo-list">
327+
<li>
328+
<label class="todo-list__label">
329+
<input type="checkbox" checked="checked" disabled="disabled"><span class="todo-list__label__description">Hello</span>
330+
</label>
331+
</li>
332+
<li>
333+
<label class="todo-list__label">
334+
<input type="checkbox" disabled="disabled"><span class="todo-list__label__description">World</span>
335+
</label>
336+
</li>
337+
</ul>
338+
`;
339+
const expected = trimIndentation`\
340+
- [x] Hello
341+
- [ ] World`;
342+
expect(markdownExportService.toMarkdown(html)).toBe(expected);
343+
});
344+
324345
});

src/services/export/markdown.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ function buildListItemFilter(): Rule {
230230
var start = parent.getAttribute('start')
231231
var index = Array.prototype.indexOf.call(parent.children, node)
232232
prefix = (start ? Number(start) + index : index + 1) + '. '
233+
} else if (parent.classList.contains("todo-list")) {
234+
const isChecked = node.querySelector("input[type=checkbox]:checked");
235+
prefix = (isChecked ? "- [x] " : "- [ ] ");
233236
}
237+
234238
const result = prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '');
235239
return result;
236240
}

0 commit comments

Comments
 (0)