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
fix(client): show the launcher code examples as code
Elian Doran952e07510508
diff --git a/apps/client/src/services/doc_renderer.spec.ts b/apps/client/src/services/doc_renderer.spec.tsindex f7fb380788..f6ba2276ca 100644--- a/apps/client/src/services/doc_renderer.spec.ts+++ b/apps/client/src/services/doc_renderer.spec.ts@@ -16,11 +16,10 @@ import renderDoc, { isDocName } from "./doc_renderer.js";const formatCodeBlocksMock = vi.fn((_arg?: unknown) => {});const applyReferenceLinksMock = vi.fn(async (_arg?: unknown) => {});-/** Resolves against the shipped English catalog, escaping interpolations the way i18next does. */+/** Resolves against the shipped English catalog, interpolating unescaped as the client's i18next does. */function translate(key: string, options?: Record<string, unknown>) {const entry = (en.doc_notes as Record<string, string>)[key.replace("doc_notes.", "")] ?? key;- return entry.replaceAll(/\{\{(\w+)\}\}/g, (_match, name: string) =>- String(options?.[name] ?? "").replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">"));+ return entry.replaceAll(/\{\{(\w+)\}\}/g, (_match, name: string) => String(options?.[name] ?? ""));}/** Builds a minimal FNote-like object with the given docName label. */diff --git a/apps/client/src/services/doc_renderer.ts b/apps/client/src/services/doc_renderer.tsindex 1f345f81ee..b7d757d60d 100644--- a/apps/client/src/services/doc_renderer.ts+++ b/apps/client/src/services/doc_renderer.ts@@ -2,6 +2,7 @@ import type FNote from "../entities/fnote.js";import { applyReferenceLinks } from "../widgets/type_widgets/text/read_only_helper.js";import { t } from "./i18n.js";import { formatCodeBlocks } from "./syntax_highlight.js";+import { escapeHtml } from "./utils.js";/*** The pages that ship with the application, named by the `docName` label that selects one. Their@@ -44,7 +45,8 @@ export default async function renderDoc(note: FNote) {return $content;}- $content.html(t(`doc_notes.${docName}`, { sample: SAMPLES[docName] }));+ const sample = SAMPLES[docName];+ $content.html(t(`doc_notes.${docName}`, { sample: sample && escapeHtml(sample) }));formatCodeBlocks($content);@@ -56,8 +58,8 @@ export default async function renderDoc(note: FNote) {/*** Code examples are not prose and have no business in the catalog, so the pages that carry one- * leave a `sample` placeholder for it. i18next escapes what it interpolates, which is what keeps- * the markup in the examples from being parsed as markup.+ * leave a `sample` placeholder for it. The client's i18next does not escape interpolations, so+ * `renderDoc()` passes each sample through `escapeHtml()`.*/const SAMPLES: Partial<Record<DocName, string>> = {launchbar_script_launcher: `api.showMessage("Current note is " + api.getActiveContextNote().title);`,