mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
feat(export/markdown): add support for todos
This commit is contained in:
parent
ea8b5131e1
commit
2edaa2c4d4
@ -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
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user