Skip to content

Build your personal knowledge base with Trilium Notes

feat(export/markdown): add support for todos

Elian Doran2edaa2c4d4a1
diff --git a/docs/Release Notes/Release Notes/v0.93.0.md b/docs/Release Notes/Release Notes/v0.93.0.md
index 8015bd79e5..573e262aec 100644
--- a/docs/Release Notes/Release Notes/v0.93.0.md
+++ b/docs/Release Notes/Release Notes/v0.93.0.md
@@ -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
diff --git a/src/services/export/markdown.spec.ts b/src/services/export/markdown.spec.ts
index 37e9bd82a1..f4f9308d20 100644
--- a/src/services/export/markdown.spec.ts
+++ b/src/services/export/markdown.spec.ts
@@ -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);
+ });
+
});
diff --git a/src/services/export/markdown.ts b/src/services/export/markdown.ts
index 8f6e3fa009..840e8b198b 100644
--- a/src/services/export/markdown.ts
+++ b/src/services/export/markdown.ts
@@ -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;
}