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(text): missing right margin in read-only text
Elian Doran1877ca768f74
diff --git a/.claude/skills/in-app-help/SKILL.md b/.claude/skills/in-app-help/SKILL.mdnew file mode 100644index 0000000000..0e8c490777--- /dev/null+++ b/.claude/skills/in-app-help/SKILL.md@@ -0,0 +1,96 @@+---+name: in-app-help+description: Use when touching Trilium's in-app help (the `_help` subtree) — regenerating it after a docs change, changing how pages, links, images or attachments are produced or served, wiring a new platform to it, or debugging "help page is blank / images are broken / search finds nothing". Covers the markdown-to-artifacts pipeline, the four packaging paths that each need their own asset copy, and the verification recipe that catches the failures status codes hide.+---++# Trilium's in-app help++The User Guide is authored as notes, exported **once** as markdown, and turned into two committed artifacts that every platform reads.++```+docs/User Guide/**.md authored source, exported by edit-docs (the only export)+ └─ edit-docs+ ├─ apps/server/src/assets/help/help_meta.json the note tree+ └─ apps/server/src/assets/help/help_content.json each page rendered, keyed by note ID+docs/User Guide/**.png|gif|dat images and attachments, committed only here+```++Both JSON files are **generated**. Never hand-edit them — run `pnpm edit-docs:edit-docs` and let the export rewrite them. If you need to regenerate without the Electron app (e.g. after changing a generator), call `buildHelpMeta` / `buildHelpBundle` directly against `docs/User Guide/!!!meta.json`; they are pure functions taking injected readers.++Help pages are **virtual notes** — becca-only, never persisted or synced, read-only through an inheritable `readOnly` label on the `_help` root. See `packages/trilium-core/src/services/virtual_notes.ts`.++## The pieces++| Concern | Where |+|---|---|+| Tree generation | `apps/edit-docs/src/help_meta_generator.ts` |+| Content generation, link + asset rewriting | `apps/edit-docs/src/help_bundle_generator.ts` |+| Injection into becca | `packages/trilium-core/src/becca/becca_loader.ts` |+| Provider contract, `{{helpAssets}}` substitution | `packages/trilium-core/src/services/in_app_help.ts` |+| Blob POJO for virtual notes | `packages/trilium-core/src/services/blob.ts` |+| Content search over virtual notes | `.../search/expressions/note_content_fulltext.ts` |+| Assistant search | `packages/trilium-core/src/services/llm/tools/help_tools.ts` |+| End-to-end guard | `apps/server/spec/in_app_help.spec.ts` |++`HelpMetaItem.source` is the page's markdown file; `dir` is set for folder notes, which have no file and are linked by directory. Links become `#root/_help_<noteId>`; assets become `{{helpAssets}}/<path from the export root>`, substituted per platform by `getHelpAssetBase()`.++## Assets need a copy step per packaging path++Images live **only** in `docs/User Guide/`. Four paths ship them, and missing one breaks only that one:++- **server** — `getHelpAssetDir()` in `routes/assets.ts` (reads `docs/User Guide` when `isDev`); `apps/server/scripts/build.ts` copies for the package+- **desktop** — runs the server, but its build copies `apps/server/src/assets`, which is *not* where these live, so `apps/desktop/scripts/build.ts` needs its own copy+- **standalone** — `copyHelpAssetsPlugin` in `apps/standalone/vite.config.mts`, which must have **both** a `configureServer` middleware (dev) and a `closeBundle` copy (build)+- **mobile** — inherits the standalone dist via `webDir`; every megabyte here lands in the APK/IPA++## A 200 does not mean it works++Both dev servers answer unknown paths under their asset prefixes with `index.html`. A missing route returns **200 `text/html`**, so `curl -w "%{http_code}"` and any status-only assertion pass while every image is broken. This has bitten twice.++Always check the content type:++```bash+curl -s -D - -o /dev/null "http://localhost:8080/assets/v<version>/help/<path>" | grep -i content-type+```++Sweep every asset the bundle references — `<port>` is 8080 for `server:start`, 5173 for `standalone:start`:++```bash+node -e "const b=require('./apps/server/src/assets/help/help_content.json');+ const u=[...new Set([...Object.values(b).join('').matchAll(/\{\{helpAssets\}\}\/([^\"]*)/g)].map(m=>m[1]))];+ require('fs').writeFileSync(process.env.TEMP+'/asseturls.txt', u.join('\n')); console.log(u.length)"++while IFS= read -r u; do+ ct=$(curl -s -D - -o /dev/null "http://localhost:8080/assets/v0.104.1/help/$u" | grep -i "^content-type" | tr -d '\r')+ case "$ct" in *image/*|*octet-stream*) ;; *) echo "BAD $ct <- $u";; esac+done < "$TEMP/asseturls.txt"+```++For a build, resolve the same URLs against the output tree instead:++```bash+node -e "const fs=require('fs'),p=require('path');+ const b=require('./apps/server/src/assets/help/help_content.json');+ const u=[...new Set([...Object.values(b).join('').matchAll(/\{\{helpAssets\}\}\/([^\"]*)/g)].map(m=>m[1]))];+ const root='apps/standalone/dist/server-assets/help';+ console.log('missing:', u.filter(x=>!fs.existsSync(p.join(root, decodeURIComponent(x)))).length)"+```++Getting the copy *destination depth* wrong is easy and silent: the export root `docs/User Guide` itself contains a `User Guide/` directory, and asset paths are relative to that root — so the copy target is `…/help`, not `…/help/User Guide`.++## Debugging a broken help page++- **Blank page, no error** — the provider has no content: standalone's fetch failed (check the worker console) or `getHelpContent()` returned `{}`+- **Error instead of a page** — the blob path: virtual notes have no `blobs` row, so `getBlobPojo` must take its virtual branch+- **Broken images** — a copy step or a dev middleware is missing; run the sweep above rather than trusting a status code+- **Dead cross-links** — links that didn't resolve stay as authored `.md` paths; the client spec `apps/client/src/services/in_app_help.spec.ts` checks every link in the markdown+- **Search finds nothing** — two separate paths: the user-facing search matches virtual notes only via the pass in `note_content_fulltext.ts`, and only when the query includes hidden notes; the assistant's `search_help` builds its own index from `note.getContent()`++## Tests to run++```bash+pnpm --filter edit-docs test --run # generators+pnpm --filter server test --run spec/in_app_help.spec.ts # shipped artifacts, end to end+pnpm --filter client test --run src/services/in_app_help.spec.ts+pnpm --filter standalone test --run src/lightweight/in_app_help_provider.spec.ts+```diff --git a/CLAUDE.md b/CLAUDE.mdindex eefa7e4b02..aa1cb39e77 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -249,7 +249,7 @@ SQLite via `better-sqlite3`. SQL abstraction in `packages/trilium-core/src/servi- **Client-side**: `import { t } from "../services/i18n"` with keys in `apps/client/src/translations/en/translation.json`- **Server-side**: `import { t } from "i18next"` with keys in `apps/server/src/assets/translations/en/server.json`- **Electron main process** (e.g. `apps/desktop/src/`): `import { t } from "i18next"` — uses server-side keys from `apps/server/src/assets/translations/en/server.json` (same as server-side). **Never hardcode user-facing strings** in Electron dialogs, tray menus, or IPC handlers — always use `t()`.-- **`packages/trilium-core`**: `import { t } from "i18next"` — also the server catalog. Despite the name, `server.json` is the catalog for **every** non-browser-UI runtime, standalone included: `apps/standalone/src/lightweight/translation_provider.ts` initialises i18next in the worker with `ns: "server"` and fetches `server-assets/translations/{{lng}}/server.json`, which `apps/standalone/vite.config.mts` populates by copying `apps/server/src/assets/**/*`. So a `t()` call added to core resolves in server, desktop **and** standalone with no extra work — don't assume a core string needs relocating or a fallback to run in the browser build. (That copy excludes `doc_notes/en/User Guide/**`, so the in-app User Guide itself is *not* in the standalone build.)+- **`packages/trilium-core`**: `import { t } from "i18next"` — also the server catalog. Despite the name, `server.json` is the catalog for **every** non-browser-UI runtime, standalone included: `apps/standalone/src/lightweight/translation_provider.ts` initialises i18next in the worker with `ns: "server"` and fetches `server-assets/translations/{{lng}}/server.json`, which `apps/standalone/vite.config.mts` populates by copying `apps/server/src/assets/**/*`. So a `t()` call added to core resolves in server, desktop **and** standalone with no extra work — don't assume a core string needs relocating or a fallback to run in the browser build. (That copy also carries `assets/help/`, which is how standalone gets the in-app help; its images come from a separate step, see Documentation.)- **Interpolation**: Use `{{variable}}` for normal interpolation; use `{{- variable}}` (with hyphen) for **unescaped** interpolation when the value contains special characters like quotes that shouldn't be HTML-escaped#### Text Editor (`packages/ckeditor5`) Translation Usage@@ -350,9 +350,31 @@ Use `note.getOwnedAttribute()` for direct, `note.getAttribute()` for inherited.## Documentation- Script API reference — Generated by `apps/build-docs` (TypeDoc) into the gitignored `site/script-api/{backend,frontend,electron}` and published to [docs.triliumnotes.org](https://docs.triliumnotes.org/). Not committed; never hand-edit — it's regenerated from the script API type definitions-- `docs/User Guide/` — Edit via `pnpm edit-docs:edit-docs`, not manually+- `docs/User Guide/` — Edit via `pnpm edit-docs:edit-docs`, not manually. It is also the **single source of the in-app help**; see below- `docs/Developer Guide/` and `docs/Release Notes/` — Safe for direct Markdown editing+### In-app help (the `_help` subtree)++The User Guide is exported **once**, as markdown. `edit-docs` derives two artifacts from that export and commits them to `apps/server/src/assets/help/`:++- `help_meta.json` — the note tree: ids, titles, types, labels, and each page's `source` (its markdown file) and `dir` (for folder notes, which have no file of their own and are linked by directory)+- `help_content.json` — each page rendered to HTML, keyed by note ID, with links rewritten to `#root/_help_<noteId>` and assets to `{{helpAssets}}/<path>`++Both are **generated** — never hand-edit them; run `pnpm edit-docs:edit-docs` and let the export rewrite them. The generators are `apps/edit-docs/src/help_meta_generator.ts` and `help_bundle_generator.ts`, both pure and unit-tested.++Help pages are **virtual notes** (`services/virtual_notes.ts`): they exist only in becca, are never persisted or synced, and are read-only via an inheritable `readOnly` label on the `_help` root. Content reaches them through `InAppHelpProvider.getHelpContent()`, and `getHelpAssetBase()` decides where the `{{helpAssets}}` placeholder points — that is how one bundle serves every platform.++**Images and attachments live only in `docs/User Guide/`** and are not committed anywhere else, so **every packaging path needs its own copy step**. There are four, and missing one fails only in that one place:++| Where | Runtime | Build |+|---|---|---|+| server | `getHelpAssetDir()` reads `docs/User Guide` when `isDev` | `apps/server/scripts/build.ts` copies it into `assets/help/` |+| desktop | same (it runs the server) | `apps/desktop/scripts/build.ts` needs its **own** copy — it copies `apps/server/src/assets`, which is not where these live |+| standalone | dev middleware in `vite.config.mts` | `copyHelpAssetsPlugin` in the same file |+| mobile | inherits the standalone dist (`webDir`) | — |++Adding a static asset route also means adding it to the **dev allowlist** in `apps/server/src/routes/assets.ts` — see the warning under Server-Side Static Assets.+## Key Entry Points- `apps/server/src/main.ts` — Server startup@@ -406,6 +428,15 @@ The viewer under `packages/pdfjs-viewer/viewer/` is vendored from the pdf.js Git- **Do not use `import.meta.url`/`fileURLToPath`** to resolve file paths — the server is bundled into CJS for production, so `import.meta.url` will not point to the source directory- **Do not use `__dirname` with relative paths** from source files — after bundling, `__dirname` points to the bundle output, not the original source tree+#### A new static route needs a dev path too, and a 200 does not mean it works++In dev, Vite's middleware owns whole URL prefixes and answers anything it does not recognise with `index.html`. A missing static route therefore returns **200 with `text/html`**, not a 404 — so `curl -o /dev/null -w "%{http_code}"`, and any test that only checks the status, passes while every asset is broken. **Check `Content-Type` (or the body), never the status alone.**++Two places apply the fallback, and both need the route added explicitly:++- **server** — `apps/server/src/routes/assets.ts` mounts Vite on `/${assetUrlFragment}/` with an allowlist (`/images/`, `/doc_notes/`, `/help/`) of prefixes that fall through to the static mounts. A path not on that list is swallowed+- **standalone** — `apps/standalone/vite.config.mts`; `viteStaticCopy` targets are served in dev, but anything copied by a custom plugin needs its own `configureServer` middleware (see `copyHelpAssetsPlugin` and `pdfjsServePlugin`). A plugin marked `apply: "build"` does nothing under `standalone:start`+## MCP Server- Trilium exposes an MCP (Model Context Protocol) server at `http://localhost:8080/mcp`, configured in `.mcp.json`- The MCP server is **only available when the Trilium server is running** (`pnpm run server:start`)diff --git a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.css b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.cssindex fa79b552a4..b866e1c831 100644--- a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.css+++ b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.css@@ -47,7 +47,7 @@ body.heading-style-underline .note-detail-readonly-text-content {}.note-detail-readonly-text {- padding-inline-start: 24px;+ padding-inline: 24px;padding-top: 10px;font-family: var(--detail-font-family);min-height: 50px;