Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(import/anytype): convert quote/highlight blocks to blockquotes
Elian Doran9b0eccf6b00f
diff --git a/packages/trilium-core/src/services/import/anytype/importer.integration.spec.ts b/packages/trilium-core/src/services/import/anytype/importer.integration.spec.tsindex 80a7ea762d..cf40ea12fa 100644--- a/packages/trilium-core/src/services/import/anytype/importer.integration.spec.ts+++ b/packages/trilium-core/src/services/import/anytype/importer.integration.spec.ts@@ -332,6 +332,27 @@ describe("Anytype importer — integration", () => {);});+ it("imports a Quote (Highlight) block as a blockquote end-to-end", async () => {+ const page = JSON.stringify({+ sbType: "Page",+ snapshot: {+ data: {+ blocks: [+ { id: "q", childrenIds: ["header", "q1"] },+ { id: "header", childrenIds: ["title"] },+ { id: "title", text: { text: "", style: "Title" } },+ { id: "q1", text: { text: "Highlighted that looks like a blockquote.", style: "Quote" } }+ ],+ details: { id: "q", name: "Quote", resolvedLayout: 0 }+ }+ }+ });+ const importRoot = await importAnytype({ "objects/q.pb.json": page });++ const note = importRoot.getChildNotes().find((n) => n.title === "Quote");+ expect(decodeUtf8(note?.getContent() ?? "")).toBe("<blockquote><p>Highlighted that looks like a blockquote.</p></blockquote>");+ });+it("produces an empty root when the export has no pages", async () => {const importRoot = await importAnytype({"types/type1.pb.json": JSON.stringify({ sbType: "STType", snapshot: { data: { details: { id: "type1", name: "Article" } } } })diff --git a/packages/trilium-core/src/services/import/anytype/importer.spec.ts b/packages/trilium-core/src/services/import/anytype/importer.spec.tsindex bfde3bb028..d26db8d6ee 100644--- a/packages/trilium-core/src/services/import/anytype/importer.spec.ts+++ b/packages/trilium-core/src/services/import/anytype/importer.spec.ts@@ -62,9 +62,9 @@ describe("isPage", () => {});describe("parseObject", () => {- it("takes the title from details.name and flattens non-heading, non-list styles to paragraphs", () => {- // Quote/Callout/Toggle etc. are all flattened to <p> for now (headings and lists are handled).- const result = parseObject(page("My Page", [textBlock("b1", "First"), textBlock("b2", "Second", "Quote")]));+ it("takes the title from details.name and falls back to a paragraph for an unrecognised style", () => {+ // Paragraph and any style we don't specially handle render as a plain <p>.+ const result = parseObject(page("My Page", [textBlock("b1", "First"), textBlock("b2", "Second", "FutureStyle")]));expect(result.id).toBe("obj");expect(result.title).toBe("My Page");expect(result.content).toBe("<p>First</p><p>Second</p>");@@ -164,6 +164,24 @@ describe("lists", () => {});});+describe("quotes", () => {+ it("converts a Quote (Anytype's Highlight block) to a blockquote", () => {+ const doc = listDoc(["q1"], [{ id: "q1", text: { text: "A quote", style: "Quote", marks: { marks: [] } } }]);+ expect(parseObject(doc).content).toBe("<blockquote><p>A quote</p></blockquote>");+ });++ it("applies inline marks and renders child blocks inside the blockquote", () => {+ const doc = listDoc(+ ["q1"],+ [+ { id: "q1", text: { text: "Bold quote", style: "Quote", marks: { marks: [mark(0, 4, "Bold")] } }, childrenIds: ["q1a"] },+ { id: "q1a", text: { text: "More", style: "Paragraph", marks: { marks: [] } } }+ ]+ );+ expect(parseObject(doc).content).toBe("<blockquote><p><strong>Bold</strong> quote</p><p>More</p></blockquote>");+ });+});+describe("callouts", () => {it("converts a default-icon callout to a tip admonition (icon implied, dropped)", () => {const doc = listDoc(["c1"], [{ id: "c1", text: { text: "Heads up", style: "Callout", marks: { marks: [] }, iconEmoji: "" } }]);diff --git a/packages/trilium-core/src/services/import/anytype/importer.ts b/packages/trilium-core/src/services/import/anytype/importer.tsindex 330934fb1d..ad58535314 100644--- a/packages/trilium-core/src/services/import/anytype/importer.ts+++ b/packages/trilium-core/src/services/import/anytype/importer.ts@@ -7,8 +7,9 @@* headings, inline marks (bold/italic/strikethrough/underline/inline-code and text/background colours),* code blocks (with the language preserved as the Trilium MIME), bullet/numbered/task lists (grouped and* nested), toggles (normal toggles → collapsible blocks; toggle headings → plain headings), callouts- * (→ admonitions) and dividers (→ `<hr>`). Links, relations, types and collections are still deferred,- * and every page lands as a flat child of a fresh "Anytype import" root (no hierarchy yet).+ * (→ admonitions), quotes/highlights (→ `<blockquote>`) and dividers (→ `<hr>`). Links, relations, types+ * and collections are still deferred, and every page lands as a flat child of a fresh "Anytype import"+ * root (no hierarchy yet).** Invoked from the shared file-import dispatcher (routes/api/import.ts) when the upload is tagged* `format=anytype`, so progress, completion and failure are reported by that dispatcher's TaskContext —@@ -183,6 +184,12 @@ function extractContent(blocks: AnytypeBlock[], rootId: string): string {return `<details class="trilium-collapsible"><summary>${renderInlineText(rawText, marks)}</summary>${renderSequence(block.childrenIds ?? [])}</details>`;}+ if (style === "Quote") {+ // Anytype's Highlight block (internal style "Quote") → a blockquote; its background tint is dropped.+ const firstPara = rawText.trim() ? `<p>${renderInlineText(rawText, marks)}</p>` : "";+ return `<blockquote>${firstPara}${renderSequence(block.childrenIds ?? [])}</blockquote>`;+ }+if (style === "Callout") {// A callout becomes a Trilium admonition. Following the Notion importer: the default icon (no// custom emoji) maps to a "tip" with the icon dropped; any custom emoji maps to a "note" with