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
client/text editor/youtube preview: add support for block captions
Adorian Doranb0358bac0298
diff --git a/.claude/skills/developing-content-embeds/SKILL.md b/.claude/skills/developing-content-embeds/SKILL.mdindex e3e992a451..dabfad57aa 100644--- a/.claude/skills/developing-content-embeds/SKILL.md+++ b/.claude/skills/developing-content-embeds/SKILL.md@@ -48,6 +48,27 @@ All three carry `boxSize`, `hideTitle`, `editable`, `displayMode` (`data-box-siz`--include-note-width` / `--include-note-height` in `style`. The figure keeps an optional`<figcaption>`.+**Captions of an embed whose element is not a `<figure>`** (`_defineCaptionedEmbedConverters()`+in `content_embed.ts`). While such an embed has a caption, the note saves its element in a+`<figure class="captioned-content-embed">` (`CAPTIONED_CONTENT_EMBED_CLASS`), followed by the+`<figcaption>`, and without a caption it saves the bare element again. Every kind gets this+without code of its own: a `low` data downcast listener wraps whatever element the kind's+converter bound, a data mapper hook puts the caption after that element, and an upcast at+`high` converts the element and turns the `<figcaption>` into the `caption` of the embed+(`isEmbedCaptionToggleable()`), or into text after content that takes none. The figure is bound+to the embed as well, view to model only, so the mapper counts it as one node; the embed still+maps to its element, where the attribute converters (width, position) write. A kind opts in+through `hasCaptionSupport()`; only inline source embeds stay out. Read-only views replace the+figure with the box and move the caption into it (`replaceWithEmbedBox()` in+`content_renderer_text.ts`); share pages move `style`, `data-box-size` and `data-position` from+the element to the figure (`moveBoxToCaptionedFigure()`), which the share CSS places; Markdown+export keeps the figure as raw HTML.++**An embed whose caption has the selection looks selected**, as one whose player or editor has+the focus (which selects it): `markEmbedOfSelectedCaption()` adds `ck-widget_selected` after+`Widget` marks the selection and takes it away on `cleanSelection`. `Widget` itself marks only+widgets inside the selection.+- **Inline source** (`inline_source.ts`, `ContentEmbedInlineSource`) keeps the document readableelsewhere: the note exports to Markdown as a fenced `mermaid` block, other apps render it, andundo in the note undoes source edits through the shared undo history (see _Undo history_ below).@@ -63,7 +84,13 @@ All three carry `boxSize`, `hideTitle`, `editable`, `displayMode` (`data-box-siz(`VIDEO_EMBED_BOX_SIZES`); `readVideoEmbedBox()` reads a video saved before as Full anduntitled, and `createVideoEmbed()` makes a new one Medium at `getVideoMediumWidth()` (20emhigh), which the box size command sets again. Height follows width (`isHeightResizable` is- per element). No caption.+ per element). A caption is saved in the captioned figure (above). The video toolbar also+ shows while the caret is in the caption (`findRelatedVideo()`), and its Copy URL and Display+ act on the video through `ChangeLinkDisplayCommand._getTarget()`: the selected preview, else,+ unless the caret is on a link, the video of the caption (`getCaptionedEmbed()`).+ `getSelectedLinkWidget()` itself reads only the selected element, as the link balloon shares+ the command and Ctrl+K in a caption must edit the caption's own link. `rebuildLinkWidget()`+ copies the caption into a preview that keeps its shape.The shape is the link preview field `aspectRatio` (`data-aspect-ratio="9/16"`), which theserver reads from oEmbed for the video's `/shorts/` address (the watch address of a Shortanswers 16:9). `getVideoAspectRatio()` validates it; every box that draws a player (the@@ -76,7 +103,8 @@ All three carry `boxSize`, `hideTitle`, `editable`, `displayMode` (`data-box-siz`augmentation.ts`) and the client's `fetchMetadata()`; `META_KEYS`, the schemas and theconverters follow the map. It renders through `contentEmbed.loadVideo()` (`loadVideoEmbed()`, whose title rowopens the embed menu only in the editor) and has a toolbar of its own (`videoEmbed` in- `content_embed_toolbar.ts`): Copy URL, the link preview's Display dropdown and ⋮. Its ⋮ menu+ `content_embed_toolbar.ts`): Copy URL, the link preview's Display dropdown and ⋮. The caption+ is toggled from ⋮ only. Its ⋮ menu(`getVideoItems()`, picked by the `url` of `ContentEmbedState`) puts _Open externally_(`openUrlExternally()` in `services/open.ts`) above the embed's commands and _Delete_ below.`ReadOnlyText`'s `applyVideoEmbeds()` swaps the section for the same box.diff --git a/apps/client/src/menus/link_context_menu.spec.ts b/apps/client/src/menus/link_context_menu.spec.tsindex d7bc776300..3890573004 100644--- a/apps/client/src/menus/link_context_menu.spec.ts+++ b/apps/client/src/menus/link_context_menu.spec.ts@@ -753,7 +753,10 @@ describe("openContextMenu", () => {it("opens a video externally first in its menu, and deletes it last", async () => {const url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";- state = { ...state, url, isCaptionSupported: false, isConvertibleToLink: false };+ state = {+ ...state, url, isCaptionSupported: true, isCaptionToggleable: true,+ hasCaption: false, isConvertibleToLink: false+ };const openMenu = async () => {await linkContextMenu.openEmbedContextMenu(contextMenuEvent(embed()));return mocks.show.mock.lastCall?.[0].items;@@ -765,19 +768,20 @@ describe("openContextMenu", () => {{ kind: "separator" },{ title: "link_context_menu.include_size" },{ title: "link_context_menu.show_title" },+ { title: "link_context_menu.show_caption", enabled: true, checked: false },{ kind: "separator" },{title: "link_context_menu.delete",uiIcon: "bx bx-trash destructive-action-icon"}]);- expect(items).toHaveLength(6);+ expect(items).toHaveLength(7);items[0].handler();expect(mocks.openUrlExternally).toHaveBeenCalledExactlyOnceWith(url);- expect(pick(items[5])).toEqual([ [ "deleteContentEmbed", undefined ] ]);+ expect(pick(items[6])).toEqual([ [ "deleteContentEmbed", undefined ] ]);- // An embed of a source has neither.- state = { ...state, url: null };+ // An embed of a source has neither, nor a caption.+ state = { ...state, url: null, isCaptionSupported: false };expect(await openMenu()).toMatchObject([{ title: "link_context_menu.include_size" },{ title: "link_context_menu.show_title" }diff --git a/apps/client/src/services/content_renderer_text.ts b/apps/client/src/services/content_renderer_text.tsindex 4927ee025c..ddc4f7356f 100644--- a/apps/client/src/services/content_renderer_text.ts+++ b/apps/client/src/services/content_renderer_text.ts@@ -6,9 +6,9 @@ import {applyStickyTableHeaders} from "@triliumnext/ckeditor5/src/plugins/table_sticky_header_read_only.js";import {- BLOCK_ID_ATTRIBUTE, CONTENT_EMBED_KIND_ATTRIBUTE, type ContentEmbedContext,- getAttachmentEmbedHref, getEmbedKey, getNestedEmbedOptions, getNoteEmbedHref, KATEX_MACROS,- resolveContentEmbed, sliceToBlockReference+ BLOCK_ID_ATTRIBUTE, CAPTIONED_CONTENT_EMBED_CLASS, CONTENT_EMBED_KIND_ATTRIBUTE,+ type ContentEmbedContext, getAttachmentEmbedHref, getEmbedKey, getNestedEmbedOptions,+ getNoteEmbedHref, KATEX_MACROS, resolveContentEmbed, sliceToBlockReference} from "@triliumnext/commons";import FAttachment from "../entities/fattachment.js";@@ -233,6 +233,25 @@ export function getEmbedCaption(embedEl: Element) {return embedEl.querySelector<HTMLElement>(":scope > figcaption");}+/**+ * Replaces `element`, the saved element of an embed, with `box`, its `.include-note` box. The+ * `<figure class="captioned-content-embed">` that holds `element` with a caption is replaced+ * too, and the caption moves into `box`.+ */+export function replaceWithEmbedBox(element: Element, box: HTMLElement) {+ const figure = element.parentElement;+ if (!figure?.matches(`figure.${CAPTIONED_CONTENT_EMBED_CLASS}`)) {+ element.replaceWith(box);+ return;+ }++ const caption = figure.querySelector(":scope > figcaption");+ if (caption) {+ box.append(caption);+ }+ figure.replaceWith(box);+}+function replaceWithReferenceLink(embedEl: Element, href: string) {const referenceLink = document.createElement("a");referenceLink.className = "reference-link";diff --git a/apps/client/src/stylesheets/style.css b/apps/client/src/stylesheets/style.cssindex e7421b183d..e2b926ef1c 100644--- a/apps/client/src/stylesheets/style.css+++ b/apps/client/src/stylesheets/style.css@@ -1345,7 +1345,11 @@ body.mobile .modal-content-with-sidebar > .modal-main > .modal-header > .modal-tborder-bottom: 2px solid var(--main-background-color);}-.include-note > figcaption {+figure.captioned-content-embed {+ margin: 0;+}++:is(.include-note, .captioned-content-embed) > figcaption {padding: 6px 1rem;font-size: .8em;text-align: center;diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 4dc6c85343..47a040765b 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -4507,6 +4507,7 @@"box-size-0": "Box size: %0","bulleted-list": "Bulleted list","caption-for-the-included-note": "Caption for the included note",+ "caption-for-the-video": "Caption for the video","card": "Card","caution": "Caution","changes": "Changes",diff --git a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsx b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsxindex cbc36b908b..c5b6080aa6 100644--- a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsx+++ b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.spec.tsx@@ -608,7 +608,9 @@ describe("ReadOnlyText videos", () => {+ ` data-aspect-ratio="9/16" data-box-size="medium" data-position="wrap-left"`+ ` data-trilium-block-id="b1">`+ ` </section>`+ + `<figure class="captioned-content-embed">`+ `<section class="link-embed" data-url="${url}" data-embed-type="youtube"></section>`+ + `<figcaption>A caption</figcaption></figure>`+ `<section class="link-embed" data-url="https://example.com/"`+ ` data-embed-type="opengraph" data-title="A card"></section>`;@@ -643,7 +645,8 @@ describe("ReadOnlyText videos", () => {className: figure.className,data: { ...figure.dataset },width: figure.style.getPropertyValue("--include-note-width"),- shape: figure.style.getPropertyValue("--video-aspect-ratio")+ shape: figure.style.getPropertyValue("--video-aspect-ratio"),+ caption: figure.querySelector(":scope > figcaption")?.textContent ?? null};});const box = {@@ -651,14 +654,15 @@ describe("ReadOnlyText videos", () => {};expect(videos).toEqual([{- ...box, title: "A video", width: "30em", shape: "0.5625",+ ...box, title: "A video", width: "30em", shape: "0.5625", caption: null,data: { boxSize: "medium", position: "wrap-left", triliumBlockId: "b1" }},{- ...box, title: null, width: "", shape: "",+ ...box, title: null, width: "", shape: "", caption: "A caption",data: { boxSize: "full", hideTitle: "true" }}]);+ expect(container.querySelector(".captioned-content-embed")).toBeNull();expect(container.querySelector("section.link-embed > a.link-embed-card")).not.toBeNull();await unmount();});diff --git a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsxindex 232ff46e17..20d17ba860 100644--- a/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx+++ b/apps/client/src/widgets/type_widgets/text/ReadOnlyText.tsx@@ -27,7 +27,7 @@ import FNote from "../../../entities/fnote";import { consumeBlockReference } from "../../../services/block_reference";import { consumeBookmark } from "../../../services/bookmark_jump";import {- applyInlineMermaid, emptyUnknownEmbeds, rewriteMermaidDiagramsInContainer+ applyInlineMermaid, emptyUnknownEmbeds, replaceWithEmbedBox, rewriteMermaidDiagramsInContainer} from "../../../services/content_renderer_text";import { t } from "../../../services/i18n";import { applyNoteImageVersions } from "../../../services/image_urls";@@ -266,7 +266,7 @@ function applyContentEmbeds(container: HTMLDivElement) {/*** Shows each video of a link preview in the embed box the editor shows it in, with its title row- * and without the menu of the editor.+ * and caption, and without the menu of the editor.*/function applyVideoEmbeds(container: HTMLDivElement) {for (const section of container.querySelectorAll<HTMLElement>("section.link-embed")) {@@ -295,7 +295,7 @@ function applyVideoEmbeds(container: HTMLDivElement) {if (aspectRatio) {figure.style.setProperty(VIDEO_ASPECT_RATIO_PROPERTY, String(aspectRatio));}- section.replaceWith(figure);+ replaceWithEmbedBox(section, figure);loadVideoEmbed(preview, figure);}}diff --git a/apps/server/src/assets/help/help_content.json b/apps/server/src/assets/help/help_content.jsonindex e90ccbeba3..37680c24b4 100644--- a/apps/server/src/assets/help/help_content.json+++ b/apps/server/src/assets/help/help_content.json@@ -134,11 +134,11 @@"_help_0Ofbk1aSuVRu": "<figure class=\"image image-style-align-right image_resized\" style=\"width:50.47%;\"><img style=\"aspect-ratio:880/553;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Images/Image%20references_image.png\" width=\"880\" height=\"553\"></figure><p>Image references are an easy way to embed the preview of another note type into a <a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a> note.</p><h2>Supported note types</h2><ul><li><a class=\"reference-link\" href=\"#root/_help_grjYqerjn243\">Canvas</a></li><li><a class=\"reference-link\" href=\"#root/_help_s1aBHPd79XYj\">Mermaid Diagrams</a></li><li><a class=\"reference-link\" href=\"#root/_help_gBbsAeiuUxI5\">Mind Map</a></li></ul><h2>Steps</h2><ol><li>Go to one of the supported notes (listed above) and look for the <span class=\"tn-icon bx bx-copy\"></span> button in the <a class=\"reference-link\" href=\"#root/_help_1P8QXI5edXNd\">Note buttons</a> area.</li><li>Go to a <a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a> note and use the Paste function to insert the reference to that note.</li></ol><h2>Interaction</h2><ul><li>Double-clicking an image reference from a text note will automatically open the target note.</li><li>Clicking an image reference while <kbd>Ctrl</kbd> is pressed will open the target note in a new tab.</li><li>Modifying the target note should also update the image reference. If that doesn't happen, consider <a class=\"reference-link\" href=\"#root/_help_s8alTXmpFR61\">Refreshing the application</a>.</li></ul>","_help_VRoP0g1uHHc2": "<figure class=\"image image-style-align-center image_resized\" style=\"width:76.29%;\"><img style=\"aspect-ratio:1479/865;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/In-editor%20AI%20assistant_image.png\" width=\"1479\" height=\"865\"></figure><p>The AI assistant works on the text you are already writing: select a passage and have it rewritten, translated or turned into a table, or ask for new content at the cursor. Unlike the <a href=\"#root/_help_LrKznOtw9cQD\">AI chat</a>, it does not open a conversation window, the result is previewed in place and only enters the note when you accept it.</p><h2>Requirements</h2><p>The assistant is only available once at least one provider is configured in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>AI / LLM</em>, with at least one model selected for it. Until then the toolbar entry is not shown at all.</p><h2>Accessing the AI assistant</h2><p>To access the AI assistant:</p><ul><li>Look for the <span class=\"tn-icon cke cke-trilium-ai\"></span> button in the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>. Press the button itself to enter the <em>Ask AI</em> mode or press the arrow key next to it to access the quick commands and the model selection. On a phone, the button has no arrow: tapping it opens the same menu at the bottom of the screen, with <em>Ask AI…</em> at its top, and a group such as <em>Translate</em> opens as a page of its own.</li><li>Look for <em>AI assistant</em> or any of the <em>AI</em>-prefixed quick commands in <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>.</li><li>Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>K</kbd>.</li><li>Select a text and choose the <em>AI assistant</em> option in the <a class=\"reference-link\" href=\"#root/_help_jcQVxzYybYgz\">Note contextual menu</a>.</li></ul><h2>What the assistant works on</h2><figure class=\"table\"><table><thead><tr><th>Situation</th><th>What is sent</th></tr></thead><tbody><tr><td>Text is selected</td><td>The selection.</td></tr><tr><td>Nothing is selected, and you pick a quick action</td><td>The paragraph the cursor is in.</td></tr><tr><td>Nothing is selected, and you type your own prompt</td><td>Nothing, the response is new content written at the cursor.</td></tr></tbody></table></figure><p>In all cases the assistant also sends the text before and after the target, so that the model can tell what it is writing into: asked to <em>Continue writing</em> or to summarize, a model that can only see the selected words is guessing at the document around them. This surrounding text is context only, it is never rewritten.</p><aside class=\"admonition important\"><p>That means a single run sends more than the passage you highlighted. See <a class=\"reference-link\" href=\"#root/_help_cRRrdZjgyhNc\">Privacy</a> for exactly what leaves your machine.</p></aside><h2>Quick actions</h2><p>The arrow beside the toolbar button opens a menu of ready-made instructions, grouped by what they do.</p><ul><li>The <em>Reformat</em> actions produce real Trilium content rather than plain text: <em>Diagram</em> inserts a Mermaid diagram, <em>Callout</em> an admonition, and <em>Collapsible</em> a collapsible block.</li><li>The <em>Translate</em> group lists the <a href=\"#root/_help_veGu4faJErEM\">content languages</a> you have enabled, or a predefined list if no content languages are set. It can be filled from within the editor, the last entry of the submenu opens the language configuration directly.</li></ul><p>Actions that need something to work on are greyed out when there is nothing to work on (for example an empty paragraph with no selection).</p><h2>Asking for something specific</h2><p>Choosing <em>Ask AI…</em> (<span class=\"tn-icon bx bx-message-square-dots\"></span>) opens a prompt where you can describe the change in your own words, for example: \"make this less formal\", \"add a row for 2024\", \"write an intro paragraph for this section\". Press <kbd>Enter</kbd> or the <span class=\"tn-icon cke cke-arrow-up\"></span> send button to run it.</p><p>Once a response arrives you can keep going in the same prompt, and the assistant treats it as a conversation rather than as a fresh request: after <em>Translate this to German</em>, asking for <em>make it shorter</em> shortens the German, not the original.</p><h2>Reviewing the result</h2><p>The response streams in as it is generated, and can be interrupted at any point by pressing the <em>Stop</em> (<span class=\"tn-icon cke cke-stop\"></span>) button; whatever arrived before that stays usable.</p><p>Nothing is written into the note until you say so. The review offers:</p><ul><li><em>Result</em>, which displays the response as it will be inserted.</li><li><em>Changes</em>, which displays an inline diff against the original, with insertions and deletions marked. When the model rewrote the passage rather than editing it, the review opens on <em>Result</em> instead: a diff of two texts with little in common is harder to read than the answer itself.</li><li><em>Try again</em> (<span class=\"tn-icon cke cke-refresh\"></span>), to re-run the same instruction.</li><li><em>Replace</em>, which substitutes the original passage</li><li><em>Insert below</em>, which keeps the original and adds the response after it.</li></ul><p>Trilium also reports the model that produced it, the tokens consumed and, for providers that report it, the price.</p><p>If you ask for a correction and there is nothing to correct, the assistant will indicate it instead of showing a blank diff.</p><h2>Choosing the model</h2><p>The bottom of the quick actions menu shows which model the assistant runs on, and lets you pick another from the models you selected in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>AI / LLM</em>, grouped by provider.</p><p>The model can also be changed while asking for something specific, or after the assistant has generated its response (i.e. if the response needs a better model).</p><p>This choice is separate from the model used by the chat, and is remembered across notes and devices. Left unset, the assistant follows the first configured provider.</p>","_help_mVEYwt20exhO": "<p><em>Quick actions</em> are a feature of the <a class=\"reference-link\" href=\"#root/_help_VRoP0g1uHHc2\">In-editor AI assistant</a> for <a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a> notes which automatically triggers an LLM suggestion based on a defined prompt. The built-in quick actions come with a predefined prompt, but it is also possible to define your own quick actions.</p><h2>Creating a custom quick action</h2><p>In the <a class=\"reference-link\" href=\"#root/_help_oPVyFC7WL2Lp\">Note Tree</a>: </p><ol><li>Right-click the note where you want to place the quick action.</li><li>Select <em>Insert child note</em>.</li><li>Select <em>More</em> → <em>AI Quick Action</em>. The entry appears only when AI is enabled.</li></ol><p>Afterwards, simply type in the content of the note the desired prompt. The text can be formatted in the same manner as a normal text note and it will be passed to the LLM as Markdown.</p><p>The title of the note will become the title of the quick action.</p><p>Of note:</p><ul><li><a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> notes work too.</li><li>An empty note is ignored.</li><li><a class=\"reference-link\" href=\"#root/_help_MKmLg5x6xkor\">Archived Notes</a> are also excluded.</li></ul><h2>Using a quick action</h2><p>Once a quick action is defined, the action will appear under the <em>Quick Actions</em> dropdown in a group called <em>Custom</em>.</p>",- "_help_nBAXQFj20hS1": "<p>Text notes can \"include\" another note as a read-only widget or an interactive widget, depending on the type of note.</p><p>This can be useful for e.g. including a dynamically generated chart (from scripts & \"render HTML\" note) or other more advanced use cases.</p><h2>Including a note</h2><p>In the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, look for the <span class=\"tn-icon cke cke-trilium-note\"></span> button. There is also a keyboard shortcut defined for it but it is not allocated by default.</p><p>The <em>Include note</em> dialog opens with two rows: <em>Note</em>, where you search for the note to include, and <em>Box size</em> (see <em>Box sizes</em> below), a row of buttons each with a small drawing of the size, with a sentence under it describing the size chosen. Once a note is picked, press <em>Include note</em> or <kbd>Enter</kbd> to include it. Typing the title of a note that does not exist offers to create it.</p><p>An image note, a <a class=\"reference-link\" href=\"#root/_help_grjYqerjn243\">Canvas</a> or a <a class=\"reference-link\" href=\"#root/_help_s1aBHPd79XYj\">Mermaid Diagrams</a> note picked in the dialog is inserted as an image rather than included, so instead of the size buttons, the <em>Box size</em> row says so. In a text note, the image can be resized once it is in the text, and the dialog reminds you of that, as it reminds you that the size of an include can be changed later.</p><p>To include a note that is already linked, right-click a reference link to it in a text note being edited and select <em>Convert link to an included note</em>, at the end of the menu. The include gets the box size that suits the note, as one added from the button does.</p><p>An <a href=\"#root/_help_0vhv7lsOLy82\">attachment</a> can be included the same way, from the context menu of a link to it (see <em>Embedding an attachment</em> there).</p><p>A link to blocks of a text note is converted the same way, with <em>Convert link to note excerpt</em>, and the include then shows only those blocks. See <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>.</p><h2>Box sizes</h2><p>The box size sets how much of the included note is shown.</p><ul><li><em>Tiny</em> shows a single row instead of the content: the note's icon, its title with the path to the note above it, and buttons to act on the note. The included note is never rendered, so wherever the note is shown outside the editor, such as in print, in a tooltip or on a shared page, a <em>Tiny</em> include appears as a link to the included note.</li><li><em>Small</em> and <em>Medium</em> show the content in a box of limited height. Text scrolls inside the box, while a picture, a diagram or a video is scaled down to fit it.</li><li><em>Full</em> shows the whole content.</li><li><em>Expandable</em> shows only the title until its <span class=\"tn-icon bx bx-chevron-right\"></span> arrow is pressed. In a read-only note, a click anywhere on the title row other than its buttons and link expands or collapses it as well.</li></ul><p>A new include gets the size that suits what it shows:</p><ul><li><em>Tiny</em> for a note or an attachment that has no preview, such as a relation map or an archive.</li><li><em>Small</em> for audio.</li><li><em>Full</em> for a code note or a code file, such as a <code>.js</code>, <code>.py</code> or <code>.txt</code> attachment, and for an excerpt of the blocks of a text note.</li><li><em>Medium</em> for anything else.</li></ul><p>The <em>Include note</em> dialog selects that size among its <em>Box size</em> buttons once the note is picked, and you can choose another one there. To change the size later, select the include and use the <em>Box size</em> menu in its toolbar, or the <em>Size</em> submenu of its <em>More actions</em> menu. For an included code or Markdown note and an embedded code or Markdown file, the <em>Box size</em> menu is the <span class=\"tn-icon bx bx-move-vertical\"></span> button, whose tooltip names the current size.</p><h2>Resizing</h2><p>A <em>Small</em>, <em>Medium</em> or <em>Expandable</em> include can be resized to any width and height. A <em>Tiny</em> or <em>Full</em> include always fits its content.</p><ul><li>To resize an include, select it and drag the handle in its bottom-right corner. To change only the width or only the height, drag the middle of its right or bottom edge instead, where a touch screen shows a handle too. In right-to-left text, the handle is in the bottom-left corner and the width changes from the left edge.</li><li>Resizing works with a mouse, a pen or a finger.</li><li>While the height changes, moving the handle near the top or the bottom of the note scrolls the note.</li><li>An include narrower than the note is centered, so changing its width moves both of its sides. A drawing aligned to the left or the right keeps that side in place and has its handles on the other side (see <em>Positioning a drawing</em> below). Making an include as wide as the note returns it to the full width.</li><li>To cancel a resize, press <kbd>Esc</kbd> before releasing the handle.</li><li>To reset the size, double-click the corner handle, or double-tap it on a touch screen. Double-clicking the right or bottom edge resets only the width or the height.</li><li>Choosing a box size resets the height. Choosing <em>Tiny</em> or <em>Full</em> resets the width too.</li><li>While an <em>Expandable</em> include is collapsed, only its width can be changed.</li></ul><h2>Caption</h2><p>An include can have a caption, shown centered at the bottom of its box. The caption is part of the text note, so it can be formatted like the rest of the text, for example in bold or with a link.</p><ul><li>To add a caption, select the include, press the <span class=\"tn-icon cke cke-caption\"></span> <em>Toggle caption on</em> button in its toolbar and type the caption.</li><li>To remove the caption, press the same button again. Pressing it once more brings back the text it had, as long as the note stays open.</li><li>A <em>Tiny</em> include has no caption. Switching an include to <em>Tiny</em> removes its caption, and switching it back to a larger size restores the caption, as long as the note stays open.</li><li>An <em>Expandable</em> include shows its caption under the title while the content is collapsed, and under the content once it is expanded.</li></ul><h2>Title</h2><p>The title row of an include links to the included note and holds its buttons. To show only the content, select the include and press the <span class=\"tn-icon bx bx-window-alt\"></span> <em>Show title</em> button in its toolbar. Pressing it again shows the title.</p><ul><li>While the title is hidden, the <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> button in the toolbar of the include opens the menu of the included note.</li><li>A <em>Tiny</em> or <em>Expandable</em> include always shows its title, and its toolbar has no <em>Show title</em> button.</li></ul><h2>Opening an included note</h2><p>To open an included note in a new tab, press the <span class=\"tn-icon bx bx-link-external\"></span> <em>Open in new tab</em> button at the end of its title. An embedded attachment has the same button.</p><p>The <span class=\"tn-icon bx bx-dots-vertical-rounded\"></span> <em>More actions</em> button at the end of the title row opens the same menu as right-clicking anywhere on the title row: the other places to open the note in and, for an embedded attachment, the actions on the attachment.</p><p>In a note being edited, the menu also has the commands of the include's toolbar: the <em>Size</em> submenu, <em>Show title</em> and <em>Show caption</em>, each checked while it is in effect, and <em>Convert to link</em> at the end. A drawing canvas, a Mermaid diagram, an included text, code or Markdown note and an embedded code or Markdown file also have <em>Editable</em>, above <em>Size</em>. An included code or Markdown note, an embedded code or Markdown file and a Mermaid diagram also have the <em>Word wrap</em> and <em>Line numbers</em> submenus after <em>Editable</em> (see <em>Editing an include in place</em> below). A Mermaid diagram, an included Markdown note and an embedded Markdown file also have <em>Source view</em>, <em>Split view</em> and <em>Preview</em> after these submenus. For an embedded attachment they follow its first group of actions; for an included note they end the menu.</p><p>To show an include of size <em>Medium</em> or <em>Full</em> on the whole screen, press the <span class=\"tn-icon bx bx-fullscreen\"></span> <em>Fullscreen</em> button at the end of its title. An excerpt of the blocks of a note has an <span class=\"tn-icon bx bx-pencil\"></span> <em>Edit excerpt</em> button there instead; see <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>. To return, press <span class=\"tn-icon bx bx-exit\"></span> <em>Exit fullscreen</em> in the top-right corner, or <kbd>Esc</kbd>.</p><p>A <em>Tiny</em> include has these buttons instead, followed by the same <em>More actions</em> button:</p><ul><li>For a note, <span class=\"tn-icon bx bx-edit\"></span> <em>Quick edit</em> opens the note in <a class=\"reference-link\" href=\"#root/_help_ZjLYv08Rp3qC\">Quick edit</a>, and <span class=\"tn-icon bx bx-link-external\"></span> <em>Open in new tab</em> opens it in a new tab.</li><li>For an embedded attachment, <span class=\"tn-icon bx bx-file-find\"></span> <em>Open externally</em> opens the file in another application, and <span class=\"tn-icon bx bx-download\"></span> <em>Download</em> downloads it. The size of the file is shown under its title.</li></ul><h2>Converting an include to a link</h2><p>To replace an include with a link to the included note, select it and press the <span class=\"tn-icon cke cke-link\"></span> <em>Convert to link</em> button in its toolbar, or choose <em>Convert to link</em> at the end of its <em>More actions</em> menu. An embedded attachment turns into a link to the attachment the same way.</p><h2>Missing notes and attachments</h2><p>An include whose note or attachment no longer exists, for example because it was deleted, keeps its size and shows the <span class=\"tn-icon bx bx-error-alt\"></span> icon in place of the content, with the ID of the missing note or attachment. To remove the include, select it and press <kbd>Delete</kbd>.</p><p>Content added by a newer version of Trilium, which this version cannot show, appears the same way with the <span class=\"tn-icon bx bx-error\"></span> icon. Editing the note keeps that content unchanged, so it shows again once Trilium is updated.</p><h2>Included notes in the share functionality</h2><p>If a <a href=\"#root/_help_R9pX4DGra2Vt\">shared note</a> contains one or more included notes, they will be displayed in the content of the note as if they were part of the note itself. An include resized narrower than the note keeps its width, and a drawing its position. On a narrow screen, a drawing with a position other than <em>Align center</em> takes the full width. The caption of an include is shown under the included content. A <em>Tiny</em> include is shown as a link to the included note instead, and so is an include that would show a note already shown around it, such as a note that includes itself. The same goes for a printed or exported note.</p><p>For this to work, the included notes must also be shared. However, they can still be hidden from the note tree via <code>#shareHiddenFromTree</code>.</p><p>An include whose note or attachment is missing or not shared shows <em>This content is not available</em> in its place, and so does content added by a newer version of Trilium.</p><h2>Interactive notes</h2><p>Since v0.104.0, included notes might become interactive depending on their note type:</p><ul><li><a class=\"reference-link\" href=\"#root/_help_GTwFsgaA0lCt\">Collections</a> (e.g. <a class=\"reference-link\" href=\"#root/_help_81SGnPGMk7Xc\">Geo Map</a>) will render fully interactive, including creating new notes.</li><li><a class=\"reference-link\" href=\"#root/_help_m523cpzocqaD\">Saved Search</a> will also display the results.</li><li><a class=\"reference-link\" href=\"#root/_help_1vHRoWCEjj0L\">Web View</a> provides an interactive preview of the website.</li></ul><h2>Included images</h2><p>An included image, whether an image note or an image attachment, is shown in the image viewer, which zooms and pans it:</p><ul><li>To zoom, press the <span class=\"tn-icon bx bx-plus-circle\"></span> <em>Zoom in</em> and <span class=\"tn-icon bx bx-minus-circle\"></span> <em>Zoom out</em> buttons in the bottom-right corner of the image, or pinch on a touch screen. The percentage between them resets the zoom.</li><li>To zoom with the mouse wheel, click the image first. Until then, the mouse wheel scrolls the note.</li><li>To pan an image that is zoomed in, drag it. At its fitted size, dragging the image on a touch screen scrolls the note.</li><li>To return to the fitted size, double-click the image.</li></ul><p>In a <em>Small</em> or <em>Medium</em> box, the image is scaled down to fit the height of the box. In fullscreen, it fits the screen.</p><h2>Editing an include in place</h2><p>An included text note, an included code note and an embedded code file such as a <code>.js</code>, <code>.py</code> or <code>.txt</code> attachment can be edited without leaving the note that includes them. Until then, a code note or file is shown read-only in the code editor, where its code can be selected and copied, and its blocks folded and unfolded with the arrows in its gutter. Included Markdown can be edited too, see <em>Included Markdown</em> below.</p><ul><li>To edit, select the include and turn on the <span class=\"tn-icon bx bx-edit-alt\"></span> <em>Editable</em> button at the start of its toolbar, or check <em>Editable</em> in its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu. Turn <em>Editable</em> off to stop editing.</li><li>While <em>Editable</em> is on, the arrow keys move the caret into the include and back out, as through the rest of the text. Entering from above or from the left puts the caret at the start of the include, and entering from below or from the right puts it at the end. A collapsed <em>Expandable</em> include is skipped.</li><li>While an included text note has the focus, the formatting toolbar applies to it. The notes it includes in turn stay read-only.</li><li>Code is edited in the same code editor as a <a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> note, with its theme, indentation and line wrapping settings.</li><li>Typing <code>/</code> in the code lists the <a class=\"reference-link\" href=\"#root/_help_IEgsWp5hHH35\">Code Snippets</a> of its language, as in a code note.</li><li>The toolbar of an included code note or an embedded code file also has the language and indentation menus of the <a class=\"reference-link\" href=\"#root/_help_AlJ73vBCjWDw\">Status bar</a>, between <em>Editable</em> and the <span class=\"tn-icon bx bx-move-vertical\"></span> <em>Box size</em> menu: <em>Change language mode</em>, which shows the current language, and <em>Change tab width</em>, which shows the current indentation. <em>Re-indent content to</em> converts the indentation of the code itself and saves it to the included note or file, whether <em>Editable</em> is on or off.<ul><li>For an included note, the menus change the note, as they do in its own tab.</li><li>For an embedded code file, the language and indentation settings change only how this include shows the file, and are saved with the note that includes it. The language replaces the one that the file name gives, and the <em>Use default</em> entries return to the indentation set in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. These settings leave the file itself unchanged, and other includes of it keep their own settings.</li></ul></li><li>The <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu of an included code or Markdown note, an embedded code or Markdown file and a <a href=\"#root/_help_CohkqWQC1iBv\">Mermaid diagram</a> has two more submenus after <em>Editable</em>, each with <em>Auto</em>, <em>On</em> and <em>Off</em>. They change how the code editor shows the source.<ul><li><em>Word wrap</em> wraps long lines instead of scrolling them. <em>Auto</em> follows the setting in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. For an included note, it sets the <code>#wrapLines</code> label of the note, as the <em>Word wrap</em> submenu of its <a class=\"reference-link\" href=\"#root/_help_8YBEPzcpUgxw\">Note menu</a> does for a code note. For an embedded file or a Mermaid diagram, it changes only this include.</li><li><em>Line numbers</em> shows or hides the numbers at the start of each line. <em>Auto</em> follows the setting in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. It changes only this include, for an included note as well.</li></ul></li><li>The changes are saved as you type, to the included note or to the attachment, as they would be in its own tab.</li><li>The changes made in the code editor of an include are part of the undo history of the note that includes it, together with the changes to its text, in the order they were made. This includes the source of included Markdown and of a <a href=\"#root/_help_CohkqWQC1iBv\">Mermaid diagram</a>, and the changes to a drawing canvas (see below).<ul><li><kbd>Ctrl</kbd>+<kbd>Z</kbd> undoes the last change of the note, and <kbd>Ctrl</kbd>+<kbd>Y</kbd> or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Z</kbd> redoes it, whether the caret is in the text or in an include, and also while <em>Editable</em> is off. The <span class=\"tn-icon cke cke-undo\"></span> <em>Undo</em> and <span class=\"tn-icon cke cke-redo\"></span> <em>Redo</em> buttons of the formatting toolbar do the same. With the Vim key bindings, <code>u</code> and <kbd>Ctrl</kbd>+<kbd>R</kbd> in an include do the same too.</li><li>The focus moves to the change that was undone or redone: into the code editor or the drawing canvas of the include, or back to the text.</li><li>Undoing a change of an included note saves the included note again. Once the included note has been changed elsewhere, for example in another tab, its earlier changes can no longer be undone from here, and undo skips them.</li><li>An included text note keeps an undo history of its own.</li></ul></li><li>An include of <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a> edits only the referenced blocks.</li><li>Editing is not available in a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, for an included note marked <code>#readOnly</code>, or for an attachment of another note.</li><li><a class=\"reference-link\" href=\"#root/_help_McngOG2jbUWX\">Search in note</a> finds the text of included text and code notes among the results of the note around them, and replaces it while <em>Editable</em> is on.</li></ul><h2>Included Markdown</h2><p>An included <a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a> note and an embedded Markdown file, such as a <code>.md</code> attachment, are shown with the same three views as a Markdown note in its own tab (see <a class=\"reference-link\" href=\"#root/_help_SL5f1Auq7sVN\">Note types with split view</a>): <span class=\"tn-icon bx bx-code\"></span> <em>Source view</em>, <span class=\"tn-icon bx bxs-dock-left\"></span> <em>Split view</em> and <span class=\"tn-icon bx bx-show\"></span> <em>Preview</em>.</p><ul><li>To switch the view, press one of the three buttons in the title row of the include. In a note being edited, the toolbar of the include has the same buttons after <em>Editable</em>, and its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu has them as <em>Source view</em>, <em>Split view</em> and <em>Preview</em>.</li><li>Until a view is chosen, the include shows the <em>Preview</em>, and the <em>Split view</em> while <em>Editable</em> is on.</li><li>To edit the Markdown, turn on <em>Editable</em> (see <em>Editing an include in place</em> above). The source is edited in the code editor of a Markdown note, and the preview follows the changes as you type. While <em>Editable</em> is off, the source can be read and copied but not changed.</li><li>The source has the slash commands and the <code>@</code> and <code>[[</code> note links of a <a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a> note. A note created from the <code>@</code> or <code>[[</code> list goes under the included note, or for an embedded file under the note that includes it, and <code>/image</code> uploads the image to that same note.</li><li>The <em>Word wrap</em> and <em>Line numbers</em> submenus of the <em>More actions</em> menu change how the source shows, as for code (see <em>Editing an include in place</em> above).</li><li>As in a Markdown note, the preview scrolls along with the source and highlights the block where the cursor is, and <kbd>Ctrl</kbd>+<kbd>B</kbd>, <kbd>Ctrl</kbd>+<kbd>I</kbd>, <kbd>Ctrl</kbd>+<kbd>M</kbd> and <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>X</kbd> format the selection.</li><li>In a note being edited, the view is saved with the include, so two includes of the same note can show different views. In a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, the view can be changed too, until the note is opened again.</li><li>While the source shows, and wherever the Markdown can be edited, the include has the height of its box size, or the height it was resized to, so turning <em>Editable</em> on or off keeps its size. Otherwise, as in a read-only note, the preview fits its text up to that height. A <em>Full</em> include fits its content instead.</li><li><a class=\"reference-link\" href=\"#root/_help_McngOG2jbUWX\">Search in note</a> searches the source while it shows, and the preview otherwise.</li></ul><h2>Drawing canvases</h2><p>A drawing canvas is an Excalidraw canvas, like the one of a <a class=\"reference-link\" href=\"#root/_help_grjYqerjn243\">Canvas</a> note, drawn directly in the text note. It is not a note of its own: the drawing is kept in a <code>Canvas.excalidraw</code> <a href=\"#root/_help_0vhv7lsOLy82\">attachment</a> of the text note and is saved together with the text.</p><ul><li>To insert a drawing canvas, open the <span class=\"tn-icon cke cke-plus\"></span> <em>Insert</em> menu of the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a> and choose <span class=\"tn-icon bx bx-pen\"></span> <em>Drawing canvas</em>, above <em>Mermaid diagram</em>. It is also available as <em>Drawing canvas</em> in the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>. The canvas is added empty and editable, in a <em>Medium</em> box with its title hidden, and takes the focus, ready for drawing.</li><li>To draw or write over an image, select the image and press the <span class=\"tn-icon bx bxs-pen\"></span> <em>Convert image to a drawing canvas</em> button of its toolbar. The image is replaced by an editable drawing canvas in a <em>Medium</em> box, with its title hidden and the focus in it. The image sits at its original size in the middle of the canvas, zoomed so that all of it shows, and is locked so that it cannot be selected or moved by accident. While it is locked, the canvas can be zoomed in on the image but not zoomed out past it or scrolled beyond its edges. To move or resize the image anyway, right-click it and choose <em>Unlock</em>. The caption of the image is kept, but not its alignment or link. Only an image on its own line can be converted, not one inside a paragraph. Undo brings the image back.</li><li>An Excalidraw file (<code>.excalidraw</code>) attached with <em>Attach and embed file</em>, under the <span class=\"tn-icon cke cke-paper-clip\"></span><em>Attach file</em> button, becomes a drawing canvas too, in a <em>Medium</em> box titled with the file name. It starts with <em>Editable</em> off, so the drawing shows but cannot be changed until <em>Editable</em> is turned on (see below).</li><li>To draw on a canvas that does not have the focus, click it first. Until then, touch gestures scroll the note. The canvas then has the tools, menus and keyboard shortcuts of a Canvas note. The toolbars, the menus and the properties of the selected shapes show only while the canvas has the focus, so elsewhere the drawing reads like a picture in the text.</li><li>The mouse wheel and the touchpad scroll the note over a canvas too, as over the text. To zoom, use the zoom buttons of the canvas toolbar; to move around the drawing, use the <span class=\"tn-icon bx bxs-hand\"></span> <em>Hand</em> tool. In fullscreen, the mouse wheel moves and zooms the drawing instead.</li><li>The canvas toolbar replaces the Excalidraw menu: <em>Export image</em>, <em>Find on canvas</em>, <em>Library</em> and <em>Help</em> are at the end of its <span class=\"tn-icon bx bx-category\"></span> <em>More tools</em> menu. In fullscreen, the Excalidraw menu shows again.</li><li>The changes to the drawing are part of the undo history of the text note (see <em>Editing an include in place</em> above). <kbd>Ctrl</kbd>+<kbd>Z</kbd>, <kbd>Ctrl</kbd>+<kbd>Y</kbd> and the <span class=\"tn-icon bx bx-undo\"></span> <em>Undo</em> and <span class=\"tn-icon bx bx-redo\"></span> <em>Redo</em> buttons of the canvas toolbar undo and redo the last change of the note, in the drawing or in the text.</li><li>A new drawing has the background color of the note. A background chosen from the Excalidraw menu replaces it.</li><li>To protect a finished drawing from accidental changes, select it and turn off the <span class=\"tn-icon bx bx-edit-alt\"></span> <em>Editable</em> button at the start of its toolbar, or uncheck <em>Editable</em> in its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu. The drawing then shows as a still picture, at the zoom and position it had, and can no longer be changed, zoomed or moved. To draw again, turn <em>Editable</em> back on.</li><li>The box sizes, resizing, the caption and the title work as for an included note, but the toolbar of a drawing leaves the box size, <em>Show title</em> and <em>Convert to link</em> to its <em>More actions</em> menu, which also sets its position (see <em>Positioning a drawing</em> below).</li><li>In the desktop layout, Excalidraw keeps its desktop interface however small the box is. In the mobile layout, a narrow or short box switches it to a compact interface. For more room, choose <em>Full</em>, or show the title and press <span class=\"tn-icon bx bx-fullscreen\"></span> <em>Fullscreen</em>.</li><li>Pictures added to the drawing are stored in the same attachment. A converted image is kept as an image attachment of the note instead, named with a generated code.</li><li>In a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, the drawing shows as a still picture too.</li><li>On a <a href=\"#root/_help_R9pX4DGra2Vt\">shared page</a>, the drawing is shown as a picture at its own size, up to the width its box was resized to, in light or dark colors to match the page. Each change to the drawing saves this picture as an SVG image attachment of the note, also named with a generated code, which the list of attachments shows under <em>Generated by Trilium</em>.</li></ul><h3>Positioning a drawing</h3><p>A drawing can sit on lines of its own or have the text wrap around it, as an <a href=\"#root/_help_mT0HEkOsz6i1\">image</a> can.</p><ul><li>To change the position, select the drawing, open its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu and choose an entry of its <em>Position</em> submenu:<ul><li>Under <em>Break text</em>, <span class=\"tn-icon cke cke-object-left\"></span> <em>Align left</em>, <span class=\"tn-icon cke cke-object-center\"></span> <em>Align center</em> and <span class=\"tn-icon cke cke-object-right\"></span> <em>Align right</em> place the drawing on lines of its own, at that side of the note. <em>Align center</em> is the default.</li><li>Under <em>Wrap text</em>, <span class=\"tn-icon cke cke-object-inline-left\"></span> <em>Align left</em> and <span class=\"tn-icon cke cke-object-inline-right\"></span> <em>Align right</em> place the drawing at that side and let the text run beside it.</li></ul></li><li>A drawing is inserted at the full width of the note, so a new position shows once the drawing is resized narrower (see <em>Resizing</em> above). The position is kept whatever the box size, and shows again when a <em>Small</em>, <em>Medium</em> or <em>Expandable</em> box is resized.</li><li>In the mobile layout, a drawing with a position other than <em>Align center</em> takes the full width, and only its height can be resized.</li></ul><h3>Limitations</h3><ul><li>The Excalidraw shape library is not saved for a drawing canvas.</li><li>Outside the editor, for example in a tooltip, when printing or in the list of attachments, the drawing is shown as a picture.</li><li>A drawing has no picture for shared pages until its first change, except one converted from an image. Until then, for example for an attached <code>.excalidraw</code> file, a shared page shows a link to download the drawing instead.</li><li>In Safari, the picture of a drawing on a shared page follows the light or dark appearance of the system rather than the theme chosen on the page.</li><li>A copy of a drawing canvas pasted in the same note shares the drawing with the original, so a change to one shows in the other only after the note is opened again. A copy pasted in another note gets a drawing of its own.</li></ul>",+ "_help_nBAXQFj20hS1": "<p>Text notes can \"include\" another note as a read-only widget or an interactive widget, depending on the type of note.</p><p>This can be useful for e.g. including a dynamically generated chart (from scripts & \"render HTML\" note) or other more advanced use cases.</p><h2>Including a note</h2><p>In the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, look for the <span class=\"tn-icon cke cke-trilium-note\"></span> button. There is also a keyboard shortcut defined for it but it is not allocated by default.</p><p>The <em>Include note</em> dialog opens with two rows: <em>Note</em>, where you search for the note to include, and <em>Box size</em> (see <em>Box sizes</em> below), a row of buttons each with a small drawing of the size, with a sentence under it describing the size chosen. Once a note is picked, press <em>Include note</em> or <kbd>Enter</kbd> to include it. Typing the title of a note that does not exist offers to create it.</p><p>An image note, a <a class=\"reference-link\" href=\"#root/_help_grjYqerjn243\">Canvas</a> or a <a class=\"reference-link\" href=\"#root/_help_s1aBHPd79XYj\">Mermaid Diagrams</a> note picked in the dialog is inserted as an image rather than included, so instead of the size buttons, the <em>Box size</em> row says so. In a text note, the image can be resized once it is in the text, and the dialog reminds you of that, as it reminds you that the size of an include can be changed later.</p><p>To include a note that is already linked, right-click a reference link to it in a text note being edited and select <em>Convert link to an included note</em>, at the end of the menu. The include gets the box size that suits the note, as one added from the button does.</p><p>An <a href=\"#root/_help_0vhv7lsOLy82\">attachment</a> can be included the same way, from the context menu of a link to it (see <em>Embedding an attachment</em> there).</p><p>A link to blocks of a text note is converted the same way, with <em>Convert link to note excerpt</em>, and the include then shows only those blocks. See <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>.</p><h2>Box sizes</h2><p>The box size sets how much of the included note is shown.</p><ul><li><em>Tiny</em> shows a single row instead of the content: the note's icon, its title with the path to the note above it, and buttons to act on the note. The included note is never rendered, so wherever the note is shown outside the editor, such as in print, in a tooltip or on a shared page, a <em>Tiny</em> include appears as a link to the included note.</li><li><em>Small</em> and <em>Medium</em> show the content in a box of limited height. Text scrolls inside the box, while a picture, a diagram or a video is scaled down to fit it.</li><li><em>Full</em> shows the whole content.</li><li><em>Expandable</em> shows only the title until its <span class=\"tn-icon bx bx-chevron-right\"></span> arrow is pressed. In a read-only note, a click anywhere on the title row other than its buttons and link expands or collapses it as well.</li></ul><p>A new include gets the size that suits what it shows:</p><ul><li><em>Tiny</em> for a note or an attachment that has no preview, such as a relation map or an archive.</li><li><em>Small</em> for audio.</li><li><em>Full</em> for a code note or a code file, such as a <code>.js</code>, <code>.py</code> or <code>.txt</code> attachment, and for an excerpt of the blocks of a text note.</li><li><em>Medium</em> for anything else.</li></ul><p>The <em>Include note</em> dialog selects that size among its <em>Box size</em> buttons once the note is picked, and you can choose another one there. To change the size later, select the include and use the <em>Box size</em> menu in its toolbar, or the <em>Size</em> submenu of its <em>More actions</em> menu. For an included code or Markdown note and an embedded code or Markdown file, the <em>Box size</em> menu is the <span class=\"tn-icon bx bx-move-vertical\"></span> button, whose tooltip names the current size.</p><h2>Resizing</h2><p>A <em>Small</em>, <em>Medium</em> or <em>Expandable</em> include can be resized to any width and height. A <em>Tiny</em> or <em>Full</em> include always fits its content.</p><ul><li>To resize an include, select it and drag the handle in its bottom-right corner. To change only the width or only the height, drag the middle of its right or bottom edge instead, where a touch screen shows a handle too. In right-to-left text, the handle is in the bottom-left corner and the width changes from the left edge.</li><li>Resizing works with a mouse, a pen or a finger.</li><li>While the height changes, moving the handle near the top or the bottom of the note scrolls the note.</li><li>An include narrower than the note is centered, so changing its width moves both of its sides. A drawing aligned to the left or the right keeps that side in place and has its handles on the other side (see <em>Positioning a drawing</em> below). Making an include as wide as the note returns it to the full width.</li><li>To cancel a resize, press <kbd>Esc</kbd> before releasing the handle.</li><li>To reset the size, double-click the corner handle, or double-tap it on a touch screen. Double-clicking the right or bottom edge resets only the width or the height.</li><li>Choosing a box size resets the height. Choosing <em>Tiny</em> or <em>Full</em> resets the width too.</li><li>While an <em>Expandable</em> include is collapsed, only its width can be changed.</li></ul><h2>Caption</h2><p>An include can have a caption, shown centered at the bottom of its box. The caption is part of the text note, so it can be formatted like the rest of the text, for example in bold or with a link.</p><ul><li>To add a caption, select the include, press the <span class=\"tn-icon cke cke-caption\"></span> <em>Toggle caption on</em> button in its toolbar and type the caption. While the cursor is in the caption, the include stays selected and keeps its toolbar.</li><li>To remove the caption, press the same button again. Pressing it once more brings back the text it had, as long as the note stays open.</li><li>A <em>Tiny</em> include has no caption. Switching an include to <em>Tiny</em> removes its caption, and switching it back to a larger size restores the caption, as long as the note stays open.</li><li>An <em>Expandable</em> include shows its caption under the title while the content is collapsed, and under the content once it is expanded.</li></ul><h2>Title</h2><p>The title row of an include links to the included note and holds its buttons. To show only the content, select the include and press the <span class=\"tn-icon bx bx-window-alt\"></span> <em>Show title</em> button in its toolbar. Pressing it again shows the title.</p><ul><li>While the title is hidden, the <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> button in the toolbar of the include opens the menu of the included note.</li><li>A <em>Tiny</em> or <em>Expandable</em> include always shows its title, and its toolbar has no <em>Show title</em> button.</li></ul><h2>Opening an included note</h2><p>To open an included note in a new tab, press the <span class=\"tn-icon bx bx-link-external\"></span> <em>Open in new tab</em> button at the end of its title. An embedded attachment has the same button.</p><p>The <span class=\"tn-icon bx bx-dots-vertical-rounded\"></span> <em>More actions</em> button at the end of the title row opens the same menu as right-clicking anywhere on the title row: the other places to open the note in and, for an embedded attachment, the actions on the attachment.</p><p>In a note being edited, the menu also has the commands of the include's toolbar: the <em>Size</em> submenu, <em>Show title</em> and <em>Show caption</em>, each checked while it is in effect, and <em>Convert to link</em> at the end. A drawing canvas, a Mermaid diagram, an included text, code or Markdown note and an embedded code or Markdown file also have <em>Editable</em>, above <em>Size</em>. An included code or Markdown note, an embedded code or Markdown file and a Mermaid diagram also have the <em>Word wrap</em> and <em>Line numbers</em> submenus after <em>Editable</em> (see <em>Editing an include in place</em> below). A Mermaid diagram, an included Markdown note and an embedded Markdown file also have <em>Source view</em>, <em>Split view</em> and <em>Preview</em> after these submenus. For an embedded attachment they follow its first group of actions; for an included note they end the menu.</p><p>To show an include of size <em>Medium</em> or <em>Full</em> on the whole screen, press the <span class=\"tn-icon bx bx-fullscreen\"></span> <em>Fullscreen</em> button at the end of its title. An excerpt of the blocks of a note has an <span class=\"tn-icon bx bx-pencil\"></span> <em>Edit excerpt</em> button there instead; see <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>. To return, press <span class=\"tn-icon bx bx-exit\"></span> <em>Exit fullscreen</em> in the top-right corner, or <kbd>Esc</kbd>.</p><p>A <em>Tiny</em> include has these buttons instead, followed by the same <em>More actions</em> button:</p><ul><li>For a note, <span class=\"tn-icon bx bx-edit\"></span> <em>Quick edit</em> opens the note in <a class=\"reference-link\" href=\"#root/_help_ZjLYv08Rp3qC\">Quick edit</a>, and <span class=\"tn-icon bx bx-link-external\"></span> <em>Open in new tab</em> opens it in a new tab.</li><li>For an embedded attachment, <span class=\"tn-icon bx bx-file-find\"></span> <em>Open externally</em> opens the file in another application, and <span class=\"tn-icon bx bx-download\"></span> <em>Download</em> downloads it. The size of the file is shown under its title.</li></ul><h2>Converting an include to a link</h2><p>To replace an include with a link to the included note, select it and press the <span class=\"tn-icon cke cke-link\"></span> <em>Convert to link</em> button in its toolbar, or choose <em>Convert to link</em> at the end of its <em>More actions</em> menu. An embedded attachment turns into a link to the attachment the same way.</p><h2>Missing notes and attachments</h2><p>An include whose note or attachment no longer exists, for example because it was deleted, keeps its size and shows the <span class=\"tn-icon bx bx-error-alt\"></span> icon in place of the content, with the ID of the missing note or attachment. To remove the include, select it and press <kbd>Delete</kbd>.</p><p>Content added by a newer version of Trilium, which this version cannot show, appears the same way with the <span class=\"tn-icon bx bx-error\"></span> icon. Editing the note keeps that content unchanged, so it shows again once Trilium is updated.</p><h2>Included notes in the share functionality</h2><p>If a <a href=\"#root/_help_R9pX4DGra2Vt\">shared note</a> contains one or more included notes, they will be displayed in the content of the note as if they were part of the note itself. An include resized narrower than the note keeps its width, and a drawing its position. On a narrow screen, a drawing with a position other than <em>Align center</em> takes the full width. The caption of an include is shown under the included content. A <em>Tiny</em> include is shown as a link to the included note instead, and so is an include that would show a note already shown around it, such as a note that includes itself. The same goes for a printed or exported note.</p><p>For this to work, the included notes must also be shared. However, they can still be hidden from the note tree via <code>#shareHiddenFromTree</code>.</p><p>An include whose note or attachment is missing or not shared shows <em>This content is not available</em> in its place, and so does content added by a newer version of Trilium.</p><h2>Interactive notes</h2><p>Since v0.104.0, included notes might become interactive depending on their note type:</p><ul><li><a class=\"reference-link\" href=\"#root/_help_GTwFsgaA0lCt\">Collections</a> (e.g. <a class=\"reference-link\" href=\"#root/_help_81SGnPGMk7Xc\">Geo Map</a>) will render fully interactive, including creating new notes.</li><li><a class=\"reference-link\" href=\"#root/_help_m523cpzocqaD\">Saved Search</a> will also display the results.</li><li><a class=\"reference-link\" href=\"#root/_help_1vHRoWCEjj0L\">Web View</a> provides an interactive preview of the website.</li></ul><h2>Included images</h2><p>An included image, whether an image note or an image attachment, is shown in the image viewer, which zooms and pans it:</p><ul><li>To zoom, press the <span class=\"tn-icon bx bx-plus-circle\"></span> <em>Zoom in</em> and <span class=\"tn-icon bx bx-minus-circle\"></span> <em>Zoom out</em> buttons in the bottom-right corner of the image, or pinch on a touch screen. The percentage between them resets the zoom.</li><li>To zoom with the mouse wheel, click the image first. Until then, the mouse wheel scrolls the note.</li><li>To pan an image that is zoomed in, drag it. At its fitted size, dragging the image on a touch screen scrolls the note.</li><li>To return to the fitted size, double-click the image.</li></ul><p>In a <em>Small</em> or <em>Medium</em> box, the image is scaled down to fit the height of the box. In fullscreen, it fits the screen.</p><h2>Editing an include in place</h2><p>An included text note, an included code note and an embedded code file such as a <code>.js</code>, <code>.py</code> or <code>.txt</code> attachment can be edited without leaving the note that includes them. Until then, a code note or file is shown read-only in the code editor, where its code can be selected and copied, and its blocks folded and unfolded with the arrows in its gutter. Included Markdown can be edited too, see <em>Included Markdown</em> below.</p><ul><li>To edit, select the include and turn on the <span class=\"tn-icon bx bx-edit-alt\"></span> <em>Editable</em> button at the start of its toolbar, or check <em>Editable</em> in its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu. Turn <em>Editable</em> off to stop editing.</li><li>While <em>Editable</em> is on, the arrow keys move the caret into the include and back out, as through the rest of the text. Entering from above or from the left puts the caret at the start of the include, and entering from below or from the right puts it at the end. A collapsed <em>Expandable</em> include is skipped.</li><li>While an included text note has the focus, the formatting toolbar applies to it. The notes it includes in turn stay read-only.</li><li>Code is edited in the same code editor as a <a class=\"reference-link\" href=\"#root/_help_6f9hih2hXXZk\">Code</a> note, with its theme, indentation and line wrapping settings.</li><li>Typing <code>/</code> in the code lists the <a class=\"reference-link\" href=\"#root/_help_IEgsWp5hHH35\">Code Snippets</a> of its language, as in a code note.</li><li>The toolbar of an included code note or an embedded code file also has the language and indentation menus of the <a class=\"reference-link\" href=\"#root/_help_AlJ73vBCjWDw\">Status bar</a>, between <em>Editable</em> and the <span class=\"tn-icon bx bx-move-vertical\"></span> <em>Box size</em> menu: <em>Change language mode</em>, which shows the current language, and <em>Change tab width</em>, which shows the current indentation. <em>Re-indent content to</em> converts the indentation of the code itself and saves it to the included note or file, whether <em>Editable</em> is on or off.<ul><li>For an included note, the menus change the note, as they do in its own tab.</li><li>For an embedded code file, the language and indentation settings change only how this include shows the file, and are saved with the note that includes it. The language replaces the one that the file name gives, and the <em>Use default</em> entries return to the indentation set in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. These settings leave the file itself unchanged, and other includes of it keep their own settings.</li></ul></li><li>The <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu of an included code or Markdown note, an embedded code or Markdown file and a <a href=\"#root/_help_CohkqWQC1iBv\">Mermaid diagram</a> has two more submenus after <em>Editable</em>, each with <em>Auto</em>, <em>On</em> and <em>Off</em>. They change how the code editor shows the source.<ul><li><em>Word wrap</em> wraps long lines instead of scrolling them. <em>Auto</em> follows the setting in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. For an included note, it sets the <code>#wrapLines</code> label of the note, as the <em>Word wrap</em> submenu of its <a class=\"reference-link\" href=\"#root/_help_8YBEPzcpUgxw\">Note menu</a> does for a code note. For an embedded file or a Mermaid diagram, it changes only this include.</li><li><em>Line numbers</em> shows or hides the numbers at the start of each line. <em>Auto</em> follows the setting in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Code Notes</em>. It changes only this include, for an included note as well.</li></ul></li><li>The changes are saved as you type, to the included note or to the attachment, as they would be in its own tab.</li><li>The changes made in the code editor of an include are part of the undo history of the note that includes it, together with the changes to its text, in the order they were made. This includes the source of included Markdown and of a <a href=\"#root/_help_CohkqWQC1iBv\">Mermaid diagram</a>, and the changes to a drawing canvas (see below).<ul><li><kbd>Ctrl</kbd>+<kbd>Z</kbd> undoes the last change of the note, and <kbd>Ctrl</kbd>+<kbd>Y</kbd> or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Z</kbd> redoes it, whether the caret is in the text or in an include, and also while <em>Editable</em> is off. The <span class=\"tn-icon cke cke-undo\"></span> <em>Undo</em> and <span class=\"tn-icon cke cke-redo\"></span> <em>Redo</em> buttons of the formatting toolbar do the same. With the Vim key bindings, <code>u</code> and <kbd>Ctrl</kbd>+<kbd>R</kbd> in an include do the same too.</li><li>The focus moves to the change that was undone or redone: into the code editor or the drawing canvas of the include, or back to the text.</li><li>Undoing a change of an included note saves the included note again. Once the included note has been changed elsewhere, for example in another tab, its earlier changes can no longer be undone from here, and undo skips them.</li><li>An included text note keeps an undo history of its own.</li></ul></li><li>An include of <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a> edits only the referenced blocks.</li><li>Editing is not available in a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, for an included note marked <code>#readOnly</code>, or for an attachment of another note.</li><li><a class=\"reference-link\" href=\"#root/_help_McngOG2jbUWX\">Search in note</a> finds the text of included text and code notes among the results of the note around them, and replaces it while <em>Editable</em> is on.</li></ul><h2>Included Markdown</h2><p>An included <a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a> note and an embedded Markdown file, such as a <code>.md</code> attachment, are shown with the same three views as a Markdown note in its own tab (see <a class=\"reference-link\" href=\"#root/_help_SL5f1Auq7sVN\">Note types with split view</a>): <span class=\"tn-icon bx bx-code\"></span> <em>Source view</em>, <span class=\"tn-icon bx bxs-dock-left\"></span> <em>Split view</em> and <span class=\"tn-icon bx bx-show\"></span> <em>Preview</em>.</p><ul><li>To switch the view, press one of the three buttons in the title row of the include. In a note being edited, the toolbar of the include has the same buttons after <em>Editable</em>, and its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu has them as <em>Source view</em>, <em>Split view</em> and <em>Preview</em>.</li><li>Until a view is chosen, the include shows the <em>Preview</em>, and the <em>Split view</em> while <em>Editable</em> is on.</li><li>To edit the Markdown, turn on <em>Editable</em> (see <em>Editing an include in place</em> above). The source is edited in the code editor of a Markdown note, and the preview follows the changes as you type. While <em>Editable</em> is off, the source can be read and copied but not changed.</li><li>The source has the slash commands and the <code>@</code> and <code>[[</code> note links of a <a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a> note. A note created from the <code>@</code> or <code>[[</code> list goes under the included note, or for an embedded file under the note that includes it, and <code>/image</code> uploads the image to that same note.</li><li>The <em>Word wrap</em> and <em>Line numbers</em> submenus of the <em>More actions</em> menu change how the source shows, as for code (see <em>Editing an include in place</em> above).</li><li>As in a Markdown note, the preview scrolls along with the source and highlights the block where the cursor is, and <kbd>Ctrl</kbd>+<kbd>B</kbd>, <kbd>Ctrl</kbd>+<kbd>I</kbd>, <kbd>Ctrl</kbd>+<kbd>M</kbd> and <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>X</kbd> format the selection.</li><li>In a note being edited, the view is saved with the include, so two includes of the same note can show different views. In a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, the view can be changed too, until the note is opened again.</li><li>While the source shows, and wherever the Markdown can be edited, the include has the height of its box size, or the height it was resized to, so turning <em>Editable</em> on or off keeps its size. Otherwise, as in a read-only note, the preview fits its text up to that height. A <em>Full</em> include fits its content instead.</li><li><a class=\"reference-link\" href=\"#root/_help_McngOG2jbUWX\">Search in note</a> searches the source while it shows, and the preview otherwise.</li></ul><h2>Drawing canvases</h2><p>A drawing canvas is an Excalidraw canvas, like the one of a <a class=\"reference-link\" href=\"#root/_help_grjYqerjn243\">Canvas</a> note, drawn directly in the text note. It is not a note of its own: the drawing is kept in a <code>Canvas.excalidraw</code> <a href=\"#root/_help_0vhv7lsOLy82\">attachment</a> of the text note and is saved together with the text.</p><ul><li>To insert a drawing canvas, open the <span class=\"tn-icon cke cke-plus\"></span> <em>Insert</em> menu of the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a> and choose <span class=\"tn-icon bx bx-pen\"></span> <em>Drawing canvas</em>, above <em>Mermaid diagram</em>. It is also available as <em>Drawing canvas</em> in the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>. The canvas is added empty and editable, in a <em>Medium</em> box with its title hidden, and takes the focus, ready for drawing.</li><li>To draw or write over an image, select the image and press the <span class=\"tn-icon bx bxs-pen\"></span> <em>Convert image to a drawing canvas</em> button of its toolbar. The image is replaced by an editable drawing canvas in a <em>Medium</em> box, with its title hidden and the focus in it. The image sits at its original size in the middle of the canvas, zoomed so that all of it shows, and is locked so that it cannot be selected or moved by accident. While it is locked, the canvas can be zoomed in on the image but not zoomed out past it or scrolled beyond its edges. To move or resize the image anyway, right-click it and choose <em>Unlock</em>. The caption of the image is kept, but not its alignment or link. Only an image on its own line can be converted, not one inside a paragraph. Undo brings the image back.</li><li>An Excalidraw file (<code>.excalidraw</code>) attached with <em>Attach and embed file</em>, under the <span class=\"tn-icon cke cke-paper-clip\"></span><em>Attach file</em> button, becomes a drawing canvas too, in a <em>Medium</em> box titled with the file name. It starts with <em>Editable</em> off, so the drawing shows but cannot be changed until <em>Editable</em> is turned on (see below).</li><li>To draw on a canvas that does not have the focus, click it first. Until then, touch gestures scroll the note. The canvas then has the tools, menus and keyboard shortcuts of a Canvas note. The toolbars, the menus and the properties of the selected shapes show only while the canvas has the focus, so elsewhere the drawing reads like a picture in the text.</li><li>The mouse wheel and the touchpad scroll the note over a canvas too, as over the text. To zoom, use the zoom buttons of the canvas toolbar; to move around the drawing, use the <span class=\"tn-icon bx bxs-hand\"></span> <em>Hand</em> tool. In fullscreen, the mouse wheel moves and zooms the drawing instead.</li><li>The canvas toolbar replaces the Excalidraw menu: <em>Export image</em>, <em>Find on canvas</em>, <em>Library</em> and <em>Help</em> are at the end of its <span class=\"tn-icon bx bx-category\"></span> <em>More tools</em> menu. In fullscreen, the Excalidraw menu shows again.</li><li>The changes to the drawing are part of the undo history of the text note (see <em>Editing an include in place</em> above). <kbd>Ctrl</kbd>+<kbd>Z</kbd>, <kbd>Ctrl</kbd>+<kbd>Y</kbd> and the <span class=\"tn-icon bx bx-undo\"></span> <em>Undo</em> and <span class=\"tn-icon bx bx-redo\"></span> <em>Redo</em> buttons of the canvas toolbar undo and redo the last change of the note, in the drawing or in the text.</li><li>A new drawing has the background color of the note. A background chosen from the Excalidraw menu replaces it.</li><li>To protect a finished drawing from accidental changes, select it and turn off the <span class=\"tn-icon bx bx-edit-alt\"></span> <em>Editable</em> button at the start of its toolbar, or uncheck <em>Editable</em> in its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu. The drawing then shows as a still picture, at the zoom and position it had, and can no longer be changed, zoomed or moved. To draw again, turn <em>Editable</em> back on.</li><li>The box sizes, resizing, the caption and the title work as for an included note, but the toolbar of a drawing leaves the box size, <em>Show title</em> and <em>Convert to link</em> to its <em>More actions</em> menu, which also sets its position (see <em>Positioning a drawing</em> below).</li><li>In the desktop layout, Excalidraw keeps its desktop interface however small the box is. In the mobile layout, a narrow or short box switches it to a compact interface. For more room, choose <em>Full</em>, or show the title and press <span class=\"tn-icon bx bx-fullscreen\"></span> <em>Fullscreen</em>.</li><li>Pictures added to the drawing are stored in the same attachment. A converted image is kept as an image attachment of the note instead, named with a generated code.</li><li>In a <a href=\"#root/_help_CoFPLs3dRlXc\">read-only note</a>, the drawing shows as a still picture too.</li><li>On a <a href=\"#root/_help_R9pX4DGra2Vt\">shared page</a>, the drawing is shown as a picture at its own size, up to the width its box was resized to, in light or dark colors to match the page. Each change to the drawing saves this picture as an SVG image attachment of the note, also named with a generated code, which the list of attachments shows under <em>Generated by Trilium</em>.</li></ul><h3>Positioning a drawing</h3><p>A drawing can sit on lines of its own or have the text wrap around it, as an <a href=\"#root/_help_mT0HEkOsz6i1\">image</a> can.</p><ul><li>To change the position, select the drawing, open its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu and choose an entry of its <em>Position</em> submenu:<ul><li>Under <em>Break text</em>, <span class=\"tn-icon cke cke-object-left\"></span> <em>Align left</em>, <span class=\"tn-icon cke cke-object-center\"></span> <em>Align center</em> and <span class=\"tn-icon cke cke-object-right\"></span> <em>Align right</em> place the drawing on lines of its own, at that side of the note. <em>Align center</em> is the default.</li><li>Under <em>Wrap text</em>, <span class=\"tn-icon cke cke-object-inline-left\"></span> <em>Align left</em> and <span class=\"tn-icon cke cke-object-inline-right\"></span> <em>Align right</em> place the drawing at that side and let the text run beside it.</li></ul></li><li>A drawing is inserted at the full width of the note, so a new position shows once the drawing is resized narrower (see <em>Resizing</em> above). The position is kept whatever the box size, and shows again when a <em>Small</em>, <em>Medium</em> or <em>Expandable</em> box is resized.</li><li>In the mobile layout, a drawing with a position other than <em>Align center</em> takes the full width, and only its height can be resized.</li></ul><h3>Limitations</h3><ul><li>The Excalidraw shape library is not saved for a drawing canvas.</li><li>Outside the editor, for example in a tooltip, when printing or in the list of attachments, the drawing is shown as a picture.</li><li>A drawing has no picture for shared pages until its first change, except one converted from an image. Until then, for example for an attached <code>.excalidraw</code> file, a shared page shows a link to download the drawing instead.</li><li>In Safari, the picture of a drawing on a shared page follows the light or dark appearance of the system rather than the theme chosen on the page.</li><li>A copy of a drawing canvas pasted in the same note shares the drawing with the original, so a change to one shows in the other only after the note is opened again. A copy pasted in another note gets a drawing of its own.</li></ul>","_help_CohkqWQC1iBv": "<p>Press the <span class=\"tn-icon cke cke-plus\"></span> button in the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a> to reveal special inserable items and blocks such as symbols, Math expressions and separators.</p><h2>Bookmarks</h2><p>See the dedicated <a class=\"reference-link\" href=\"#root/_help_oSuaNgyyKnhu\">Anchors</a> section.</p><h2>New child note</h2><p>Choose <span class=\"tn-icon bx bx-subdirectory-right\"></span> <em>New child note</em> to create an empty child note of the current note and insert a link to it at the cursor. The new note opens in <a class=\"reference-link\" href=\"#root/_help_ZjLYv08Rp3qC\">Quick edit</a> with its title selected, so typing names it, and the link shows the new title. While the note is still empty, Quick edit offers the note types to turn it into.</p><p>The same action is available as <em>Create a new child note</em> in the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>. A child note of a protected note is protected too.</p><h2>Emoji</h2><figure class=\"image image-style-align-right image_resized\" style=\"width:42.4%;\"><img style=\"aspect-ratio:366/410;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Insert%20buttons_plus.png\" width=\"366\" height=\"410\"></figure><p>This feature allows inserting Unicode emoji characters. Simply select a category and a desired emoji to insert it.</p><p>Emojis can also be searched by their English name and the skin tone can be selected via a combo box to the right.</p><p>There is also the possibility of inserting emojis directly by typing <code>:</code> followed by a name of an emoji, triggering the display of a list of emojis. Simply use the arrow keys to select one and press <kbd>Enter</kbd> or <kbd>Tab</kbd> to insert it.</p><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Insert%20buttons_plus.png\" width=\"272\" height=\"187\"><h2>Symbols</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:346/322;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Insert%20buttons_image.png\" width=\"346\" height=\"322\"></figure><p>Pressing the <span class=\"tn-icon cke cke-special-characters\"></span> button will reveal a popup window displaying a list of characters that are generally more difficult to insert directly from the keyboard, such as a subset of emojis, quotation characters, etc.</p><p>Interaction:</p><ul><li>Click on a character to insert it at the current cursor position.</li><li>The window can be dragged around by the top bar where the title is, to avoid it getting in the way of the text.</li><li>Click on the <em>Category</em> selector to filter the characters.</li></ul><h2>Multicolumn layout</h2><p>See the dedicated <a class=\"reference-link\" href=\"#root/_help_wYDzQ1fBFgfT\">Multicolumn layout</a> page.</p><h2>Extended code block</h2><p>Choose <span class=\"tn-icon bx bx-code-block\"></span> <em>Extended code block</em> to insert a code block that is edited as a code note. This entry is experimental and is shown only once it is turned on. See <em>Extended code blocks</em> in <a class=\"reference-link\" href=\"#root/_help_QxEyIjRBizuC\">Code blocks</a>.</p><h2>Math equations</h2><p>See the dedicated <a class=\"reference-link\" href=\"#root/_help_YfYAtQBcfo5V\">Math Equations</a> page.</p><h2>Drawing canvas</h2><p>Choose <span class=\"tn-icon bx bx-pen\"></span> <em>Drawing canvas</em> to draw on an Excalidraw canvas inside the text. See <em>Drawing canvases</em> in <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>.</p><h2>Mermaid diagram</h2><p>Press the <span class=\"tn-icon cke cke-trilium-mermaid-insert\"></span> button to create an inline Mermaid diagram. The arrow next to it lists a template for each kind of diagram. The diagram is also available as <em>Mermaid diagram</em> in the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>.</p><p>This feature is quite similar to the <a class=\"reference-link\" href=\"#root/_help_s1aBHPd79XYj\">Mermaid Diagrams</a> note types and is meant as an alternative to it for simple diagrams. For more complex diagrams, use the <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a> feature for a dedicated Mermaid note.</p><figure class=\"image\"><img style=\"aspect-ratio:1174/358;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_Insert%20buttons_image.png\" width=\"1174\" height=\"358\"></figure><p>A diagram shows in a box like the one of an included note, so it can be resized, given another box size (<em>Small</em>, <em>Medium</em> or <em>Full</em>) from its <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu or shown in fullscreen, as described in <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>.</p><ul><li>The <span class=\"tn-icon bx bx-edit-alt\"></span> <em>Editable</em> button at the start of the diagram's toolbar decides whether its source can be changed. While it is off, the source still shows, but read-only.</li><li>The buttons next to it choose what the diagram shows, as for a Mermaid note: <span class=\"tn-icon bx bx-code\"></span> <em>Source view</em> for the Mermaid source alone, <span class=\"tn-icon bx bxs-dock-left\"></span> <em>Split view</em> for the source with the diagram next to it, and <span class=\"tn-icon bx bx-show\"></span> <em>Preview</em> for the diagram alone. Its <em>More actions</em> menu offers the same choice.</li><li>The <em>Word wrap</em> and <em>Line numbers</em> submenus of its <em>More actions</em> menu change how the source shows, each with <em>Auto</em>, <em>On</em> and <em>Off</em>, as for an included code note (see <em>Editing an include in place</em> in <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>).</li><li>A new diagram starts editable, in <em>Split view</em>. The diagram updates a moment after you stop typing. If the source has an error, the error shows over the last diagram that worked, which stays dimmed, as in a Mermaid note. On desktop, drag the divider between the source and the diagram to resize them.</li><li>A diagram without a chosen view shows the source next to the diagram while it is editable, and the diagram alone otherwise. In a read-only note, the source can never be changed. A read-only note and the AI chat show a diagram in the same box, in the view it was saved with, and with the zoom buttons over the diagram instead of in a toolbar. A <em>Medium</em> or <em>Full</em> diagram also has a <span class=\"tn-icon bx bx-fullscreen\"></span> <em>Fullscreen</em> button there, or over the source in the <em>Source</em> view.</li><li>To zoom, use the <span class=\"tn-icon bx bx-zoom-out\"></span> and <span class=\"tn-icon bx bx-zoom-in\"></span> buttons of the diagram's toolbar; the zoom level between them resets the zoom. In fullscreen, where the toolbar is hidden, the same buttons show over the diagram. Drag the diagram to move around it, and double-click it to reset the view. The mouse wheel scrolls the note until you click the diagram, and then zooms it.</li><li>While the source shows, the <span class=\"tn-icon bx bx-help-circle\"></span> <em>Mermaid syntax help</em> button at the end of the toolbar opens the help on <a class=\"reference-link\" href=\"#root/_help_s1aBHPd79XYj\">Mermaid Diagrams</a>, which links to the Mermaid syntax.</li><li>The changes made to the source of a diagram are part of the undo history of the text note, in the order they were made. <kbd>Ctrl</kbd>+<kbd>Z</kbd> and <kbd>Ctrl</kbd>+<kbd>Y</kbd> undo and redo them from the source as well as from the text, as described in <em>Editing an include in place</em> in <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>.</li></ul><p>The source of the diagram stays in the note as a Mermaid code block, so the diagram is exported to Markdown as a <code>mermaid</code> code block that other applications can show.</p><p>Diagrams created in earlier versions keep the view they were saved with, and open editable.</p><h2>YouTube video</h2><p>Choose <span class=\"tn-icon bx bxl-youtube\"></span> <em>YouTube video</em> to insert a YouTube video that can be watched inside the note. Paste the address of the video, then press <em>Insert video</em> or <kbd>Enter</kbd>. The video is inserted as a link preview in the <em>Embed</em> display mode, described in <a class=\"reference-link\" href=\"#root/_help_UmgZAfcltxkS\">Link Previews</a>. The same action is available as <em>Insert YouTube video</em> in the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>.</p><h2>Horizontal ruler</h2><p>This feature will display a horizontal line, generally useful to separate different sections of the text. To do so, press the <span class=\"tn-icon cke cke-horizontal-line\"></span> button in the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>.</p><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Insert%20buttons_image.png\" width=\"502\" height=\"95\"><p>Alternatively, it's possible to insert a horizontal ruler by typing <code>---</code>.</p><h2>Page break</h2><figure class=\"image image-style-align-right\"><img style=\"aspect-ratio:371/79;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/3_Insert%20buttons_image.png\" width=\"371\" height=\"79\"></figure><p>Page breaks provide a way to force the next paragraph or block (table, image, etc.) to be displayed onto the next page when printing (either to a real printer to <a href=\"#root/_help_NRnIZmSMc5sj\">when exporting to PDF</a>).</p><p>Page breaks are marked in the editor with the words <em>Page break</em>, but they will not actually be shown when printed.</p><ul><li>To insert a page break, press the <span class=\"tn-icon cke cke-page-break\"></span> in the formatting toolbar.</li><li>To insert many page breaks at once, insert a page break first, click on it and press <kbd>Ctrl</kbd>+<kbd>C</kbd>. Then use <kbd>Ctrl</kbd>+<kbd>V</kbd>, to paste as many times as needed.</li></ul><h2>Date and time</h2><p>The <span class=\"tn-icon cke cke-trilium-date-time\"></span> button inserts the current date and time at the cursor, replacing the selected text if there is any. The inserted text takes the formatting of the text around it, so a date inserted inside bold text is bold too.</p><ul><li>To insert the date in the default format, press the button itself or press <kbd>Alt</kbd>+<kbd>T</kbd>.</li><li>To insert it in another format, press the arrow next to the button and pick a format from the list. Each entry shows the current date and time in that format: the default one, the date or the time alone, the date written out, and ISO 8601.</li><li>The same formats are offered by the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>: type <code>/date</code>, <code>/time</code>, <code>/now</code> or <code>/today</code>. The <em>Insert date/time</em> entry uses the default format, and shows what it inserts underneath; the other entries show their output in the title.</li></ul><p>The default format can be changed in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Text Notes</em> → <em>Editor</em> → <em>Date/time format</em>, using <a href=\"https://day.js.org/docs/en/display/format\">Day.js format tokens</a> (for example <code>DD.MM.YYYY HH:mm</code>).</p><h2>Icons</h2><p>Icons just like the ones for the <a href=\"#root/_help_p9kXRFAkwN4o\">note icon</a> can be inserted in text. For more information see <a class=\"reference-link\" href=\"#root/_help_hD8GawVuazff\">Icons</a>.</p>","_help_hD8GawVuazff": "<p>Icons just like the <a href=\"#root/_help_hD8GawVuazff\">note icons</a> can be inserted in the content of a note, including from any other <a href=\"#root/_help_gOKqSJgXLcIj\">custom icon packs</a>.</p><h2>Features</h2><ul><li>The icon can be formatted through the<a class=\"reference-link\" href=\"#root/_help_Gr6xFaF6ioJ5\">General formatting</a> tools of the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>:<ul><li>Foreground/icon color</li><li>Background color/highlight</li><li>Font size</li></ul></li><li>Custom <a class=\"reference-link\" href=\"#root/_help_gOKqSJgXLcIj\">Icon Packs</a> are also supported.<ul><li>For emojis, prefer the Emoji functionality from <a class=\"reference-link\" href=\"#root/_help_CohkqWQC1iBv\">Insert buttons</a>.</li></ul></li><li>When an icon is clicked a floating toolbar appears with the following functions:<ul><li><span class=\"tn-icon bx bx-sticker\"></span> which changes the icon.</li><li><span class=\"tn-icon bx bx-reflect-horizontal\"></span> which applies transforms: rotate (90 / 180 / 270) and flip horizontal/vertical. Only one transform can be used per icon.</li></ul></li></ul><h2>Usage</h2><ul><li>The in-app help/user guide makes use of these icons in order to illustrate buttons in the UI.</li><li>The <a class=\"reference-link\" href=\"#root/_help_GnhlmrATVqcH\">Microsoft OneNote</a> importer also makes use of them for the <a class=\"reference-link\" href=\"#root/_help_LpvyEIBIAAj7\">Tags</a>.</li></ul><h2>Inserting an icon</h2><p>There are two ways to insert an icon:</p><ul><li>Via the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a> look for the <span class=\"tn-icon bx bx-plus\"></span> icon and then the <span class=\"tn-icon bx bx-sticker\"></span> icon.</li><li>Via <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>, type <code>/icon</code>.</li></ul><p>An icon picker will appear, search for an icon and click it to insert it in the document.</p><h2>Finding notes by their icons</h2><p>An icon can be <a href=\"#root/_help_eIg8jdvaoNNd\">searched</a>. A note containing a <span class=\"tn-icon bx bx-star\"></span> icon can be found by searching for <code>star</code>, or its <code>iconClass</code> (<code>bx-star</code>).</p><p>To find the name of the icon, hover the mouse over an icon while in the icon picker.</p><h2>Markdown rendering</h2><p>When exporting to <a class=\"reference-link\" href=\"#root/_help_Oau6X9rCuegd\">Markdown</a>, the item will render as raw HTML representation of the icon as is used by Trilium:</p><pre><code class=\"language-text-html\"><span class=\"tn-icon bx bx-star\"></span></code></pre>","_help_oiVPnW8QfnvS": "<h2>Trilium-specific shortcuts</h2><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Bring up inline formatting toolbar (arrow keys ←,→ to navigate, Enter to apply)</td><td>Alt+F10</td><td>⌥+F10</td></tr><tr><td>Bring up block formatting toolbar</td><td>Alt+F10</td><td>⌥+F10</td></tr><tr><td>Create <a href=\"#root/_help_QEAPj01N5f7w\">external link</a></td><td>Ctrl+K</td><td>⌘+K</td></tr><tr><td>Create <a href=\"#root/_help_QEAPj01N5f7w\">internal (note) link</a></td><td>Ctrl+L</td><td>⌘+L</td></tr><tr><td>Inserts current date and time at caret position</td><td>Alt+T</td><td>⌥+T</td></tr><tr><td>Increase paragraph indentation</td><td>Tab</td><td>⇥</td></tr><tr><td>Decrease paragraph indentation</td><td>Shift + Tab</td><td>⇧ + ⇥</td></tr><tr><td>Mark selected text as <a href=\"#root/_help_UYuUB1ZekNQU\">keyboard shortcut</a></td><td>Ctrl + Alt + K</td><td>⌘+ ⌥+ K</td></tr><tr><td>Insert <a class=\"reference-link\" href=\"#root/_help_YfYAtQBcfo5V\">Math Equations</a></td><td>Ctrl + M</td><td>⌘+ M</td></tr><tr><td>Move blocks (lists, paragraphs, etc.) up, or in a <a href=\"#root/_help_NdowYOC1GFKS\">table</a> the rows</td><td>Alt+↑</td><td>⌥+↑</td></tr><tr><td>Move blocks (lists, paragraphs, etc.) down, or in a <a href=\"#root/_help_NdowYOC1GFKS\">table</a> the rows</td><td>Alt+↓</td><td>⌥+↓</td></tr><tr><td>Move the selected content to another column of a <a class=\"reference-link\" href=\"#root/_help_wYDzQ1fBFgfT\">Multicolumn layout</a></td><td>Ctrl+←, Ctrl+→, Ctrl+Shift+Home, Ctrl+Shift+End</td><td>⌘+←, ⌘+→, ⌘+⇧+Home, ⌘+⇧+End</td></tr><tr><td>Move the current column of a multicolumn layout</td><td>Ctrl+Alt+←, Ctrl+Alt+→, Ctrl+Alt+Home, Ctrl+Alt+End</td><td>⌘+⌥+←, ⌘+⌥+→, ⌘+⌥+Home, ⌘+⌥+End</td></tr><tr><td>Add a column after or before the current one in a multicolumn layout</td><td>Ctrl+Enter, Ctrl+Shift+Enter</td><td>⌘+Enter, ⌘+⇧+Enter</td></tr><tr><td>Move the selected content to another tab in <a class=\"reference-link\" href=\"#root/_help_EK2ckIZ74tbT\">Content tabs</a></td><td>Ctrl+←, Ctrl+→, Ctrl+Shift+Home, Ctrl+Shift+End</td><td>⌘+←, ⌘+→, ⌘+⇧+Home, ⌘+⇧+End</td></tr><tr><td>Move the current tab of a tabs block</td><td>Ctrl+Alt+←, Ctrl+Alt+→, Ctrl+Alt+Home, Ctrl+Alt+End</td><td>⌘+⌥+←, ⌘+⌥+→, ⌘+⌥+Home, ⌘+⌥+End</td></tr><tr><td>Add a tab after or before the current one in a tabs block</td><td>Ctrl+Enter, Ctrl+Shift+Enter</td><td>⌘+Enter, ⌘+⇧+Enter</td></tr></tbody></table></figure><h2>Common shortcuts</h2><aside class=\"admonition tip\"><p>This section of keyboard shortcuts presents a subset of the keyboard shortcuts as supported by the editor technology we are using, <a class=\"reference-link\" href=\"#root/_help_MI26XDLSAlCD\">CKEditor</a>. The shortcuts were taken from the <a href=\"https://ckeditor.com/docs/ckeditor5/latest/features/accessibility.html#keyboard-shortcuts\">official documentation</a>. Note that not all the shortcuts in the original documentation are applicable (due to using a different configuration).</p></aside><h3>Content editing</h3><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Insert a hard break (a new paragraph)</td><td>Enter</td><td></td></tr><tr><td>Insert a soft break (a <code><br></code> element)</td><td>Shift+Enter</td><td>⇧Enter</td></tr><tr><td>Copy selected content</td><td>Ctrl+C</td><td>⌘C</td></tr><tr><td>Paste content</td><td>Ctrl+V</td><td>⌘V</td></tr><tr><td>Paste content as plain text</td><td>Ctrl+Shift+V</td><td>⌘⇧V</td></tr><tr><td>Undo</td><td>Ctrl+Z</td><td>⌘Z</td></tr><tr><td>Redo</td><td>Ctrl+Y, Ctrl+Shift+Z</td><td>⌘Y, ⌘⇧Z</td></tr><tr><td>Bold text</td><td>Ctrl+B</td><td>⌘B</td></tr><tr><td>Change text case</td><td>Shift+F3</td><td>⇧F3 (may require Fn)</td></tr><tr><td>Create link</td><td>Ctrl+K</td><td>⌘K</td></tr><tr><td>Move out of a link</td><td>←←, →→</td><td></td></tr><tr><td>Move out of an inline code style</td><td>←←, →→</td><td></td></tr><tr><td>Select all</td><td>Ctrl+A</td><td>⌘A</td></tr><tr><td>Find in the document</td><td>Ctrl+F</td><td>⌘F</td></tr><tr><td>Copy text formatting</td><td>Ctrl+Shift+C</td><td>⌘⇧C</td></tr><tr><td>Paste text formatting</td><td>Ctrl+Shift+V</td><td>⌘⇧V</td></tr><tr><td>Italic text</td><td>Ctrl+I</td><td>⌘I</td></tr><tr><td>Strikethrough text</td><td>Ctrl+Shift+X</td><td>⌘⇧X</td></tr><tr><td>Underline text</td><td>Ctrl+U</td><td>⌘U</td></tr><tr><td>Revert autoformatting action</td><td>Backspace</td><td></td></tr></tbody></table></figure><h3>Interacting with blocks</h3><p>Blocks are images, tables, blockquotes, annotations.</p><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Insert a new paragraph directly after a widget</td><td>Enter</td><td></td></tr><tr><td>Insert a new paragraph directly before a widget</td><td>Shift+Enter</td><td>⇧Enter</td></tr><tr><td>Move the caret to allow typing directly before a widget</td><td>↑, ←</td><td></td></tr><tr><td>Move the caret to allow typing directly after a widget</td><td>↓, →</td><td></td></tr><tr><td>After entering a nested editable, move the selection to the closest ancestor widget. For example: move from an image caption to the whole image widget.</td><td>Tab then Esc</td><td></td></tr></tbody></table></figure><p>Specifically for lists:</p><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Increase list item indent</td><td>⇥</td><td></td></tr><tr><td>Decrease list item indent</td><td>Shift+⇥</td><td>⇧⇥</td></tr></tbody></table></figure><p>In tables:</p><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Move the selection to the next cell</td><td>⇥</td><td></td></tr><tr><td>Move the selection to the previous cell</td><td>Shift+⇥</td><td>⇧⇥</td></tr><tr><td>Insert a new table row (when in the last cell of a table)</td><td>⇥</td><td></td></tr><tr><td>Navigate through the table</td><td>↑, →, ↓, ←</td><td></td></tr></tbody></table></figure><h3>General UI shortcuts</h3><figure class=\"table\"><table><thead><tr><th>Action</th><th>PC</th><th>Mac</th></tr></thead><tbody><tr><td>Close contextual balloons, dropdowns, and dialogs</td><td>Esc</td><td></td></tr><tr><td>Open the accessibility help dialog</td><td>Alt+0</td><td>⌥0</td></tr><tr><td>Move focus between form fields (inputs, buttons, etc.)</td><td>⇥, Shift+⇥</td><td>⇥, ⇧⇥</td></tr><tr><td>Move focus to the toolbar, navigate between toolbars</td><td>Alt+F10</td><td>⌥F10 (may require Fn)</td></tr><tr><td>Navigate through the toolbar or menu bar</td><td>↑, →, ↓, ←</td><td></td></tr><tr><td>Navigate to the next focusable field or an element outside the editor</td><td>Tab, Shift+Tab</td><td></td></tr><tr><td>Execute the currently focused button. Executing buttons that interact with the editor content moves the focus back to the content.</td><td>Enter, Space</td><td></td></tr><tr><td>Move focus in and out of an active dialog window</td><td>Ctrl+F6</td><td>⌘F6 (may require Fn)</td></tr></tbody></table></figure>",- "_help_UmgZAfcltxkS": "<p>Link previews turn a pasted URL into a rich, metadata-aware widget that can be displayed in three visual modes:</p><h2>Display modes</h2><p>A link preview can be displayed in one of three modes:</p><ul><li><strong>Inline</strong> — a link showing the site's favicon and page title (quite similar to <a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a>). Use this when you want the link to flow with the surrounding paragraph.</li><li><strong>Card</strong> — a block-level preview with thumbnail, title, description, and site name. Use this when the link is the focus of a paragraph.</li><li><strong>Embed</strong> — a block-level interactive embed.<ul><li>Currently supported for YouTube videos, which render interactively (via an <code>iframe</code>).</li><li>To prevent unwanted remote requests, the video is shown only after clicking on it first. Until then, the video's thumbnail is shown with a play button.</li><li>The video can be resized and aligned (see <em>Videos</em> below).</li></ul></li></ul><div class=\"trilium-multicolumn-layout\" data-trilium-column-ratios=\"1-1-1\"><div class=\"trilium-multicolumn-column\"><figure class=\"image image_resized\" style=\"width:100%;\"><img style=\"aspect-ratio:251/42;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Link%20Previews_image.png\" width=\"251\" height=\"42\"><figcaption><em>Inline</em> link preview</figcaption></figure></div><div class=\"trilium-multicolumn-column\"><figure class=\"image image_resized\" style=\"width:100%;\"><img style=\"aspect-ratio:1217/196;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_Link%20Previews_image.png\" width=\"1217\" height=\"196\"><figcaption><em>Card</em> link preview</figcaption></figure></div><div class=\"trilium-multicolumn-column\"><figure class=\"image image_resized\" style=\"width:100%;\"><img style=\"aspect-ratio:994/563;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Link%20Previews_image.png\" width=\"994\" height=\"563\"><figcaption><em>Embed</em> link preview</figcaption></figure></div></div><h2>Inserting a link preview</h2><p>There are four ways to create one:</p><h3>1. By pasting a URL</h3><p>A link preview is automatically created:</p><ul><li>By pasting the URL and pressing <kbd>Space</kbd>. This will create an <em>inline</em> link preview.</li><li>When at the start of a new paragraph, pressing <kbd>Enter</kbd> will create a <em>card</em> or an <em>embed</em> for YouTube URLs.</li></ul><p>To undo an automatic link preview, press <kbd>Ctrl</kbd>+<kbd>Z</kbd> immediately afterwards which keeps it as a plain link instead. Alternatively, once a link preview was created, click on the link and select <em>Plain link</em> from the link preview toolbar.</p><p>This automatic conversion can be disabled by going to <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Text Notes</em> and unchecking <em>Autogenerate link previews</em> from the <em>Features</em> section.</p><p>If the link is not accessible to the Trilium server (or the network request fails for any other reason), it will not be converted to a link preview.</p><aside class=\"admonition note\"><p>A URL is only auto-converted when the pasted text <em>is</em> the URL. Links with a display name (e.g. <a href=\"https://triliumnotes.org\">Trilium Notes website</a>) are left as plain links.</p></aside><h3>2. From the link dialog</h3><p>Since v0.107.0, a link preview is created from the same <em>Add link</em> dialog as any other link (see <a class=\"reference-link\" href=\"#root/_help_3IDVtesTQ8ds\">External links</a>):</p><ul><li>Press <span class=\"tn-icon cke cke-link\"></span> in the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, or press <kbd>Ctrl</kbd>+<kbd>K</kbd>, to open the dialog on <em>Web link</em>.</li><li>Type or paste the address, then pick the preview in <em>Display as</em>: <em>Inline</em>, <em>Card</em> or, for a YouTube video, <em>YouTube embed</em>. <em>Plain link</em> inserts an ordinary link. <em>Display as</em> is not shown when text is selected, since the link then keeps the selected text.</li><li>Optionally, type a <em>Link title</em> to show instead of the page's own title. A <em>Card</em> also offers a <em>Description</em> to show instead of the page's own description.</li><li>Press <kbd>Enter</kbd> or <em>Insert link</em> to confirm. The link appears right away and turns into the preview once Trilium has read the page.</li></ul><p>Alternatively, use <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a> and look for <em>link preview</em> (it is also found by <em>embed</em>, <em>url</em> or <em>video</em>). It opens the same dialog with a preview already picked: a <em>YouTube embed</em> for a YouTube video, a <em>Card</em> for any other page.</p><p>To turn an existing link into a preview, open its <em>Edit link</em> dialog and change <em>Display as</em>. A link whose text differs from its address keeps that text as the title of the preview.</p><h3>3. From the Insert menu, for a YouTube video</h3><p>Choose <span class=\"tn-icon bx bxl-youtube\"></span> <em>YouTube video</em> from the <a class=\"reference-link\" href=\"#root/_help_CohkqWQC1iBv\">Insert buttons</a> menu, or <em>Insert YouTube video</em> from the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>. Paste the address of the video and press <em>Insert video</em> or <kbd>Enter</kbd> to insert it as an <em>Embed</em>. The video is inserted once its title and thumbnail have loaded, which can take a few seconds. When they cannot be loaded, an error is shown and the prompt stays open.</p><h3>4. By saving browser tabs from the Web Clipper</h3><p>When the <a class=\"reference-link\" href=\"#root/_help_MtPxeAWVAzMg\">Web Clipper</a> saves the tabs of a window, each tab becomes an <em>inline</em> link preview showing the title and favicon the browser displays for it. Because this data comes from the browser, pages behind a login keep their real title, and the Trilium server does not contact the saved pages.</p><p>When <em>Autogenerate link previews</em> is turned off, the tabs are saved as a list of plain links instead.</p><h2>Altering an existing link preview</h2><p>Click on an inserted <em>Inline</em> or <em>Card</em> link preview to select it, and a small toolbar will appear with the following options:</p><ul><li>The normal link operations (opening in a new tab, copying the link, unlinking).</li><li>The <span class=\"tn-icon cke cke-pencil\"></span> <em>Edit link</em> button, which opens the <em>Edit link</em> dialog on the link preview, as does pressing <kbd>Ctrl</kbd>+<kbd>K</kbd> while it is selected. The dialog changes its address, its <em>Link title</em> (especially useful if the title is hidden behind a login screen), the <em>Description</em> of a card and how it is displayed. A new address shows the title and description of the new page, unless you type your own.</li><li>A way to switch between the link preview modes (Inline, Card or Embed) as well as to convert it to a normal link instead.<ul><li>The Embed option is only enabled when the URL points to a supported service (YouTube today).</li></ul></li></ul><h3>Videos</h3><p>A YouTube video shown as an <em>Embed</em> has a size, a position and a title, like an <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>. It keeps the shape of the video, so a YouTube Short stands upright and an older video can be 4:3. A video inserted in an earlier version is 16:9 until it is inserted again. In the editor, a click on the video both plays it and selects it, and so does a later click on the player. The toolbar of a selected video offers:</p><ul><li><span class=\"tn-icon cke cke-trilium-copy\"></span> <em>Copy URL</em>.</li><li>The <em>Display</em> menu, which turns the video into an <em>Inline</em> or <em>Card</em> link preview, or a <em>Plain link</em>.</li><li>The <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu:<ul><li><span class=\"tn-icon bx bx-link-external\"></span> <em>Open externally</em> opens the video outside Trilium: in the browser, or in the app that handles the link, such as the YouTube app on Android.</li><li><em>Size</em>: a <em>Medium</em> video can be resized, a <em>Full</em> video takes the width of the note, or less when it would be taller than most of the window. A new video is <em>Medium</em>. A video inserted in an earlier version is <em>Full</em>.</li><li><em>Position</em>: under <em>Break text</em>, <span class=\"tn-icon cke cke-object-left\"></span> <em>Align left</em>, <span class=\"tn-icon cke cke-object-center\"></span> <em>Align center</em> and <span class=\"tn-icon cke cke-object-right\"></span> <em>Align right</em> place the video on lines of its own, at that side of the note. Under <em>Wrap text</em>, <span class=\"tn-icon cke cke-object-inline-left\"></span> <em>Align left</em> and <span class=\"tn-icon cke cke-object-inline-right\"></span> <em>Align right</em> place it at that side and let the text run beside it. <em>Align center</em> is the default.</li><li><em>Show title</em> shows the title of the video above it, as a link to the video. The <span class=\"tn-icon bx bx-dots-vertical-rounded\"></span> button of the title opens this same menu.</li><li><span class=\"tn-icon bx bx-trash\"></span> <em>Delete</em> removes the video from the note.</li></ul></li></ul><p>To resize a <em>Medium</em> video, select it and drag the handle in its bottom-right corner, or its bottom-left corner for a video aligned to the right. The height follows the width. Choosing <em>Medium</em> again returns the video to its first size.</p><p>On a <a href=\"#root/_help_R9pX4DGra2Vt\">shared page</a>, the video keeps its width and position, but not its title. In the mobile layout, a video with a position other than <em>Align center</em> takes the full width.</p><h2>Where the preview data comes from</h2><p>When you insert a link preview, Trilium fetches metadata once and stores it with the note:</p><ul><li><strong>YouTube URLs</strong>: the title, the channel name and the shape of the video are fetched via YouTube's public oEmbed endpoint, and the video's thumbnail is downloaded at up to 1280×720.</li><li><strong>All other URLs</strong>: Trilium fetches the page and reads OpenGraph tags (<code>og:title</code>, <code>og:description</code>, <code>og:image</code>, <code>og:site_name</code>), falling back to the page's <code><title></code> and <code><meta name=\"description\"></code>. The site's favicon and the page's image are downloaded as well.</li></ul><p>The text is kept in the note's HTML. The images are kept as system <a class=\"reference-link\" href=\"#root/_help_0vhv7lsOLy82\">Attachments</a> of the note, listed under <em>Generated by Trilium</em>.</p><p>Because the data is stored in the note itself, link previews continue to render correctly when you reopen the note, share/publish it, or export to HTML — without any further network requests.</p><p>The metadata is captured <strong>at insertion time</strong> and is not automatically refreshed. If the linked page later changes its title or thumbnail, you'll need to re-insert the link to pick up the new values. To refresh a link, simply create it again.</p><p>A YouTube embed inserted before v0.107.0 keeps its smaller thumbnail, shown blurred, until the link is inserted again.</p><p>When accessing a <a class=\"reference-link\" href=\"#root/_help_WOcw2SLH6tbX\">Server Installation</a>, the data is fetched from the remote URL by the server and not the client.</p><h2>Known limitations</h2><ul><li>The Embed display mode currently only supports YouTube. Other video and media platforms fall back to a Card preview.</li><li>Pages that block automated fetches may produce a minimal preview (hostname only).</li><li>Link previews require the Trilium server to reach the target URL, so they won't generate previews for pages on networks the server can't see.</li></ul>",+ "_help_UmgZAfcltxkS": "<p>Link previews turn a pasted URL into a rich, metadata-aware widget that can be displayed in three visual modes:</p><h2>Display modes</h2><p>A link preview can be displayed in one of three modes:</p><ul><li><strong>Inline</strong> — a link showing the site's favicon and page title (quite similar to <a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a>). Use this when you want the link to flow with the surrounding paragraph.</li><li><strong>Card</strong> — a block-level preview with thumbnail, title, description, and site name. Use this when the link is the focus of a paragraph.</li><li><strong>Embed</strong> — a block-level interactive embed.<ul><li>Currently supported for YouTube videos, which render interactively (via an <code>iframe</code>).</li><li>To prevent unwanted remote requests, the video is shown only after clicking on it first. Until then, the video's thumbnail is shown with a play button.</li><li>The video can be resized and aligned (see <em>Videos</em> below).</li></ul></li></ul><div class=\"trilium-multicolumn-layout\" data-trilium-column-ratios=\"1-1-1\"><div class=\"trilium-multicolumn-column\"><figure class=\"image image_resized\" style=\"width:100%;\"><img style=\"aspect-ratio:251/42;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Link%20Previews_image.png\" width=\"251\" height=\"42\"><figcaption><em>Inline</em> link preview</figcaption></figure></div><div class=\"trilium-multicolumn-column\"><figure class=\"image image_resized\" style=\"width:100%;\"><img style=\"aspect-ratio:1217/196;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/2_Link%20Previews_image.png\" width=\"1217\" height=\"196\"><figcaption><em>Card</em> link preview</figcaption></figure></div><div class=\"trilium-multicolumn-column\"><figure class=\"image image_resized\" style=\"width:100%;\"><img style=\"aspect-ratio:994/563;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Link%20Previews_image.png\" width=\"994\" height=\"563\"><figcaption><em>Embed</em> link preview</figcaption></figure></div></div><h2>Inserting a link preview</h2><p>There are four ways to create one:</p><h3>1. By pasting a URL</h3><p>A link preview is automatically created:</p><ul><li>By pasting the URL and pressing <kbd>Space</kbd>. This will create an <em>inline</em> link preview.</li><li>When at the start of a new paragraph, pressing <kbd>Enter</kbd> will create a <em>card</em> or an <em>embed</em> for YouTube URLs.</li></ul><p>To undo an automatic link preview, press <kbd>Ctrl</kbd>+<kbd>Z</kbd> immediately afterwards which keeps it as a plain link instead. Alternatively, once a link preview was created, click on the link and select <em>Plain link</em> from the link preview toolbar.</p><p>This automatic conversion can be disabled by going to <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Text Notes</em> and unchecking <em>Autogenerate link previews</em> from the <em>Features</em> section.</p><p>If the link is not accessible to the Trilium server (or the network request fails for any other reason), it will not be converted to a link preview.</p><aside class=\"admonition note\"><p>A URL is only auto-converted when the pasted text <em>is</em> the URL. Links with a display name (e.g. <a href=\"https://triliumnotes.org\">Trilium Notes website</a>) are left as plain links.</p></aside><h3>2. From the link dialog</h3><p>Since v0.107.0, a link preview is created from the same <em>Add link</em> dialog as any other link (see <a class=\"reference-link\" href=\"#root/_help_3IDVtesTQ8ds\">External links</a>):</p><ul><li>Press <span class=\"tn-icon cke cke-link\"></span> in the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, or press <kbd>Ctrl</kbd>+<kbd>K</kbd>, to open the dialog on <em>Web link</em>.</li><li>Type or paste the address, then pick the preview in <em>Display as</em>: <em>Inline</em>, <em>Card</em> or, for a YouTube video, <em>YouTube embed</em>. <em>Plain link</em> inserts an ordinary link. <em>Display as</em> is not shown when text is selected, since the link then keeps the selected text.</li><li>Optionally, type a <em>Link title</em> to show instead of the page's own title. A <em>Card</em> also offers a <em>Description</em> to show instead of the page's own description.</li><li>Press <kbd>Enter</kbd> or <em>Insert link</em> to confirm. The link appears right away and turns into the preview once Trilium has read the page.</li></ul><p>Alternatively, use <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a> and look for <em>link preview</em> (it is also found by <em>embed</em>, <em>url</em> or <em>video</em>). It opens the same dialog with a preview already picked: a <em>YouTube embed</em> for a YouTube video, a <em>Card</em> for any other page.</p><p>To turn an existing link into a preview, open its <em>Edit link</em> dialog and change <em>Display as</em>. A link whose text differs from its address keeps that text as the title of the preview.</p><h3>3. From the Insert menu, for a YouTube video</h3><p>Choose <span class=\"tn-icon bx bxl-youtube\"></span> <em>YouTube video</em> from the <a class=\"reference-link\" href=\"#root/_help_CohkqWQC1iBv\">Insert buttons</a> menu, or <em>Insert YouTube video</em> from the <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>. Paste the address of the video and press <em>Insert video</em> or <kbd>Enter</kbd> to insert it as an <em>Embed</em>. The video is inserted once its title and thumbnail have loaded, which can take a few seconds. When they cannot be loaded, an error is shown and the prompt stays open.</p><h3>4. By saving browser tabs from the Web Clipper</h3><p>When the <a class=\"reference-link\" href=\"#root/_help_MtPxeAWVAzMg\">Web Clipper</a> saves the tabs of a window, each tab becomes an <em>inline</em> link preview showing the title and favicon the browser displays for it. Because this data comes from the browser, pages behind a login keep their real title, and the Trilium server does not contact the saved pages.</p><p>When <em>Autogenerate link previews</em> is turned off, the tabs are saved as a list of plain links instead.</p><h2>Altering an existing link preview</h2><p>Click on an inserted <em>Inline</em> or <em>Card</em> link preview to select it, and a small toolbar will appear with the following options:</p><ul><li>The normal link operations (opening in a new tab, copying the link, unlinking).</li><li>The <span class=\"tn-icon cke cke-pencil\"></span> <em>Edit link</em> button, which opens the <em>Edit link</em> dialog on the link preview, as does pressing <kbd>Ctrl</kbd>+<kbd>K</kbd> while it is selected. The dialog changes its address, its <em>Link title</em> (especially useful if the title is hidden behind a login screen), the <em>Description</em> of a card and how it is displayed. A new address shows the title and description of the new page, unless you type your own.</li><li>A way to switch between the link preview modes (Inline, Card or Embed) as well as to convert it to a normal link instead.<ul><li>The Embed option is only enabled when the URL points to a supported service (YouTube today).</li></ul></li></ul><h3>Videos</h3><p>A YouTube video shown as an <em>Embed</em> has a size, a position, a title and a caption, like an <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>. It keeps the shape of the video, so a YouTube Short stands upright and an older video can be 4:3. A video inserted in an earlier version is 16:9 until it is inserted again. In the editor, a click on the video both plays it and selects it, and so does a later click on the player. The toolbar of a selected video offers:</p><ul><li><span class=\"tn-icon cke cke-trilium-copy\"></span> <em>Copy URL</em>.</li><li>The <em>Display</em> menu, which turns the video into an <em>Inline</em> or <em>Card</em> link preview, or a <em>Plain link</em>.</li><li>The <span class=\"tn-icon cke cke-three-vertical-dots\"></span> <em>More actions</em> menu:<ul><li><span class=\"tn-icon bx bx-link-external\"></span> <em>Open externally</em> opens the video outside Trilium: in the browser, or in the app that handles the link, such as the YouTube app on Android.</li><li><em>Size</em>: a <em>Medium</em> video can be resized, a <em>Full</em> video takes the width of the note, or less when it would be taller than most of the window. A new video is <em>Medium</em>. A video inserted in an earlier version is <em>Full</em>.</li><li><em>Position</em>: under <em>Break text</em>, <span class=\"tn-icon cke cke-object-left\"></span> <em>Align left</em>, <span class=\"tn-icon cke cke-object-center\"></span> <em>Align center</em> and <span class=\"tn-icon cke cke-object-right\"></span> <em>Align right</em> place the video on lines of its own, at that side of the note. Under <em>Wrap text</em>, <span class=\"tn-icon cke cke-object-inline-left\"></span> <em>Align left</em> and <span class=\"tn-icon cke cke-object-inline-right\"></span> <em>Align right</em> place it at that side and let the text run beside it. <em>Align center</em> is the default.</li><li><em>Show title</em> shows the title of the video above it, as a link to the video. The <span class=\"tn-icon bx bx-dots-vertical-rounded\"></span> button of the title opens this same menu.</li><li><em>Show caption</em> adds a caption under the video, centered, and puts the cursor in it. The caption is part of the text note, so it can be formatted like the rest of the text. While the cursor is in the caption, the video stays selected and keeps its toolbar. Choosing <em>Show caption</em> again removes the caption.</li><li><span class=\"tn-icon bx bx-trash\"></span> <em>Delete</em> removes the video from the note.</li></ul></li></ul><p>To resize a <em>Medium</em> video, select it and drag the handle in its bottom-right corner, or its bottom-left corner for a video aligned to the right. The height follows the width. Choosing <em>Medium</em> again returns the video to its first size.</p><p>On a <a href=\"#root/_help_R9pX4DGra2Vt\">shared page</a>, the video keeps its width, position and caption, but not its title. In the mobile layout, a video with a position other than <em>Align center</em> takes the full width.</p><h2>Where the preview data comes from</h2><p>When you insert a link preview, Trilium fetches metadata once and stores it with the note:</p><ul><li><strong>YouTube URLs</strong>: the title, the channel name and the shape of the video are fetched via YouTube's public oEmbed endpoint, and the video's thumbnail is downloaded at up to 1280×720.</li><li><strong>All other URLs</strong>: Trilium fetches the page and reads OpenGraph tags (<code>og:title</code>, <code>og:description</code>, <code>og:image</code>, <code>og:site_name</code>), falling back to the page's <code><title></code> and <code><meta name=\"description\"></code>. The site's favicon and the page's image are downloaded as well.</li></ul><p>The text is kept in the note's HTML. The images are kept as system <a class=\"reference-link\" href=\"#root/_help_0vhv7lsOLy82\">Attachments</a> of the note, listed under <em>Generated by Trilium</em>.</p><p>Because the data is stored in the note itself, link previews continue to render correctly when you reopen the note, share/publish it, or export to HTML — without any further network requests.</p><p>The metadata is captured <strong>at insertion time</strong> and is not automatically refreshed. If the linked page later changes its title or thumbnail, you'll need to re-insert the link to pick up the new values. To refresh a link, simply create it again.</p><p>A YouTube embed inserted before v0.107.0 keeps its smaller thumbnail, shown blurred, until the link is inserted again.</p><p>When accessing a <a class=\"reference-link\" href=\"#root/_help_WOcw2SLH6tbX\">Server Installation</a>, the data is fetched from the remote URL by the server and not the client.</p><h2>Known limitations</h2><ul><li>The Embed display mode currently only supports YouTube. Other video and media platforms fall back to a Card preview.</li><li>Pages that block automated fetches may produce a minimal preview (hostname only).</li><li>Link previews require the Trilium server to reach the target URL, so they won't generate previews for pages on networks the server can't see.</li></ul>","_help_QEAPj01N5f7w": "<p>There are two types of links:</p><ul><li><a class=\"reference-link\" href=\"#root/_help_3IDVtesTQ8ds\">External links</a>, for standard hyperlinks to websites or other resources.</li><li><a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a> for links to other notes within Trilium.<ul><li>The list of notes that refer to a particular note is called <a class=\"reference-link\" href=\"#root/_help_wfGXLmm7x27z\">Backlinks</a>.</li></ul></li></ul><h2>Note map</h2><p>Trilium provides a visualization of incoming and outgoing links for a particular note. See <a href=\"#root/_help_BCkXAVs63Ttv\">note map</a> for details.</p>","_help_3IDVtesTQ8ds": "<p>An external link is a standard web link targeting for example a website. For example, <a href=\"https://en.wikipedia.org/wiki/South_China_Sea\">https://en.wikipedia.org/wiki/South_China_Sea</a> is an external link to a Wikipedia page.</p><p>To create a link without a custom text:</p><ul><li>Press <span class=\"tn-icon cke cke-link\"></span> in the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, or press <kbd>Ctrl</kbd>+<kbd>K</kbd>:<ul><li>Since v0.107.0, the <em>Add link</em> dialog opens on <em>Web link</em>, in a popup next to the cursor on desktop. Type or paste the address, and optionally a <em>Link title</em>; without one, the link shows its address.</li><li><em>Display as</em> inserts the address as a <em>Plain link</em>, or as one of the <a class=\"reference-link\" href=\"#root/_help_UmgZAfcltxkS\">Link Previews</a>: <em>Inline</em>, <em>Card</em> or, for a YouTube video, <em>YouTube embed</em>.</li><li>Press <kbd>Enter</kbd> or <em>Insert link</em> to confirm.</li></ul></li><li>A simpler way is to paste the raw link and press space to turn it automatically into a link.</li><li>The <span class=\"tn-icon cke cke-trilium\"></span> button and <kbd>Ctrl</kbd>+<kbd>L</kbd> of <a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a> open the same dialog on <em>Note</em>. Select <em>Web link</em> at the top of the dialog to create an external link from there.</li></ul><p>An address without a scheme, such as <code>example.com</code>, gets <code>https://</code>. A URL pasted into the <em>Note</em> field, or picked from its search, switches the dialog to <em>Web link</em>. The dialog also opens on <em>Web link</em> when the selected text is a URL.</p><p>To create a link with a custom text:</p><ul><li>First, type and select the text which will be turned into a link.</li><li>Open the <em>Add link</em> dialog as above (via the formatting toolbar, or <kbd>Ctrl</kbd>+<kbd>K</kbd>). The selected text becomes the text of the link, so the dialog does not offer <em>Display as</em>.</li><li>Alternatively, simply paste (<kbd>Ctrl</kbd>+<kbd>V</kbd>) over the selected text to turn it into a link.</li></ul><p>Once a link is inserted:</p><ul><li>The text inside the link can be changed if needed but the link itself will remain.</li><li>To modify the link, click on the link to display the popup and press the <span class=\"tn-icon cke cke-pencil\"></span> <em>Edit link</em> button. It opens the <em>Edit link</em> dialog, filled with the link's address and text, as do placing the cursor inside the link and pressing <kbd>Ctrl</kbd>+<kbd>K</kbd>, <kbd>Ctrl</kbd>+<kbd>L</kbd> or one of the link buttons. <em>Save link</em> changes the whole link, its text included, and the dialog can also turn it into a link to a note.</li><li>To remove a link, click on it and press the <span class=\"tn-icon cke cke-unlink\"></span> <em>Unlink</em> button.</li></ul><p>You can follow external link by either double clicking (will open new tab/window) it or right clicking on them and choosing \"Open in new tab\".</p>","_help_hrZ1D00cLbal": "<p>Internal links are links to other notes within Trilium.</p><p>You can open an internal link by clicking it. You can also see a read-only preview of an internal link's contents by hovering over it.</p><p>Since v0.107.0, clicking an internal link while editing a text note shows its popup instead, as clicking an external link does:</p><ul><li><em>Open note</em> opens the linked note, or <em>Open attachment</em> for a link to an attachment. A link into the same note reads <em>Jump to heading</em>, <em>Jump to block</em> or <em>Jump to anchor</em> instead, and scrolls to it without leaving the note.</li><li><span class=\"tn-icon cke cke-trilium-copy\"></span> <em>Copy URL</em> copies the address of the link.</li><li><span class=\"tn-icon cke cke-pencil\"></span> <em>Edit link</em> changes the link, as described below.</li><li><span class=\"tn-icon cke cke-unlink\"></span> <em>Unlink</em> turns the link into plain text.</li></ul><p>To open the note in a new tab without the popup, <kbd>Ctrl</kbd>+click or double-click the link. The preview does not show while the popup is open.</p><h2>Inserting internal links</h2><p>Internal links can be created at the current position in a text note by:</p><ol><li>Pressing <kbd>Ctrl</kbd> + <kbd>L</kbd> or the <span class=\"tn-icon cke cke-trilium\"></span> button underneath the <span class=\"tn-icon cke cke-plus\"></span> menu in the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>. On desktop, the <em>Add link</em> dialog opens in a popup next to the cursor.</li><li>Searching for the title of the desired note to link. It's also possible to create new notes from this dialog by typing a non-existing note title and selecting either <em>Create note</em>, which places it in the <a class=\"reference-link\" href=\"#root/_help_S0Fos78ZfcY7\">Note Inbox</a> (today's day note, or the top level, when no inbox is set), or <em>Create child note</em>, which places it under the note being edited.</li></ol><p>There are two link types, depending on the <em>Link title</em> field of the dialog:</p><ol><li>When the link title is not set, the link will display the title of the note. If the title of the note gets changed, the link will be renamed automatically to the new name.<ol><li>This is sometimes also called \"reference link\".</li><li>The icon of the linked note will also be displayed.</li><li>If the linked note is deleted, the link keeps the last title it showed, in red and with a <span class=\"tn-icon bx bx-x\"></span> icon instead of the note icon. Clicking it while editing opens the <em>Fix link</em> dialog, which searches for that title; picking a note, or creating a new one, replaces the link with one to that note.</li></ol></li><li>When a link title is typed, the link shows that text instead.<ol><li>This will create a traditional hyperlink, where the text of the link can be different from the note title.</li></ol></li></ol><p>Since v0.107.0, to change a link, click it and press the <span class=\"tn-icon cke cke-pencil\"></span> <em>Edit link</em> button in its popup. For a link with a title of its own, placing the cursor inside it and pressing <kbd>Ctrl</kbd> + <kbd>L</kbd> or the <span class=\"tn-icon cke cke-trilium\"></span> button works too. The <em>Edit link</em> dialog opens on the linked note, with its anchor and, for a link with a title of its own, the link's text; <em>Save link</em> changes the whole link. Emptying the <em>Link title</em> there turns the link into one that displays the title of the note, and typing one gives it a title of its own.</p><h2>In-place linking</h2><p>You can also insert internal links “inline” by using the <code>@</code> symbol:</p><ol><li>Type <code>@</code> in a text note, which will open the note search menu.</li><li>Search for the desired note's title by typing a few characters. Use <kbd>Up</kbd> and <kbd>Down</kbd> to select the correct note, and press <kbd>Enter</kbd> or <kbd>Tab</kbd> to create the link. It's also possible to create new notes with this method by typing a non-existing note title and selecting <em>Create note</em>, as described above, or <em>Create child note</em>. <em>Create child note</em> creates the note under the note being edited without asking for its type, inserts the link and opens the new note in <a class=\"reference-link\" href=\"#root/_help_ZjLYv08Rp3qC\">Quick edit</a>, which offers the note types to turn it into while it is still empty.</li></ol><p>To create an empty child note and link to it before naming it, use <em>New child note</em>, described in <a class=\"reference-link\" href=\"#root/_help_CohkqWQC1iBv\">Insert buttons</a>.</p><h2>Pasting internal links</h2><p>You can also insert internal links by copying a note from the note tree.</p><ol><li>In the <a class=\"reference-link\" href=\"#root/_help_oPVyFC7WL2Lp\">Note Tree</a>, select a note and press <kbd>Ctrl</kbd> + <kbd>C</kbd>.</li><li>In a text note, paste the link by pressing <kbd>Ctrl</kbd> + <kbd>V</kbd>.</li></ol>",diff --git a/docs/User Guide/User Guide/Note Types/Text/Include Note.md b/docs/User Guide/User Guide/Note Types/Text/Include Note.mdindex 17a0fcb93a..9be6bb68f1 100644--- a/docs/User Guide/User Guide/Note Types/Text/Include Note.md+++ b/docs/User Guide/User Guide/Note Types/Text/Include Note.md@@ -52,7 +52,7 @@ A _Small_, _Medium_ or _Expandable_ include can be resized to any width and heigAn include can have a caption, shown centered at the bottom of its box. The caption is part of the text note, so it can be formatted like the rest of the text, for example in bold or with a link.-* To add a caption, select the include, press the <span class="tn-icon cke cke-caption"></span> _Toggle caption on_ button in its toolbar and type the caption.+* To add a caption, select the include, press the <span class="tn-icon cke cke-caption"></span> _Toggle caption on_ button in its toolbar and type the caption. While the cursor is in the caption, the include stays selected and keeps its toolbar.* To remove the caption, press the same button again. Pressing it once more brings back the text it had, as long as the note stays open.* A _Tiny_ include has no caption. Switching an include to _Tiny_ removes its caption, and switching it back to a larger size restores the caption, as long as the note stays open.* An _Expandable_ include shows its caption under the title while the content is collapsed, and under the content once it is expanded.diff --git a/docs/User Guide/User Guide/Note Types/Text/Link Previews.md b/docs/User Guide/User Guide/Note Types/Text/Link Previews.mdindex dd330367b4..6bb8ff5b7a 100644--- a/docs/User Guide/User Guide/Note Types/Text/Link Previews.md+++ b/docs/User Guide/User Guide/Note Types/Text/Link Previews.md@@ -84,7 +84,7 @@ Click on an inserted _Inline_ or _Card_ link preview to select it, and a small t### Videos-A YouTube video shown as an _Embed_ has a size, a position and a title, like an <a class="reference-link" href="Include%20Note.md">Include Note</a>. It keeps the shape of the video, so a YouTube Short stands upright and an older video can be 4:3. A video inserted in an earlier version is 16:9 until it is inserted again. In the editor, a click on the video both plays it and selects it, and so does a later click on the player. The toolbar of a selected video offers:+A YouTube video shown as an _Embed_ has a size, a position, a title and a caption, like an <a class="reference-link" href="Include%20Note.md">Include Note</a>. It keeps the shape of the video, so a YouTube Short stands upright and an older video can be 4:3. A video inserted in an earlier version is 16:9 until it is inserted again. In the editor, a click on the video both plays it and selects it, and so does a later click on the player. The toolbar of a selected video offers:* <span class="tn-icon cke cke-trilium-copy"></span> _Copy URL_.* The _Display_ menu, which turns the video into an _Inline_ or _Card_ link preview, or a _Plain link_.@@ -93,11 +93,12 @@ A YouTube video shown as an _Embed_ has a size, a position and a title, like an* _Size_: a _Medium_ video can be resized, a _Full_ video takes the width of the note, or less when it would be taller than most of the window. A new video is _Medium_. A video inserted in an earlier version is _Full_.* _Position_: under _Break text_, <span class="tn-icon cke cke-object-left"></span> _Align left_, <span class="tn-icon cke cke-object-center"></span> _Align center_ and <span class="tn-icon cke cke-object-right"></span> _Align right_ place the video on lines of its own, at that side of the note. Under _Wrap text_, <span class="tn-icon cke cke-object-inline-left"></span> _Align left_ and <span class="tn-icon cke cke-object-inline-right"></span> _Align right_ place it at that side and let the text run beside it. _Align center_ is the default.* _Show title_ shows the title of the video above it, as a link to the video. The <span class="tn-icon bx bx-dots-vertical-rounded"></span> button of the title opens this same menu.+ * _Show caption_ adds a caption under the video, centered, and puts the cursor in it. The caption is part of the text note, so it can be formatted like the rest of the text. While the cursor is in the caption, the video stays selected and keeps its toolbar. Choosing _Show caption_ again removes the caption.* <span class="tn-icon bx bx-trash"></span> _Delete_ removes the video from the note.To resize a _Medium_ video, select it and drag the handle in its bottom-right corner, or its bottom-left corner for a video aligned to the right. The height follows the width. Choosing _Medium_ again returns the video to its first size.-On a [shared page](../../Advanced%20Usage/Sharing.md), the video keeps its width and position, but not its title. In the mobile layout, a video with a position other than _Align center_ takes the full width.+On a [shared page](../../Advanced%20Usage/Sharing.md), the video keeps its width, position and caption, but not its title. In the mobile layout, a video with a position other than _Align center_ takes the full width.## Where the preview data comes fromdiff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.tsindex 6ddffe3113..6767bd346e 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts@@ -38,6 +38,7 @@ import ContentEmbed, {DELETE_COMMAND_NAME,DISPLAY_MODE_BUTTONS,DISPLAY_MODES,+ getCaption,POSITION_COMMAND_NAME,TOGGLE_CAPTION_COMMAND_NAME,TOGGLE_EDITABLE_COMMAND_NAME,@@ -1287,6 +1288,34 @@ describe("ContentEmbed captions", () => {expect(isSelectionInCaption()).toBe(false);});+ it("looks selected while its caption has the selection, as while it is selected", () => {+ editor.setData(`<p>Text</p>${CAPTIONED}`);+ const isMarked = () => !!editor.editing.view.getDomRoot()+ ?.querySelector("figure.include-note")?.classList.contains("ck-widget_selected");+ const embed = findContentEmbed(editor);+ const caption = embed && getCaption(embed);+ const paragraph = editor.model.document.getRoot()?.getChild(0);+ if (!caption || !paragraph) {+ throw new Error("Expected a paragraph and a captioned embed.");+ }+ expect(isMarked()).toBe(false);++ editor.model.change((writer) => writer.setSelection(caption, 2));+ expect(isMarked()).toBe(true);+ editor.model.change((writer) => writer.setSelection(caption, "end"));+ expect(isMarked()).toBe(true);++ editor.model.change((writer) => writer.setSelection(paragraph, 0));+ expect(isMarked()).toBe(false);++ selectEmbed();+ expect(isMarked()).toBe(true);+ editor.model.change((writer) => writer.setSelection(caption, 0));+ expect(isMarked()).toBe(true);+ editor.model.change((writer) => writer.setSelection(paragraph, 0));+ expect(isMarked()).toBe(false);+ });+it("keeps the rendered content while the caption is toggled and edited", () => {insertContentEmbed(editor, "n1", "medium");const wrapper = editor.editing.view.getDomRoot()?.querySelector(".include-note-wrapper");diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed.tsindex 50153b74dd..007d4fae37 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed.ts@@ -3,7 +3,10 @@ import {Command,type DomEmitter,DomEmitterMixin,+ type DowncastCleanSelectionEvent,type DowncastConversionApi,+ type DowncastInsertEvent,+ type DowncastSelectionEvent,type Editor,enableViewPlaceholder,IconCaption,@@ -14,15 +17,19 @@ import {ModelElement,type ModelNode,type ModelDocumentFragment,+ type ModelPosition,type ModelWriter,type PlaceholderableViewElement,Plugin,toWidget,toWidgetEditable,+ type UpcastElementEvent,View,type ViewEditableElement,type ViewElement,+ ViewPosition,Widget,+ WIDGET_SELECTED_CLASS_NAME,type Observable} from 'ckeditor5';import codeIcon from 'boxicons/svg/regular/bx-code.svg?raw';@@ -32,8 +39,9 @@ import dockLeftIcon from 'boxicons/svg/solid/bxs-dock-left.svg?raw';import windowIcon from 'boxicons/svg/regular/bx-window-alt.svg?raw';import noteIcon from '../../icons/note.svg?raw';import {- encodeBlockParameter, EXTENDED_CODE_BLOCK_CLASS, type LinkPreviewData,- normalizeMimeTypeForCKEditor, parseBlockRange, VIDEO_EMBED_BOX_SIZES, VIDEO_EMBED_CLASS+ CAPTIONED_CONTENT_EMBED_CLASS, encodeBlockParameter, EXTENDED_CODE_BLOCK_CLASS,+ type LinkPreviewData, normalizeMimeTypeForCKEditor, parseBlockRange, VIDEO_EMBED_BOX_SIZES,+ VIDEO_EMBED_CLASS} from '@triliumnext/commons';import { getAttachmentId, getNoteId } from '../referencelink.js';import ResizableWidgets, {@@ -162,7 +170,7 @@ export interface ContentEmbedState {/** Whether the title shows, which a Tiny or an Expandable embed always does. */isTitleShown: boolean;isTitleToggleable: boolean;- /** Whether the embed can have a caption, which an embed of a source or a video cannot. */+ /** Whether the embed can have a caption, which an embed of a source cannot. */isCaptionSupported: boolean;hasCaption: boolean;isCaptionToggleable: boolean;@@ -561,6 +569,7 @@ class ContentEmbedEditing extends Plugin {commands.add( DELETE_COMMAND_NAME, new DeleteContentEmbedCommand( editor ) );editor.model.document.registerPostFixer( writer => this.removeTinyCaptions( writer ) );+ this.markEmbedOfSelectedCaption();restoreRendererFocusOnInput( this );fireFrameFocusEvents( editor, this.windowEmitter );@@ -799,7 +808,8 @@ class ContentEmbedEditing extends Plugin {conversion.for( 'editingDowncast' ).elementToElement( {model: 'caption',view: ( modelElement, { writer: viewWriter } ) => {- if ( !isContentEmbed( modelElement.parent ) ) {+ const embed = modelElement.parent;+ if ( !isContentEmbed( embed ) ) {return null;}@@ -813,10 +823,13 @@ class ContentEmbedEditing extends Plugin {} );return toWidgetEditable( figcaption, viewWriter, {- label: t( 'Caption for the included note' )+ label: isVideoEmbed( embed )+ ? t( 'Caption for the video' )+ : t( 'Caption for the included note' )} );}} );+ this._defineCaptionedEmbedConverters();// The default mapping places model offset 0 before the content wrapper, which has no model// length. The caption goes after it.@@ -838,6 +851,120 @@ class ContentEmbedEditing extends Plugin {);}+ /**+ * Saves an embed whose own element is not a `<figure>`, such as the `<section>` of a video,+ * in a `<figure class="captioned-content-embed">` while it has a caption, with the+ * `<figcaption>` after the element, and loads it back.+ */+ _defineCaptionedEmbedConverters() {+ const editor = this.editor;+ const { downcastDispatcher, mapper, upcastDispatcher } = editor.data;++ // Runs after the converter of the embed's kind draws its element, and before the default+ // converter of the `lowest` priority converts the caption.+ downcastDispatcher.on<DowncastInsertEvent<ModelElement>>( 'insert:contentEmbed',+ ( _evt, { item }, api ) => {+ const element = api.mapper.toViewElement( item );+ if ( !element || element.is( 'element', 'figure' ) || !getCaption( item ) ) {+ return;+ }++ const writer = api.writer;+ const figure = writer.createContainerElement( 'figure', {+ class: CAPTIONED_CONTENT_EMBED_CLASS+ } );+ writer.insert( writer.createPositionBefore( element ), figure );+ writer.move( writer.createRangeOn( element ),+ writer.createPositionAt( figure, 0 ) );+ // The figure maps to the embed, so the mapper counts it as one model node. The+ // embed still maps to its element, which the attribute converters write to.+ api.mapper.bindElements( item, figure );+ api.mapper.bindElements( item, element );+ }, { priority: 'low' } );++ // The children of such an embed, its caption, go after its element in the figure.+ mapper.on<MapperModelToViewPositionEvent>( 'modelToViewPosition', ( _evt, data ) => {+ const embed = data.modelPosition.parent;+ const element = isContentEmbed( embed )+ ? data.mapper.toViewElement( embed )+ : undefined;+ const figure = element?.parent;+ if ( !element || !figure?.is( 'element' ) || !isCaptionedEmbedView( figure ) ) {+ return;+ }++ const offset = figure.getChildIndex( element ) + 1 + data.modelPosition.offset;+ data.viewPosition = new ViewPosition( figure, offset );+ } );++ upcastDispatcher.on<UpcastElementEvent>( 'element:figure', ( _evt, data, api ) => {+ const figure = data.viewItem;+ if ( !isCaptionedEmbedView( figure )+ || !api.consumable.test( figure, { name: true } ) ) {+ return;+ }++ const children = [ ...figure.getChildren() ]+ .filter( ( child ): child is ViewElement => child.is( 'element' ) );+ const figcaption = children.find( child => child.name === 'figcaption' );+ const element = children.find( child => child !== figcaption );+ if ( !element ) {+ return;+ }++ api.consumable.consume( figure, {+ name: true, classes: CAPTIONED_CONTENT_EMBED_CLASS+ } );+ const converted = api.convertItem( element, data.modelCursor );+ const modelRange = converted.modelRange;+ /* v8 ignore next 3 -- the default element converter gives every element a range */+ if ( !modelRange ) {+ return;+ }++ const embed = modelRange.start.nodeAfter;+ let modelCursor = converted.modelCursor;+ if ( figcaption && isContentEmbed( embed )+ && isEmbedCaptionToggleable( editor, embed ) ) {+ const caption = api.writer.createElement( 'caption' );+ api.writer.append( caption, embed );+ api.consumable.consume( figcaption, { name: true } );+ api.convertChildren( figcaption, caption );+ } else if ( figcaption ) {+ // Content that takes no caption keeps the text of the caption after it.+ modelCursor = api.convertItem( figcaption, modelCursor ).modelCursor;+ }++ data.modelRange = api.writer.createRange( modelRange.start, modelCursor );+ data.modelCursor = modelCursor;+ }, { priority: 'high' } );+ }++ /**+ * Marks the embed whose caption has the selection as selected, as `Widget` marks the embed+ * that the selection is on, such as one whose player has the focus.+ */+ private markEmbedOfSelectedCaption() {+ const dispatcher = this.editor.editing.downcastDispatcher;+ let marked: ViewElement | null = null;++ dispatcher.on<DowncastCleanSelectionEvent>( 'cleanSelection', ( _evt, _data, api ) => {+ if ( marked ) {+ api.writer.removeClass( WIDGET_SELECTED_CLASS_NAME, marked );+ marked = null;+ }+ } );+ // After `Widget` marks the widgets in the selection.+ dispatcher.on<DowncastSelectionEvent>( 'selection', ( _evt, { selection }, api ) => {+ const embed = getCaptionedEmbed( selection.getFirstPosition() );+ const view = embed && api.mapper.toViewElement( embed );+ if ( view ) {+ api.writer.addClass( WIDGET_SELECTED_CLASS_NAME, view );+ marked = view;+ }+ }, { priority: 'lowest' } );+ }+/*** Removes the caption of every Tiny embed that a change touched, keeping a copy for when* the embed gets a larger box size.@@ -1334,9 +1461,9 @@ function hasTitleRow( embed: ModelElement ) {return !isInlineSourceEmbed( embed );}-/** Whether `embed` can have a caption: an embed of a source or of a video has none. */+/** Whether `embed` can have a caption: an embed of a source has none. */function hasCaptionSupport( embed: ModelElement ) {- return !isInlineSourceEmbed( embed ) && !isVideoEmbed( embed );+ return !isInlineSourceEmbed( embed );}/** Whether the content of `embed` has an editable mode, which its content type opts in to. */@@ -1414,6 +1541,12 @@ function isEmbedConvertibleToLink( editor: Editor, embed: ModelElement ) {&& editor.model.schema.isRegistered( 'reference' );}+/** The embed whose caption holds `position`, or `null`. */+export function getCaptionedEmbed( position: ModelPosition | null ): ModelElement | null {+ const embed = position?.findAncestor( 'caption' )?.parent ?? null;+ return isContentEmbed( embed ) ? embed : null;+}+/** The caption of `embed`, or `null`. */export function getCaption( embed: ModelElement ) {return Array.from( embed.getChildren() )@@ -1427,6 +1560,11 @@ function isContentEmbedCaptionView( element: ViewElement ) {&& parent.hasClass( 'include-note' );}+/** Whether `element` is the `<figure>` that holds an embed saved with its caption. */+function isCaptionedEmbedView( element: ViewElement ) {+ return element.name === 'figure' && element.hasClass( CAPTIONED_CONTENT_EMBED_CLASS );+}+/** The index of the content wrapper among the children of an embed's view, or `-1`. */function getWrapperIndex( viewElement: ViewElement ) {return Array.from( viewElement.getChildren() )diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.spec.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.spec.tsindex 44cf842258..4cc4cd7fbe 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.spec.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.spec.ts@@ -151,6 +151,14 @@ describe("ContentEmbedToolbar", () => {setModelData(editor.model, "<paragraph>foo[]bar</paragraph>");expect(definition?.getRelatedElement(editor.editing.view.document.selection)).toBeNull();++ // The caption of a video keeps its toolbar, as its player does.+ setModelData(editor.model, `<contentEmbed embedType="youtube"`+ + ` url="https://youtube.com/watch?v=abc12345678"><caption>A [] caption</caption>`+ + `</contentEmbed>`);+ expect(definition?.getRelatedElement(selection))+ .toBe(editor.editing.view.document.getRoot()?.getChild(0));+ expect(getRelatedElementFn(editor)(selection)).toBeNull();});it("offers Editable, the display modes, the content's tools, then the embed's items", () => {diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.tsindex 79bf5c9fe5..6295269011 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_toolbar.ts@@ -80,14 +80,26 @@ export default class ContentEmbedToolbar extends Plugin {/** The embed that the toolbar shows for: the selected one, or the one whose caption is edited. */function findRelatedEmbed(selection: ViewDocumentSelection) {+ return findRelatedWidget(selection, isContentEmbedWidget);+}++/** The video embed that the selection is on or in the caption of, with a toolbar of its own. */+function findRelatedVideo(selection: ViewDocumentSelection) {+ return findRelatedWidget(selection, isVideoEmbedWidget);+}++/** The widget that `matches()` and that `selection` is on or inside, or `null`. */+function findRelatedWidget(+ selection: ViewDocumentSelection, matches: (element: ViewElement) => boolean+) {const selectedElement = selection.getSelectedElement();- if (selectedElement && isContentEmbedWidget(selectedElement)) {+ if (selectedElement && matches(selectedElement)) {return selectedElement;}for (const ancestor of selection.getFirstPosition()?.getAncestors() ?? []) {- if (ancestor.is("element") && isContentEmbedWidget(ancestor)) {+ if (ancestor.is("element") && matches(ancestor)) {return ancestor;}}@@ -95,17 +107,15 @@ function findRelatedEmbed(selection: ViewDocumentSelection) {return null;}-/** The video embed that the selection is on, which has a toolbar of its own. */-function findRelatedVideo(selection: ViewDocumentSelection) {- const selected = selection.getSelectedElement();- return selected && isWidget(selected) && selected.hasClass(VIDEO_EMBED_CLASS) ? selected : null;-}-function isContentEmbedWidget(element: ViewElement): boolean {return isWidget(element) && element.hasClass("include-note")&& !element.hasClass(VIDEO_EMBED_CLASS);}+function isVideoEmbedWidget(element: ViewElement): boolean {+ return isWidget(element) && element.hasClass(VIDEO_EMBED_CLASS);+}+/*** The positions of the toolbar: level with the edge of the embed that `getAnchor()` returns, then,* or where those do not fit, the positions that `WidgetToolbarRepository` gives a widget toolbar.diff --git a/packages/ckeditor5/src/plugins/content_embed/video_embed.spec.ts b/packages/ckeditor5/src/plugins/content_embed/video_embed.spec.tsindex 0c52cb6ece..fe6ed22b35 100644--- a/packages/ckeditor5/src/plugins/content_embed/video_embed.spec.ts+++ b/packages/ckeditor5/src/plugins/content_embed/video_embed.spec.ts@@ -8,6 +8,7 @@ import LinkEmbed from "../link_embed/link_embed.js";import { SIZE_ATTRIBUTES } from "../resizable_widgets/resizable_widgets.js";import ContentEmbed, {BOX_SIZE_COMMAND_NAME,+ getCaption,POSITION_COMMAND_NAME,TOGGLE_CAPTION_COMMAND_NAME,TOGGLE_TITLE_COMMAND_NAME@@ -62,6 +63,14 @@ describe("ContentEmbedVideo", () => {editor.model.change((writer) => writer.setSelection(getBlock(index), "on"));}+ function getCaptionOf(index: number) {+ const caption = getCaption(getBlock(index));+ if (!caption) {+ throw new Error(`Expected a caption on the block at ${index}.`);+ }+ return caption;+ }+/** Inserts a paragraph and a video whose player is a frame of `src`, and returns the frame. */function insertPlayer(src: string) {loadVideo.mockImplementation((_preview: unknown, wrapper: HTMLElement) => {@@ -188,7 +197,7 @@ describe("ContentEmbedVideo", () => {expect(editor.model.document.selection.getSelectedElement()).toBe(getBlock(1));});- it("has the Medium and Full sizes, a title, a position and no caption", () => {+ it("has the Medium and Full sizes, a title, a position and a caption", () => {editor.setData(`<p>Text</p>${SAVED_PREVIEW}`);selectBlock(1);@@ -197,13 +206,14 @@ describe("ContentEmbedVideo", () => {POSITION_COMMAND_NAME];expect(commands.map((name) => editor.commands.get(name)?.isEnabled))- .toEqual([ true, true, false, true ]);+ .toEqual([ true, true, true, true ]);const contentEmbed = editor.plugins.get(ContentEmbed);expect(contentEmbed.getBoxSizes(getFigure())).toEqual([ { value: "medium", label: "Medium" }, { value: "full", label: "Full" } ]);expect(contentEmbed.getEmbedStateAt(getFigure())).toMatchObject({boxSize: "full", position: "center", isTitleSupported: true, isTitleShown: false,- isTitleToggleable: true, isCaptionSupported: false, url: VIDEO_URL+ isTitleToggleable: true, isCaptionSupported: true, isCaptionToggleable: true,+ hasCaption: false, url: VIDEO_URL});editor.execute(TOGGLE_TITLE_COMMAND_NAME);@@ -214,6 +224,59 @@ describe("ContentEmbedVideo", () => {expect(editor.getData()).toContain(` data-position="right"`);});+ it("saves a caption in a figure around its section, which goes away with the caption", () => {+ editor.setData(`<p>Text</p>${SAVED_PREVIEW}`);+ selectBlock(1);+ editor.execute(TOGGLE_CAPTION_COMMAND_NAME, { focusCaptionOnShow: true });+ editor.model.change((writer) => writer.insertText("A caption", getCaptionOf(1), 0));++ const caption = getFigure().querySelector(":scope > .include-note-wrapper + figcaption");+ expect(caption?.textContent).toBe("A caption");+ const section = `<section class="link-embed" ${PREVIEW_ATTRIBUTES}`+ + ` data-box-size="full" data-hide-title="true"> </section>`;+ expect(editor.getData()).toBe(`<p>Text</p><figure class="captioned-content-embed">`+ + `${section}<figcaption>A caption</figcaption></figure>`);++ editor.execute(TOGGLE_CAPTION_COMMAND_NAME);+ expect(editor.getData()).toBe(`<p>Text</p>${section}`);+ });++ it("loads a caption saved in a figure around its section, and saves it the same way", () => {+ const saved = `<figure class="captioned-content-embed"><section class="link-embed"`+ + ` style="--include-note-width:30em;" ${PREVIEW_ATTRIBUTES} data-box-size="medium"`+ + ` data-position="wrap-right"> </section><figcaption>A caption</figcaption>`+ + `</figure>`;+ editor.setData(`<p>Text</p>${saved}<p>After</p>`);++ const embed = getBlock(1);+ expect(isVideoEmbed(embed)).toBe(true);+ expect([ embed.getAttribute(SIZE_ATTRIBUTES.width), embed.getAttribute("position") ])+ .toEqual([ "30em", "wrap-right" ]);+ expect([ ...getCaptionOf(1).getChildren() ]+ .map((child) => child.is("$text") ? child.data : child.name)).toEqual([ "A caption" ]);+ expect(editor.model.document.getRoot()?.childCount).toBe(3);+ expect(editor.getData()).toBe(`<p>Text</p>${saved}<p>After</p>`);+ });++ it("keeps the caption of a figure whose content takes none as a paragraph after it", () => {+ editor.setData(`<figure class="captioned-content-embed"><section class="link-embed"`+ + ` data-url="https://example.com/" data-embed-type="opengraph"> </section>`+ + `<figcaption>A caption</figcaption></figure>`);++ expect([ getBlock(0).name, getBlock(1).name ]).toEqual([ "linkEmbed", "paragraph" ]);+ expect(editor.getData()).toMatch(/<\/section><p>A caption<\/p>$/);+ });++ it("drops a figure around its section with no caption, and keeps one with no content", () => {+ editor.setData(`<figure class="captioned-content-embed">${SAVED_PREVIEW}</figure>`+ + `<figure class="captioned-content-embed"><figcaption>Text</figcaption></figure>`);++ expect([ isVideoEmbed(getBlock(0)), getBlock(0).childCount ]).toEqual([ true, 0 ]);+ expect(getBlock(1).name).toBe("paragraph");+ expect(editor.getData()).toBe(`<section class="link-embed" ${PREVIEW_ATTRIBUTES}`+ + ` data-box-size="full" data-hide-title="true"> </section><p>Text</p>`);+ });+it("is resized in width at Medium, which a box size sets to its own width", () => {editor.setData(`<p>Text</p>${SAVED_PREVIEW}`);selectBlock(1);diff --git a/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.spec.ts b/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.spec.tsindex 7b7744e7c5..6d7627dabf 100644--- a/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.spec.ts+++ b/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.spec.ts@@ -368,9 +368,10 @@ describe("LinkEmbed commands", () => {expect(editor.getData()).toBe(`<p><a href="${url}">${url}</a></p>`);});- it("keeps the box, title and position of a video retitled in the dialog", async () => {+ it("keeps the box, title, position and caption of a retitled video", async () => {setModelData(editor.model, `[<contentEmbed boxSize="full" embedType="youtube"`- + ` position="right" title="T" url="${url}"></contentEmbed>]`);+ + ` position="right" title="T" url="${url}"><caption>Note</caption>`+ + `</contentEmbed>]`);await editor.execute(LINK_EMBED_COMMAND, { url, mode: "embed", title: "Mine" });@@ -379,9 +380,28 @@ describe("LinkEmbed commands", () => {expect(embed && Object.fromEntries(embed.getAttributes())).toEqual({url, embedType: "youtube", title: "Mine", boxSize: "full", position: "right"});+ expect(editor.getData()).toContain("</section><figcaption>Note</figcaption></figure>");expect(editor.model.document.selection.getSelectedElement()).toBe(embed);});+ it("acts on a video from its caption, and on a link in the caption from that link", () => {+ const caption = (text: string) => `<contentEmbed embedType="youtube" title="T"`+ + ` url="${url}"><caption>${text}</caption></contentEmbed>`;+ const link = "https://example.com/";+ setModelData(editor.model, caption("A [] caption"));+ const command = changeCommand(editor);+ expect([ command.isEnabled, command.value, command.url ])+ .toEqual([ true, "embed", url ]);++ editor.execute(CHANGE_LINK_DISPLAY_COMMAND, { value: "card" });+ expect(findElement(editor, "contentEmbed")).toBeUndefined();+ expect(findElement(editor, "linkEmbed")?.getAttribute("embedType")).toBe("opengraph");++ setModelData(editor.model, caption(`<$text linkHref="${link}">a[]b</$text>`));+ expect([ command.isEnabled, command.value, command.url ])+ .toEqual([ true, "plain", link ]);+ });+it("leaves other embeds alone", () => {setModelData(editor.model, "[<contentEmbed boxSize=\"medium\" noteId=\"n1\">"+ "</contentEmbed>]");diff --git a/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.ts b/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.tsindex 32be497157..547c012225 100644--- a/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.ts+++ b/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.ts@@ -6,6 +6,7 @@ import {type ModelWriter} from 'ckeditor5';+import { getCaptionedEmbed } from '../content_embed/content_embed.js';import { createVideoEmbed, isVideoEmbed } from '../content_embed/video_embed.js';export const LINK_EMBED_COMMAND = 'insertLinkEmbed';@@ -158,7 +159,7 @@ export class ChangeLinkDisplayCommand extends Command {override async execute(options: { value: LinkDisplayMode }) {const model = this.editor.model;- const selected = getSelectedLinkWidget(this.editor);+ const selected = this._getTarget();// No widget selected means the dropdown sits in the link balloon, over a native link.if (!selected) {@@ -190,7 +191,7 @@ export class ChangeLinkDisplayCommand extends Command {}override refresh() {- const selected = getSelectedLinkWidget(this.editor);+ const selected = this._getTarget();if (selected) {this.isEnabled = true;@@ -242,6 +243,21 @@ export class ChangeLinkDisplayCommand extends Command {await replaceLinkWithPreview(this.editor, range, href, targetMode);}+ /**+ * The link preview that the command acts on: the selected one, else, unless the caret is on a+ * link, the video whose caption has the selection, which keeps its toolbar there.+ */+ private _getTarget(): ModelElement | null {+ const selection = this.editor.model.document.selection;+ const selected = getSelectedLinkWidget(this.editor);+ if (selected || selection.hasAttribute('linkHref')) {+ return selected;+ }++ const video = getCaptionedEmbed(selection.getFirstPosition());+ return video && isVideoEmbed(video) ? video : null;+ }+/** Delegates to the host to avoid duplicating URL detection logic. */private _detectEmbedType(url: string): string {return getLinkEmbedHost(this.editor).detectEmbedType(url);@@ -341,11 +357,16 @@ function rebuildLinkWidget(// Replaced rather than given new attributes: the editing downcast is elementToElement, which// does not re-render on attribute changes. A preview that keeps its shape keeps its other- // attributes, such as the box of a video.+ // attributes, such as the box of a video, and its children, such as the caption of a video.const ownAttributes = Object.fromEntries(element.getAttributes());- const replacement = getLinkPreviewName(mode, attrs) === element.name+ const keepsShape = getLinkPreviewName(mode, attrs) === element.name;+ const replacement = keepsShape? writer.createElement(element.name, { ...ownAttributes, ...attrs }): createLinkPreview(writer, mode, attrs);+ // The only child of a link preview is the caption of a video.+ for (const caption of keepsShape ? element.getChildren() : []) {+ writer.append(writer.cloneElement(caption as ModelElement), replacement);+ }editor.model.insertContent(replacement, writer.createRangeOn(element));return replacement;}diff --git a/packages/commons/src/lib/content_embeds.ts b/packages/commons/src/lib/content_embeds.tsindex 366bf19bcb..1e5abc30db 100644--- a/packages/commons/src/lib/content_embeds.ts+++ b/packages/commons/src/lib/content_embeds.ts@@ -39,6 +39,13 @@ export const EXTENDED_CODE_BLOCK_DEFAULT_LANGUAGE = "text-plain";/** The class of the embed box of a video, in the editor and in read-only views. */export const VIDEO_EMBED_CLASS = "video-embed";+/**+ * The class of the `<figure>` that holds an embed saved as an element other than a `<figure>`,+ * such as the `<section>` of a video, and its `<figcaption>`. An embed without a caption is saved+ * without it.+ */+export const CAPTIONED_CONTENT_EMBED_CLASS = "captioned-content-embed";+/*** The attribute that marks a `<section>` as a content embed and names its kind, for kinds added* after include notes and source embeds. A version that does not know the kind keeps the sectiondiff --git a/packages/share-theme/src/content/content.css b/packages/share-theme/src/content/content.cssindex c9d47e0984..00543cd812 100644--- a/packages/share-theme/src/content/content.css+++ b/packages/share-theme/src/content/content.css@@ -344,20 +344,23 @@ body:not(.math-loaded) .math-tex {}/* An include, or the video of a link preview, placed and sized as the editor saved it. */-.ck-content :is(figure.include-note, section.link-embed:where([data-embed-type="youtube"])) {+.ck-content :is(+ figure.include-note, figure.captioned-content-embed,+ section.link-embed:where([data-embed-type="youtube"])+) {clear: both;margin: 1em 0;&:is([data-box-size="small"], [data-box-size="medium"], [data-box-size="expandable"],- .link-embed+ .link-embed, .captioned-content-embed) {margin-inline: auto;max-width: 100%;width: var(--include-note-width, auto);}- &.link-embed[data-box-size="full"] {+ &:is(.link-embed, :has(> .link-embed))[data-box-size="full"] {max-width: min(100%, 70vh * var(--video-aspect-ratio, 16 / 9));}@@ -392,8 +395,15 @@ body:not(.math-loaded) .math-tex {}}+.ck-content figure.captioned-content-embed > section.link-embed {+ margin: 0;+ width: auto;+}+@media (max-width: 48em) {- .ck-content :is(figure.include-note, section.link-embed)[data-position] {+ .ck-content :is(+ figure.include-note, figure.captioned-content-embed, section.link-embed+ )[data-position] {float: none;clear: both;margin: 1em 0;@@ -401,7 +411,7 @@ body:not(.math-loaded) .math-tex {}}-.ck-content .include-note > figcaption {+.ck-content :is(.include-note, .captioned-content-embed) > figcaption {margin-top: .5em;border-top: 1px solid var(--background-active);padding-top: .5em;diff --git a/packages/trilium-core/src/services/export/markdown.spec.ts b/packages/trilium-core/src/services/export/markdown.spec.tsindex c58136f18a..7194bcf4a0 100644--- a/packages/trilium-core/src/services/export/markdown.spec.ts+++ b/packages/trilium-core/src/services/export/markdown.spec.ts@@ -587,6 +587,16 @@ describe("Markdown export", () => {.toBe(`Before\n\n${captioned}\n\nAfter`);});+ it("preserves a video saved with its caption, with the fallback link of the video", () => {+ const url = "https://www.youtube.com/watch?v=abc";+ const section = `<section class="link-embed" data-url="${url}" data-embed-type="youtube">`;+ const figure = (content: string) => `<figure class="captioned-content-embed">${section}`+ + `${content}</section><figcaption>A <strong>caption</strong></figcaption></figure>`;++ expect(markdownExportService.toMarkdown(`<p>Before</p>${figure("")}<p>After</p>`))+ .toBe(`Before\n\n${figure(`<a href="${url}">${url}</a>`)}\n\nAfter`);+ });+it("exports todo lists properly", () => {const html = trimIndentation/*html*/`\<ul class="todo-list">diff --git a/packages/trilium-core/src/services/export/markdown.ts b/packages/trilium-core/src/services/export/markdown.tsindex 25dc61e7ca..abf7841edc 100644--- a/packages/trilium-core/src/services/export/markdown.ts+++ b/packages/trilium-core/src/services/export/markdown.ts@@ -1,6 +1,6 @@import {- getMarkdownNameFromCKEditorLanguage, MIME_TYPE_AUTO, MULTICOLUMN_COLUMN_CLASS,- MULTICOLUMN_LAYOUT_CLASS, safeLinkPreviewHref, type TaskStateDef+ CAPTIONED_CONTENT_EMBED_CLASS, getMarkdownNameFromCKEditorLanguage, MIME_TYPE_AUTO,+ MULTICOLUMN_COLUMN_CLASS, MULTICOLUMN_LAYOUT_CLASS, safeLinkPreviewHref, type TaskStateDef} from "@triliumnext/commons";import { ADMONITION_TYPE_MAPPINGS } from "@triliumnext/commons/src/lib/markdown_renderer.js";import { HIGHLIGHT_BACKGROUND } from "@triliumnext/commons/src/lib/marked_extensions.js";@@ -331,10 +331,14 @@ function buildFigureFilter(): Rule {};}-/** Whether `node` is an embed. Embeds saved before captions existed are `<section>`s. */+/**+ * Whether `node` is an embed, or the figure that holds an embed with its caption. Embeds saved+ * before captions existed are `<section>`s.+ */function isContentEmbed(node: Pick<LinkPreviewNodeLike, "nodeName" | "classList">) {- return (node.nodeName === "FIGURE" || node.nodeName === "SECTION")- && node.classList.contains("include-note");+ return ((node.nodeName === "FIGURE" || node.nodeName === "SECTION")+ && node.classList.contains("include-note"))+ || (node.nodeName === "FIGURE" && node.classList.contains(CAPTIONED_CONTENT_EMBED_CLASS));}/**diff --git a/packages/trilium-core/src/share/content_renderer.spec.ts b/packages/trilium-core/src/share/content_renderer.spec.tsindex 64f4b81032..97c46dfa71 100644--- a/packages/trilium-core/src/share/content_renderer.spec.ts+++ b/packages/trilium-core/src/share/content_renderer.spec.ts@@ -1093,6 +1093,26 @@ describe("content_renderer", () => {]);});+ it("places a video saved with a caption by the figure that holds both", () => {+ const note = buildShareNote({+ content: `<figure class="captioned-content-embed"><section class="link-embed"`+ + ` style="--include-note-width:30em;"`+ + ` data-url="https://www.youtube.com/watch?v=dQw4w9WgXcQ"`+ + ` data-embed-type="youtube" data-box-size="medium"`+ + ` data-position="wrap-right"> </section>`+ + `<figcaption>A caption</figcaption></figure>`+ });++ const figure = parse(String(getContent(note).content)).querySelector("figure");+ const section = figure?.querySelector("section.link-embed");+ const box = (element: typeof section) => [ "style", "data-box-size", "data-position" ]+ .map((name) => element?.getAttribute(name));+ expect(box(figure)).toEqual([ "--include-note-width:30em;", "medium", "wrap-right" ]);+ expect(box(section)).toEqual([ undefined, undefined, undefined ]);+ expect(section?.querySelector(".link-embed-video-facade")).not.toBeNull();+ expect(figure?.querySelector("figcaption")?.textContent).toBe("A caption");+ });+it("neuters a hostile scheme in the stored URL, on a page served to anyone", () => {// `data-*` values pass through the save-time sanitizer verbatim, so a note that arrives// by import, ETAPI or sync can carry `data-url="javascript:…"`. It must not become adiff --git a/packages/trilium-core/src/share/content_renderer.ts b/packages/trilium-core/src/share/content_renderer.tsindex d3ccbef94d..f69bf4532b 100644--- a/packages/trilium-core/src/share/content_renderer.ts+++ b/packages/trilium-core/src/share/content_renderer.ts@@ -1,6 +1,7 @@import type { PreviewThemeSlot } from "@triliumnext/codemirror/src/code_preview.js";import {- BLOCK_ID_ATTRIBUTE, CANVAS_ATTACHMENT_MIME, CONTENT_EMBED_KIND_ATTRIBUTE, encodeBlockParameter,+ BLOCK_ID_ATTRIBUTE, CANVAS_ATTACHMENT_MIME, CAPTIONED_CONTENT_EMBED_CLASS,+ CONTENT_EMBED_KIND_ATTRIBUTE, encodeBlockParameter,getAttachmentEmbedHref, getDrawingPictureTitle, getEmbedKey, getLinkPreviewVideoId,getNestedEmbedOptions, getNoteEmbedHref, getVideoAspectRatio, isHttpUrl, isImageAttachmentRole,MIME_TYPE_AUTO, type MimeType, normalizeMimeTypeForCKEditor, readLinkPreviewData,@@ -642,6 +643,7 @@ function renderText(result: Result, note: SNote | BNote, options: ShareRenderOptembedEl.innerHTML = renderLinkEmbedHtml(data, previewOptions);if (getLinkPreviewVideoId(data)) {setVideoBox(embedEl, getVideoAspectRatio(data));+ moveBoxToCaptionedFigure(embedEl);}}}@@ -805,6 +807,29 @@ function setVideoBox(section: HTMLElement, aspectRatio: number | null) {}}+/** The attributes that size and place the box of an embed. */+const EMBED_BOX_ATTRIBUTES = [ "style", "data-box-size", "data-position" ];++/**+ * Moves the box of `element`, an embed saved with a caption, onto the+ * `<figure class="captioned-content-embed">` that holds both, which the share theme then places+ * and sizes as it does the embed.+ */+function moveBoxToCaptionedFigure(element: HTMLElement) {+ const figure = element.parentNode;+ if (figure?.tagName !== "FIGURE" || !figure.classList.contains(CAPTIONED_CONTENT_EMBED_CLASS)) {+ return;+ }++ for (const name of EMBED_BOX_ATTRIBUTES) {+ const value = element.getAttribute(name);+ if (value !== undefined) {+ figure.setAttribute(name, value);+ element.removeAttribute(name);+ }+ }+}+/*** What an embedded attachment shows: a picture as an image, a canvas drawing as the picture that* its note keeps of it, at the size of the picture, and anything else, or a drawing without a