Skip to content

Build your personal knowledge base with Trilium Notes

feat(onenote): import note tags as inline icons rather than emoji

Elian Doran4562b48d2b89
diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications/Microsoft OneNote.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications/Microsoft OneNote.html
index c89814aa5f..5f5fbbaddd 100644
--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications/Microsoft OneNote.html
+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications/Microsoft OneNote.html
@@ -66,9 +66,10 @@
the text of the link matches the name of the page, or plain links otherwise.
If the pages are not part of the import, the original <code>onenote:</code> link
is kept.</li>
- <li>Tags (apart from to-do lists) are mildly preserved by converting them
- to emojis. This loses their searchability. Since Trilium has no concept
- of inline attributes or badges, this is considered a middle-ground.</li>
+ <li>Tags (apart from to-do lists) are preserved by converting them to inline
+ icons, which are searchable by the icon&apos;s name and can be recoloured like
+ any other icon. The Project A/B and numbered priority tags keep an emoji
+ instead, as the icon pack has no letters or numerals.</li>
</ul>
<p>Regarding the note structure:</p>
<ul>
diff --git a/apps/server/src/services/import/onenote/converter.spec.ts b/apps/server/src/services/import/onenote/converter.spec.ts
index cf20a68625..d95eeb4be6 100644
--- a/apps/server/src/services/import/onenote/converter.spec.ts
+++ b/apps/server/src/services/import/onenote/converter.spec.ts
@@ -141,8 +141,8 @@ const TAGS_SAMPLE = `<html lang="en-US">
</html>`;
// Real OneNote source (web-OneNote Graph export): the decorative (non-checkbox) note tags. Each is a
-// paragraph carrying a `data-tag` that OneNote renders as an icon — we render it as an emoji prefix.
-const EMOJI_TAGS_SAMPLE = `<html lang="en-US">
+// paragraph carrying a `data-tag` that OneNote renders as an icon — we render it as an icon prefix.
+const DECORATIVE_TAGS_SAMPLE = `<html lang="en-US">
<body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
<div style="position:absolute;left:48px;top:115px;width:624px">
<p data-tag="important" style="margin-top:0pt;margin-bottom:0pt">Important</p>
@@ -154,6 +154,17 @@ const EMOJI_TAGS_SAMPLE = `<html lang="en-US">
</body>
</html>`;
+// Constructed from the same shapes: the Project A/B tags, whose glyph is a character Boxicons has no
+// icon for.
+const CHARACTER_TAGS_SAMPLE = `<html lang="en-US">
+ <body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
+ <div style="position:absolute;left:48px;top:115px;width:624px">
+ <p data-tag="project-a" style="margin-top:0pt;margin-bottom:0pt">First project</p>
+ <p data-tag="project-b" style="margin-top:0pt;margin-bottom:0pt">Second project</p>
+ </div>
+ </body>
+</html>`;
+
// Real OneNote source (web-OneNote Graph export): checkbox note tags other than plain to-do
// (priorities, discussions, meetings, client requests). All render as task-list items, and the
// `:completed` status checks the box.
@@ -529,42 +540,55 @@ describe("convertPageHtml", () => {
expect(root.querySelectorAll(`input[type="checkbox"]`)).toHaveLength(4);
// Only the schedule-meeting:completed item is checked.
expect(root.querySelectorAll("input[checked]")).toHaveLength(1);
- // Each meaningful checkbox tag keeps an inner emoji alongside the checkbox.
+ // Each meaningful checkbox tag keeps an inner glyph alongside the checkbox — an icon, or the
+ // emoji for the priorities, whose glyph is a numeral.
expect(out).toContain("1️⃣ Priority 1");
- expect(out).toContain("📅 Schedule meeting");
- expect(out).toContain("🗣️ Discuss with Manager");
- expect(out).toContain("📋 Client Request");
+ expect(out).toContain(`${icon("bx-calendar")} Schedule meeting`);
+ expect(out).toContain(`${icon("bx-conversation")} Discuss with Manager`);
+ expect(out).toContain(`${icon("bx-clipboard")} Client Request`);
// The raw data-tag attribute is consumed, not left on the output.
expect(out).not.toContain("data-tag");
});
- it("renders decorative tags as an emoji prefix, leaving the paragraph in place", () => {
- const out = converter.convertPageHtml(EMOJI_TAGS_SAMPLE);
+ it("renders decorative tags as an icon prefix, leaving the paragraph in place", () => {
+ const out = converter.convertPageHtml(DECORATIVE_TAGS_SAMPLE);
const root = parse(out);
// No checkbox tags here, so nothing becomes a task list.
expect(root.querySelectorAll("ul.todo-list")).toHaveLength(0);
expect(root.querySelectorAll("p")).toHaveLength(5);
- expect(out).toContain("⭐ Important");
- expect(out).toContain("❓ Question");
- expect(out).toContain("💡 Idea");
- expect(out).toContain("🔑 Password");
- expect(out).toContain("📞 Phone number");
+ expect(out).toContain(`${icon("bx-star")} Important`);
+ expect(out).toContain(`${icon("bx-help-circle")} Question`);
+ expect(out).toContain(`${icon("bx-bulb")} Idea`);
+ expect(out).toContain(`${icon("bx-key")} Password`);
+ expect(out).toContain(`${icon("bx-phone")} Phone number`);
expect(out).not.toContain("data-tag");
+
+ // The sanitizer keeps the empty span and its classes, which is the whole of an icon.
+ expect(root.querySelectorAll("span.tn-icon")).toHaveLength(5);
+ });
+
+ it("keeps an emoji for the tags whose glyph is a character", () => {
+ const out = converter.convertPageHtml(CHARACTER_TAGS_SAMPLE);
+
+ // Boxicons has no alphabet, so Project A/B stay the boxed letters OneNote draws.
+ expect(out).toContain("🅰️ First project");
+ expect(out).toContain("🅱️ Second project");
+ expect(out).not.toContain("tn-icon");
});
it("supports multiple comma-separated tags on one paragraph", () => {
const out = converter.convertPageHtml(MULTI_TAGS_SAMPLE);
const root = parse(out);
- // The checkbox tag turns its paragraph into a task item, prefixed with the decorative emoji.
+ // The checkbox tag turns its paragraph into a task item, prefixed with the decorative icons.
expect(root.querySelectorAll("ul.todo-list")).toHaveLength(1);
expect(root.querySelectorAll(`input[type="checkbox"]`)).toHaveLength(1);
expect(root.querySelectorAll("input[checked]")).toHaveLength(0);
- expect(out).toContain("⭐❓ Todo plus star plus question");
+ expect(out).toContain(`${icon("bx-star")}${icon("bx-help-circle")} Todo plus star plus question`);
- // The decorative-only paragraph stays a <p>, prefixed with both emoji.
- expect(out).toContain("🎬📚 Movie and book");
+ // The decorative-only paragraph stays a <p>, prefixed with both icons.
+ expect(out).toContain(`${icon("bx-movie")}${icon("bx-book")} Movie and book`);
});
it("normalizes OneNote resource references so the importer can rewrite them", () => {
@@ -890,3 +914,8 @@ describe("extractPageCreatedDate", () => {
expect(converter.extractPageCreatedDate(`<html><head><meta name="created" /></head><body></body></html>`)).toBeUndefined();
});
});
+
+/** One note tag's icon, in the markup a text note stores icons as. */
+function icon(name: string) {
+ return `<span class="tn-icon bx ${name}"></span>`;
+}
diff --git a/apps/server/src/services/import/onenote/converter.ts b/apps/server/src/services/import/onenote/converter.ts
index cbad52df11..187400a37a 100644
--- a/apps/server/src/services/import/onenote/converter.ts
+++ b/apps/server/src/services/import/onenote/converter.ts
@@ -43,7 +43,7 @@ const LIST_STYLE_MAP = new Map<string, string>([["lower-alpha", "lower-latin"],
* OneNote's checkbox-style note tags — the ones it renders with a tick box and that carry a
* `:completed` status (see https://learn.microsoft.com/en-us/graph/onenote-note-tags). Each becomes a
* CKEditor task-list item, checked when its status is `completed`. The ones that mean more than a bare
- * to-do (priorities, discussions, meetings, requests) also keep an inner emoji from TAG_EMOJI.
+ * to-do (priorities, discussions, meetings, requests) also keep an inner glyph from {@link tagGlyph}.
*/
const CHECKBOX_TAGS = new Set<string>([
"to-do",
@@ -58,41 +58,49 @@ const CHECKBOX_TAGS = new Set<string>([
]);
/**
- * OneNote's note tags mapped to a representative emoji, keyed on the tag *shape* (the part before any
- * `:status`). Decorative tags render as the emoji alone; checkbox tags (CHECKBOX_TAGS) render as a task
- * item with the emoji prefixed inside it — except plain `to-do`, which is a bare checkbox with no
- * emoji. A shape not listed here (e.g. a user's custom tag) simply renders with no prefix.
+ * OneNote's note tags mapped to a Boxicons name, keyed on the tag *shape* (the part before any
+ * `:status`). Every name here is in `icon_pack_boxicons-v2.json`, the one icon pack Trilium builds
+ * in — a class from an installable pack would draw nothing on a fresh install.
+ */
+const TAG_ICON = new Map<string, string>([
+ ["important", "bx-star"],
+ ["critical", "bx-error-circle"],
+ ["question", "bx-help-circle"],
+ ["highlight", "bx-highlight"],
+ // Graph returns a Definition tag as `remember-for-later`, so this shape never reaches us.
+ ["definition", "bx-book-open"],
+ ["remember-for-later", "bx-pin"],
+ ["remember-for-blog", "bx-edit"],
+ ["idea", "bx-bulb"],
+ ["password", "bx-key"],
+ ["contact", "bx-user"],
+ ["address", "bx-home"],
+ ["phone-number", "bx-phone"],
+ ["web-site-to-visit", "bx-globe"],
+ ["source-for-article", "bx-news"],
+ ["send-in-email", "bx-envelope"],
+ ["movie-to-see", "bx-movie"],
+ ["book-to-read", "bx-book"],
+ ["music-to-listen-to", "bx-music"],
+ // Checkbox tags that carry meaning beyond a bare to-do; `to-do` itself stays glyph-less.
+ ["discuss-with-person-a", "bx-message-rounded"],
+ ["discuss-with-person-b", "bx-message-rounded"],
+ ["discuss-with-manager", "bx-conversation"],
+ ["schedule-meeting", "bx-calendar"],
+ ["call-back", "bx-phone-call"],
+ ["client-request", "bx-clipboard"]
+]);
+
+/**
+ * The tags whose glyph is a character rather than a picture. Boxicons carries no alphabet and no
+ * numerals, so an icon could not tell A from B, and these keep the boxed-character emoji OneNote
+ * itself draws. The cost is that they are not findable by name the way an icon is.
*/
const TAG_EMOJI = new Map<string, string>([
- ["important", "⭐"],
- ["critical", "❗"],
- ["question", "❓"],
- ["highlight", "🖍️"],
- ["definition", "📖"],
- ["remember-for-later", "📌"],
- ["remember-for-blog", "✍️"],
- ["idea", "💡"],
- ["password", "🔑"],
- ["contact", "👤"],
- ["address", "🏠"],
- ["phone-number", "📞"],
- ["web-site-to-visit", "🌐"],
- ["source-for-article", "📰"],
- ["send-in-email", "📧"],
- ["movie-to-see", "🎬"],
- ["book-to-read", "📚"],
- ["music-to-listen-to", "🎵"],
["project-a", "🅰️"],
["project-b", "🅱️"],
- // Checkbox tags that carry meaning beyond a bare to-do; `to-do` itself stays emoji-less.
["to-do-priority-1", "1️⃣"],
- ["to-do-priority-2", "2️⃣"],
- ["discuss-with-person-a", "💬"],
- ["discuss-with-person-b", "💬"],
- ["discuss-with-manager", "🗣️"],
- ["schedule-meeting", "📅"],
- ["call-back", "📲"],
- ["client-request", "📋"]
+ ["to-do-priority-2", "2️⃣"]
]);
/** OneNote's highlight/font palette uses the 16 basic CSS color names; map them to hex (see below). */
@@ -268,16 +276,17 @@ function takeTrailingCaption(img: HTMLElement): string | null {
*
* Checkbox-style tags (CHECKBOX_TAGS — `to-do` and its priority/discussion/meeting siblings) become a
* CKEditor task list, checked when their status is `completed`; runs of consecutive ones collapse into
- * one list, matching the structure Trilium's TodoList plugin produces. The emoji prefix (TAG_EMOJI) is
- * orthogonal: it applies to decorative tags and to the meaningful checkbox tags alike, so e.g. a
- * `discuss-with-manager` paragraph becomes a task item reading "🗣️ …" while bare `to-do` stays a plain
- * checkbox. A paragraph can carry several comma-separated tags (e.g. `to-do,important`), in which case
- * its emojis stack and a single checkbox tag still turns it into a task item.
+ * one list, matching the structure Trilium's TodoList plugin produces. The glyph prefix ({@link
+ * tagGlyph}) is orthogonal: it applies to decorative tags and to the meaningful checkbox tags alike,
+ * so e.g. a `discuss-with-manager` paragraph becomes a task item led by a `bx-conversation` icon while
+ * bare `to-do` stays a plain checkbox. A paragraph can carry several comma-separated tags (e.g.
+ * `to-do,important`), in which case its glyphs stack and a single checkbox tag still turns it into a
+ * task item.
*/
function convertTags(scope: HTMLElement) {
const tagged = scope.querySelectorAll("p[data-tag]");
- // Prefix each tagged paragraph's emoji in place, and record whether it is a checkbox paragraph
+ // Prefix each tagged paragraph's glyph in place, and record whether it is a checkbox paragraph
// (and if so, whether it's completed) so adjacent ones can be grouped.
const completedByCheckbox = new Map<HTMLElement, boolean>();
for (const p of tagged) {
@@ -287,9 +296,9 @@ function convertTags(scope: HTMLElement) {
});
p.removeAttribute("data-tag");
- const emojis = tags.map((tag) => TAG_EMOJI.get(tag.shape)).filter((emoji): emoji is string => Boolean(emoji));
- if (emojis.length > 0) {
- p.set_content(`${emojis.join("")} ${p.innerHTML}`);
+ const glyphs = tags.map((tag) => tagGlyph(tag.shape)).filter((glyph): glyph is string => Boolean(glyph));
+ if (glyphs.length > 0) {
+ p.set_content(`${glyphs.join("")} ${p.innerHTML}`);
}
const checkbox = tags.find((tag) => CHECKBOX_TAGS.has(tag.shape));
@@ -322,6 +331,17 @@ function convertTags(scope: HTMLElement) {
}
}
+/**
+ * What one tag shape is drawn as: an inline icon in the form the text editor and the share theme
+ * both read, or the emoji from {@link TAG_EMOJI}. Returns undefined for plain `to-do`, which is a
+ * bare tick box, and for a shape neither map lists.
+ */
+function tagGlyph(shape: string) {
+ const icon = TAG_ICON.get(shape);
+
+ return icon ? `<span class="tn-icon bx ${icon}"></span>` : TAG_EMOJI.get(shape);
+}
+
/**
* OneNote carries bold/italic/underline/strikethrough as inline styles (`font-weight:bold`,
* `font-style:italic`, `text-decoration:underline`/`line-through`), which the sanitizer strips. Wrap
diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications/Microsoft OneNote.md b/docs/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications/Microsoft OneNote.md
index ab6e767cce..d9e8d401c9 100644
--- a/docs/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications/Microsoft OneNote.md
+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Import & Export/Importing data from other applications/Microsoft OneNote.md
@@ -29,7 +29,7 @@ The following features are preserved by Trilium during the import process:
* Hand-drawing is preserved and displayed as an SVG image inside the note
* OneNote's default color (black) is special since it also renders as white for dark themes. Since v0.104.1, this is also supported by using a special SVG tweak which reacts to light/dark themes.
* Links between other imported pages are converted to <a class="reference-link" href="../../../Note%20Types/Text/Links/Internal%20(reference)%20links.md">Internal (reference) links</a> if the text of the link matches the name of the page, or plain links otherwise. If the pages are not part of the import, the original `onenote:` link is kept.
-* Tags (apart from to-do lists) are mildly preserved by converting them to emojis. This loses their searchability. Since Trilium has no concept of inline attributes or badges, this is considered a middle-ground.
+* Tags (apart from to-do lists) are preserved by converting them to inline icons, which are searchable by the icon's name and can be recoloured like any other icon. The Project A/B and numbered priority tags keep an emoji instead, as the icon pack has no letters or numerals.
Regarding the note structure: