Skip to content

Build your personal knowledge base with Trilium Notes

fix(import): convert Notion to-do lists nested in other blocks

Elian Doran32b5d756f996
diff --git a/packages/trilium-core/src/services/import/notion/converter.spec.ts b/packages/trilium-core/src/services/import/notion/converter.spec.ts
index 73b5b0058b..d7c5bef6bd 100644
--- a/packages/trilium-core/src/services/import/notion/converter.spec.ts
+++ b/packages/trilium-core/src/services/import/notion/converter.spec.ts
@@ -55,6 +55,14 @@ describe("convertNotionHtml — to-do nesting and merging", () => {
const input = `${wrap(off("A"))}<p>Sep</p>${wrap(off("B"))}`;
expect(convertNotionHtml(input)).toBe(`${list(item("A"))}<p>Sep</p>${list(item("B"))}`);
});
+
+ it("converts to-do lists nested inside other blocks (e.g. a toggle's <details>)", () => {
+ const toggle = (summary: string, body: string) => `<ul class="toggle"><li><details open=""><summary>${summary}</summary>${body}</details></li></ul>`;
+ const input = toggle("The quick brownie", wrap(off("The quick brown", wrap(off("fox jumps")))));
+ expect(convertNotionHtml(input)).toBe(
+ `<details class="trilium-collapsible"><summary>The quick brownie</summary>${list(item("The quick brown", { nested: list(item("fox jumps")) }))}</details>`
+ );
+ });
});
describe("convertNotionHtml — display:contents wrappers", () => {
diff --git a/packages/trilium-core/src/services/import/notion/converter.ts b/packages/trilium-core/src/services/import/notion/converter.ts
index cd5b7a5b1f..b442eecd65 100644
--- a/packages/trilium-core/src/services/import/notion/converter.ts
+++ b/packages/trilium-core/src/services/import/notion/converter.ts
@@ -71,6 +71,16 @@ function convertTodoLists(container: HTMLElement) {
block.remove();
}
}
+
+ // To-do lists can also sit inside other blocks — a toggle's <details>, a callout, a list item, a
+ // table cell — which the run pass above (limited to `container`'s direct children) doesn't reach.
+ // Recurse into the remaining element children so those are converted in place too. The just-built
+ // `todo-list`s are visited harmlessly: they hold no `to-do-list` markup for the run pass to match.
+ for (const child of container.childNodes) {
+ if (child instanceof HTMLElement) {
+ convertTodoLists(child);
+ }
+ }
}
interface TodoBlock {