Skip to content

Build your personal knowledge base with Trilium Notes

feat(import/notion): import url, email and phone columns as url labels

Elian Doran9c07d989c58a
diff --git a/packages/trilium-core/src/services/import/notion/importer.integration.spec.ts b/packages/trilium-core/src/services/import/notion/importer.integration.spec.ts
index 95d0e2edca..4de110b22b 100644
--- a/packages/trilium-core/src/services/import/notion/importer.integration.spec.ts
+++ b/packages/trilium-core/src/services/import/notion/importer.integration.spec.ts
@@ -447,6 +447,36 @@ describe("Notion importer — integration", () => {
expect(row?.getOwnedLabelValue("Status_column")).toBe("Another in progress");
});
+ it("imports url, email and phone columns as url-typed labels (mailto:/tel: schemes)", async () => {
+ const dbId = "388c5eca1b8b8078a20fd18330d81306";
+ const rowId = "388c5eca1b8b80929a78da7c68154bd7";
+ // All three render as <a class="url-value">; email/phone hrefs are bare addresses.
+ const props =
+ `<table class="properties"><tbody>` +
+ `<tr class="property-row property-row-url"><th><span class="icon property-icon"><img src="x.svg"/></span>URL</th><td><a href="https://triliumnotes.org" class="url-value">https://triliumnotes.org</a></td></tr>` +
+ `<tr class="property-row property-row-email"><th><span class="icon property-icon"><img src="y.svg"/></span>Email</th><td><a href="[email protected]" class="url-value">[email protected]</a></td></tr>` +
+ `<tr class="property-row property-row-phone_number"><th><span class="icon property-icon"><img src="z.svg"/></span>Phone</th><td><a href="12345678" class="url-value">12345678</a></td></tr>` +
+ `</tbody></table>`;
+ const importRoot = await importNotion({
+ "DB 388c5eca1b8b8078a20fd18330d81306.html":
+ `<html><head><title>DB</title></head><body><div id="${dbId}"><div class="page-body"></div></div></body></html>`,
+ "DB/Row 388c5eca1b8b80929a78da7c68154bd7.html":
+ `<html><head><title>Row</title></head><body><div id="${rowId}">${props}<div class="page-body"><p>x</p></div></div></body></html>`
+ });
+
+ const db = importRoot.getChildNotes().find((n) => n.title === "DB");
+ // Each column gets a url-typed definition.
+ expect(db?.getOwnedLabel("label:URL")?.value).toBe("promoted,single,url,alias=URL");
+ expect(db?.getOwnedLabel("label:Email")?.value).toBe("promoted,single,url,alias=Email");
+ expect(db?.getOwnedLabel("label:Phone")?.value).toBe("promoted,single,url,alias=Phone");
+
+ const row = db?.getChildNotes().find((n) => n.title === "Row");
+ expect(row?.getOwnedLabelValue("URL")).toBe("https://triliumnotes.org");
+ // Email/phone are stored as clickable mailto:/tel: links.
+ expect(row?.getOwnedLabelValue("Email")).toBe("mailto:[email protected]");
+ expect(row?.getOwnedLabelValue("Phone")).toBe("tel:12345678");
+ });
+
it("neutralizes commas in a column name so the alias can't corrupt the definition", async () => {
const dbId = "388c5eca1b8b8078a20fd18330d81306";
const rowId = "388c5eca1b8b80929a78da7c68154bd7";
diff --git a/packages/trilium-core/src/services/import/notion/importer.ts b/packages/trilium-core/src/services/import/notion/importer.ts
index 0199e15255..a51e144aa1 100644
--- a/packages/trilium-core/src/services/import/notion/importer.ts
+++ b/packages/trilium-core/src/services/import/notion/importer.ts
@@ -483,7 +483,8 @@ export function firstChildNotionId(body: HTMLElement | null): string | undefined
* `<tr class="property-row property-row-<type>">` whose `<th>` holds the column name (after an icon span,
* which carries no text) and `<td>` the value. Handled so far:
* - `text` / `select` / `status`: the cell's text → one single-valued property;
- * - `multi_select`: each `<span class="selected-value">` option → one entry of a multi-valued property.
+ * - `multi_select`: each `<span class="selected-value">` option → one entry of a multi-valued property;
+ * - `url` / `email` / `phone_number`: the anchor's href → one single-valued url-typed property (email gets `mailto:`, phone `tel:`).
* The importer turns each `{ name, value }` into a Trilium label; blank names/values are skipped (Notion
* sometimes emits an empty cell, e.g. an unset multi-select, which should contribute no label). Other types
* (dates handled separately by extractDate) fall through untouched.
@@ -512,11 +513,29 @@ function extractProperties(root: HTMLElement): NotionProperty[] {
properties.push({ name, value, labelType: "text", multiplicity: "multi" });
}
}
+ } else if (type === "url" || type === "email" || type === "phone_number") {
+ // All three render as `<a class="url-value">`; the href is the canonical value. Email/phone hrefs
+ // are bare addresses, so give them a `mailto:`/`tel:` scheme to stay clickable as url labels.
+ const href = cell.querySelector("a")?.getAttribute("href")?.trim();
+ if (href) {
+ properties.push({ name, value: toUrlValue(type, href), labelType: "url", multiplicity: "single" });
+ }
}
}
return properties;
}
+/** Gives an email/phone href a clickable scheme (`mailto:`/`tel:`); a plain url href is returned as-is. */
+function toUrlValue(type: string, href: string): string {
+ if (type === "email") {
+ return href.startsWith("mailto:") ? href : `mailto:${href}`;
+ }
+ if (type === "phone_number") {
+ return href.startsWith("tel:") ? href : `tel:${href}`;
+ }
+ return href;
+}
+
/**
* Reads a Notion property-row timestamp (created/last-edited) from the page's properties table and
* converts it to Trilium's UTC DB format. Returns undefined when the row, the <time> element or the