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
perf(client): drop the markdown renderer from the commons barrel
Elian Doranb22b107d1113
diff --git a/apps/client/src/services/content_renderer.spec.ts b/apps/client/src/services/content_renderer.spec.tsindex da548a2428..d16b491eb2 100644--- a/apps/client/src/services/content_renderer.spec.ts+++ b/apps/client/src/services/content_renderer.spec.ts@@ -73,7 +73,7 @@ vi.mock("../widgets/type_widgets/file/PdfViewer", () => ({ default: pdfViewerComvi.mock("dompurify", () => ({ default: { sanitize: (s: string) => s, addHook: () => {} } }));const renderToHtml = vi.fn((...args: any[]) => `<p>${args[0]}</p>`);-vi.mock("@triliumnext/commons", async (orig) => ({+vi.mock("@triliumnext/commons/src/lib/markdown_renderer", async (orig) => ({...(await (orig() as Promise<object>)),renderToHtml: (...a: any[]) => renderToHtml(...a)}));diff --git a/apps/client/src/services/content_renderer.ts b/apps/client/src/services/content_renderer.tsindex 590a9cca01..d4fdf49ace 100644--- a/apps/client/src/services/content_renderer.ts+++ b/apps/client/src/services/content_renderer.ts@@ -1,6 +1,6 @@import "./content_renderer.css";-import { normalizeMimeTypeForCKEditor, renderToHtml, type TextRepresentationResponse } from "@triliumnext/commons";+import { normalizeMimeTypeForCKEditor, type TextRepresentationResponse } from "@triliumnext/commons";import DOMPurify from "dompurify";import { h, render } from "preact";@@ -136,6 +136,8 @@ async function renderMarkdown(note: FNote | FAttachment, $renderedContent: JQuerreturn;}+ // The markdown renderer pulls in marked, so it is only loaded when a markdown note is rendered.+ const { renderToHtml } = await import("@triliumnext/commons/src/lib/markdown_renderer");const html = renderToHtml(source, note.title, {sanitize: (dirty) => DOMPurify.sanitize(dirty),wikiLink: { formatHref: (id) => `#root/${id}` }diff --git a/apps/client/src/widgets/type_widgets/code/Markdown.tsx b/apps/client/src/widgets/type_widgets/code/Markdown.tsxindex a8a6d02455..c47f85eed6 100644--- a/apps/client/src/widgets/type_widgets/code/Markdown.tsx+++ b/apps/client/src/widgets/type_widgets/code/Markdown.tsx@@ -5,7 +5,8 @@ import { autocompletion } from "@codemirror/autocomplete";import { syntaxTree } from "@codemirror/language";import type { SyntaxNode } from "@lezer/common";import VanillaCodeMirror from "@triliumnext/codemirror";-import { CustomMarkdownRenderer, isAnchorState, renderToHtml, type TaskStateDef } from "@triliumnext/commons";+import { isAnchorState, type TaskStateDef } from "@triliumnext/commons";+import { CustomMarkdownRenderer, renderToHtml } from "@triliumnext/commons/src/lib/markdown_renderer";import DOMPurify from "dompurify";import { Marked, type Tokens } from "marked";import { createContext } from "preact";diff --git a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsxindex bcf69e5c6e..332b03020f 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx+++ b/apps/client/src/widgets/type_widgets/llm_chat/ChatMessage.tsx@@ -1,7 +1,8 @@import "./ChatMessage.css";import "../code/MarkdownCommons.css";-import { CustomMarkdownRenderer, type LlmCitation, renderToHtml } from "@triliumnext/commons";+import { type LlmCitation } from "@triliumnext/commons";+import { CustomMarkdownRenderer, renderToHtml } from "@triliumnext/commons/src/lib/markdown_renderer";import DOMPurify from "dompurify";import type { Tokens } from "marked";import { useMemo } from "preact/hooks";diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.tsindex d65a4c9d65..6728d1c7a0 100644--- a/apps/server/src/share/content_renderer.ts+++ b/apps/server/src/share/content_renderer.ts@@ -1,4 +1,5 @@-import { extractYouTubeVideoId, renderToHtml as renderMarkdownToHtml } from "@triliumnext/commons";+import { extractYouTubeVideoId } from "@triliumnext/commons";+import { renderToHtml as renderMarkdownToHtml } from "@triliumnext/commons/src/lib/markdown_renderer.js";import { renderSpreadsheetToHtml } from "@triliumnext/commons/src/lib/spreadsheet/render_to_html.js";import { type BAttachment, type BBranch, becca, BNote, getLog, icon_packs as iconPackService, options, sanitize, task_states, utils } from "@triliumnext/core";import { highlightAuto } from "@triliumnext/highlightjs";diff --git a/packages/commons/src/index.ts b/packages/commons/src/index.tsindex d34578f038..4c1b0cb42d 100644--- a/packages/commons/src/index.ts+++ b/packages/commons/src/index.ts@@ -23,5 +23,7 @@ export * from "./lib/electron_api_interface.js";export * from "./lib/link_embed.js";export * from "./lib/llm_api.js";export * from "./lib/marked_extensions.js";-export * from "./lib/markdown_renderer.js";+// The markdown renderer is deliberately not re-exported here: it pulls in marked, and the barrel+// is imported by virtually every client module. Import it via its subpath instead,+// e.g. "@triliumnext/commons/src/lib/markdown_renderer".export * from "./lib/task_states.js";diff --git a/packages/trilium-core/src/services/export/markdown.ts b/packages/trilium-core/src/services/export/markdown.tsindex b23f619569..dcb4316b96 100644--- a/packages/trilium-core/src/services/export/markdown.ts+++ b/packages/trilium-core/src/services/export/markdown.ts@@ -1,4 +1,5 @@-import { ADMONITION_TYPE_MAPPINGS, type TaskStateDef } from "@triliumnext/commons";+import { type TaskStateDef } from "@triliumnext/commons";+import { ADMONITION_TYPE_MAPPINGS } from "@triliumnext/commons/src/lib/markdown_renderer.js";import { gfm } from "@triliumnext/turndown-plugin-gfm";import Turnish, { type Rule } from "turnish";diff --git a/packages/trilium-core/src/services/import/markdown.ts b/packages/trilium-core/src/services/import/markdown.tsindex 4d7d07c92b..970605934c 100644--- a/packages/trilium-core/src/services/import/markdown.ts+++ b/packages/trilium-core/src/services/import/markdown.ts@@ -1,4 +1,4 @@-import { renderToHtml as renderToHtmlShared } from "@triliumnext/commons";+import { renderToHtml as renderToHtmlShared } from "@triliumnext/commons/src/lib/markdown_renderer.js";import { sanitizeHtml } from "../sanitizer.js";import { getTaskStates } from "../task_states.js";