feat(export/markdown): add support for todos

This commit is contained in:
Elian Doran 2025-04-16 22:29:31 +03:00
parent ea8b5131e1
commit 2edaa2c4d4
No known key found for this signature in database
3 changed files with 26 additions and 0 deletions

View File

@ -37,6 +37,7 @@
* Basic Touch Bar support for macOS.
* [Support Bearer Token](https://github.com/TriliumNext/Notes/issues/1701)
* The tab bar is now scrollable when there are many tabs by @SiriusXT
* Markdown export: support todo lists
## 🌍 Internationalization

View File

@ -321,4 +321,25 @@ describe("Markdown export", () => {
expect(markdownExportService.toMarkdown(html)).toBe(expected);
});
it("exports todo lists properly", () => {
const html = trimIndentation/*html*/`\
<ul class="todo-list">
<li>
<label class="todo-list__label">
<input type="checkbox" checked="checked" disabled="disabled"><span class="todo-list__label__description">Hello</span>
</label>
</li>
<li>
<label class="todo-list__label">
<input type="checkbox" disabled="disabled"><span class="todo-list__label__description">World</span>
</label>
</li>
</ul>
`;
const expected = trimIndentation`\
- [x] Hello
- [ ] World`;
expect(markdownExportService.toMarkdown(html)).toBe(expected);
});
});

View File

@ -230,7 +230,11 @@ function buildListItemFilter(): Rule {
var start = parent.getAttribute('start')
var index = Array.prototype.indexOf.call(parent.children, node)
prefix = (start ? Number(start) + index : index + 1) + '. '
} else if (parent.classList.contains("todo-list")) {
const isChecked = node.querySelector("input[type=checkbox]:checked");
prefix = (isChecked ? "- [x] " : "- [ ] ");
}
const result = prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '');
return result;
}