Skip to content

Build your personal knowledge base with Trilium Notes

fix(share): keep an icon's rotation and mirroring on a shared page

Elian Doran0c14f6af2db8
diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.ts
index 8b1882a058..79c76c3176 100644
--- a/apps/server/src/share/content_renderer.ts
+++ b/apps/server/src/share/content_renderer.ts
@@ -117,6 +117,7 @@ export function renderNoteForExport(note: BNote, parentBranch: BBranch, basePath
isStatic: true,
iconPackCss: [
...iconPacks.map(p => iconPackService.generateCss(p, `${basePath}assets/icon-pack-${p.prefix.toLowerCase()}.${iconPackService.MIME_TO_EXTENSION_MAPPINGS[p.fontMime]}`)),
+ iconPackService.generateIconTransformCss(),
task_states.generateTaskStateCss()
]
.filter(Boolean)
@@ -176,6 +177,7 @@ export function renderNoteContent(note: SNote, canAccessInclude?: CanAccessInclu
? `assets/fonts/${p.fontAttachmentId}.${iconPackService.MIME_TO_EXTENSION_MAPPINGS[p.fontMime]}`
: `api/attachments/${p.fontAttachmentId}/download`
)),
+ iconPackService.generateIconTransformCss(),
task_states.generateTaskStateCss()
]
.filter(Boolean)
diff --git a/packages/trilium-core/src/services/icon_packs.spec.ts b/packages/trilium-core/src/services/icon_packs.spec.ts
index a947a31f2f..dedc8d0eb9 100644
--- a/packages/trilium-core/src/services/icon_packs.spec.ts
+++ b/packages/trilium-core/src/services/icon_packs.spec.ts
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { buildNote } from "../test/becca_easy_mocking";
-import { determineBestFontAttachment, generateCss, generateIconRegistry, IconPackManifest, processIconPack } from "./icon_packs";
+import { determineBestFontAttachment, generateCss, generateIconRegistry, generateIconTransformCss, IconPackManifest, processIconPack } from "./icon_packs";
const manifest: IconPackManifest = {
icons: {
@@ -331,3 +331,15 @@ describe("Icon registry", () => {
expect(iconPack).toBeFalsy();
});
});
+
+describe("Generating CSS for icon transforms", () => {
+ it("carries every transform the text editor can write, unscoped to a pack", () => {
+ const css = generateIconTransformCss();
+
+ expect(css).toContain(".bx-rotate-90 { transform: rotate(90deg); }");
+ expect(css).toContain(".bx-rotate-180 { transform: rotate(180deg); }");
+ expect(css).toContain(".bx-rotate-270 { transform: rotate(270deg); }");
+ expect(css).toContain(".bx-flip-horizontal { transform: scaleX(-1); }");
+ expect(css).toContain(".bx-flip-vertical { transform: scaleY(-1); }");
+ });
+});
diff --git a/packages/trilium-core/src/services/icon_packs.ts b/packages/trilium-core/src/services/icon_packs.ts
index 421c451ef9..3f995dcc96 100644
--- a/packages/trilium-core/src/services/icon_packs.ts
+++ b/packages/trilium-core/src/services/icon_packs.ts
@@ -166,6 +166,30 @@ export function determineBestFontAttachment(iconPackNote: BNote) {
return null;
}
+/**
+ * The transforms an icon can carry in a note's content, written by the text editor's icon toolbar
+ * as a class. Boxicons names them, but the rules are not scoped to a pack, so they apply to any
+ * icon — the application's own `bx bx-sidebar bx-flip-horizontal` is one.
+ */
+const ICON_TRANSFORM_RULES: Record<string, string> = {
+ "bx-rotate-90": "rotate(90deg)",
+ "bx-rotate-180": "rotate(180deg)",
+ "bx-rotate-270": "rotate(270deg)",
+ "bx-flip-horizontal": "scaleX(-1)",
+ "bx-flip-vertical": "scaleY(-1)"
+};
+
+/**
+ * Generates the CSS for {@link ICON_TRANSFORM_RULES}. `boxicons-compat.css` carries these rules in
+ * the application, which a shared or exported page does not load: there they come from here, beside
+ * the icon packs' own CSS.
+ */
+export function generateIconTransformCss(): string {
+ return Object.entries(ICON_TRANSFORM_RULES)
+ .map(([ className, transform ]) => `.${className} { transform: ${transform}; }`)
+ .join("\n");
+}
+
export function generateCss({ manifest, fontMime, builtin, fontAttachmentId, prefix }: ProcessedIconPack, fontUrl: string) {
try {
const iconDeclarations: string[] = [];