Skip to content

Build your personal knowledge base with Trilium Notes

feat(import/anytype): convert dividers to <hr>

Elian Doranbf7097df3c17
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.ts
index cb5309b3a3..04d29ebacd 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
@@ -285,6 +285,28 @@ describe("Anytype importer — integration", () => {
expect(decodeUtf8(note?.getContent() ?? "")).toBe('<details class="trilium-collapsible"><summary>Toggle</summary><p>Inside</p></details>');
});
+ it("imports a divider as <hr> end-to-end", async () => {
+ const page = JSON.stringify({
+ sbType: "Page",
+ snapshot: {
+ data: {
+ blocks: [
+ { id: "div", childrenIds: ["header", "p1", "d1"] },
+ { id: "header", childrenIds: ["title"] },
+ { id: "title", text: { text: "", style: "Title" } },
+ { id: "p1", text: { text: "Above", style: "Paragraph" } },
+ { id: "d1", div: { style: "Dots" } }
+ ],
+ details: { id: "div", name: "Divider", resolvedLayout: 0 }
+ }
+ }
+ });
+ const importRoot = await importAnytype({ "objects/div.pb.json": page });
+
+ const note = importRoot.getChildNotes().find((n) => n.title === "Divider");
+ expect(decodeUtf8(note?.getContent() ?? "")).toBe("<p>Above</p><hr>");
+ });
+
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.ts
index 64d8c745ef..3c4301aa31 100644
--- a/packages/trilium-core/src/services/import/anytype/importer.spec.ts
+++ b/packages/trilium-core/src/services/import/anytype/importer.spec.ts
@@ -164,6 +164,21 @@ describe("lists", () => {
});
});
+describe("dividers", () => {
+ it("converts Line and Dots divider blocks to <hr>", () => {
+ const doc = listDoc(
+ ["p1", "d1", "d2", "p2"],
+ [
+ { id: "p1", text: { text: "Above", style: "Paragraph", marks: { marks: [] } } },
+ { id: "d1", div: { style: "Line" } },
+ { id: "d2", div: { style: "Dots" } },
+ { id: "p2", text: { text: "Below", style: "Paragraph", marks: { marks: [] } } }
+ ]
+ );
+ expect(parseObject(doc).content).toBe("<p>Above</p><hr><hr><p>Below</p>");
+ });
+});
+
describe("toggles", () => {
it("converts a Toggle to a collapsible block, nesting its children as the collapsed body", () => {
const doc = listDoc(
diff --git a/packages/trilium-core/src/services/import/anytype/importer.ts b/packages/trilium-core/src/services/import/anytype/importer.ts
index a299bec348..5c3678567a 100644
--- a/packages/trilium-core/src/services/import/anytype/importer.ts
+++ b/packages/trilium-core/src/services/import/anytype/importer.ts
@@ -6,9 +6,9 @@
* folders. This importer reads the *pages* (basic note-like objects) and converts each text block to HTML:
* 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) and toggles (normal toggles → collapsible blocks; toggle headings → plain headings). 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).
+ * nested), toggles (normal toggles → collapsible blocks; toggle headings → plain headings) 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 —
@@ -167,6 +167,11 @@ function extractContent(blocks: AnytypeBlock[], rootId: string): string {
}
function renderLeaf(block: AnytypeBlock): string {
+ // A divider block (Line or Dots) — both become a horizontal rule.
+ if (block.div) {
+ return "<hr>";
+ }
+
// Use the raw text (not trimmed) so mark offsets stay aligned; only the emptiness test trims.
const rawText = block.text?.text ?? "";
const style = block.text?.style;
@@ -456,6 +461,10 @@ export interface AnytypeBlock {
fields?: {
lang?: string;
};
+ /** A divider block (`style` is "Line" or "Dots"); both become a horizontal rule. */
+ div?: {
+ style?: string;
+ };
}
/** The object's `snapshot.data.details` — its metadata map. `layout` distinguishes a basic page (0) from