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/link editor: add support for editing the description
Adorian Doran43abb87abad9
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 5052aee221..6ae76b3b04 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -76,6 +76,8 @@"display_card": "Card","display_embed": "YouTube embed","page_title": "Title of the web page",+ "description": "Description",+ "page_description": "Description of the web page","anchors": "Anchors","target_anchor": "Target anchor","no_anchors": "No anchors available."diff --git a/apps/client/src/widgets/dialogs/edit_link.css b/apps/client/src/widgets/dialogs/edit_link.cssindex 9e2387061a..715ca3ed51 100644--- a/apps/client/src/widgets/dialogs/edit_link.css+++ b/apps/client/src/widgets/dialogs/edit_link.css@@ -26,7 +26,7 @@/* Matches the 500px at which Card.css stacks a wide control under its label. */@container (min-width: 501px) {- :is(.edit-link-note, .edit-link-url, .edit-link-text) {+ :is(.edit-link-note, .edit-link-url, .edit-link-text, .edit-link-description) {--edit-link-label-width: 8em;> .tn-card-option-label {@@ -45,6 +45,10 @@}}+ .edit-link-description textarea {+ resize: none;+ }+.edit-link-target {display: flex;width: fit-content;diff --git a/apps/client/src/widgets/dialogs/edit_link.spec.tsx b/apps/client/src/widgets/dialogs/edit_link.spec.tsxindex e68955de66..39c3d69e4e 100644--- a/apps/client/src/widgets/dialogs/edit_link.spec.tsx+++ b/apps/client/src/widgets/dialogs/edit_link.spec.tsx@@ -112,6 +112,10 @@ describe("EditLinkDialog", () => {return container.querySelector<HTMLSelectElement>(".edit-link-display select");}+ function description() {+ return container.querySelector<HTMLTextAreaElement>(".edit-link-description textarea");+ }+function anchorRows() {return [ ...container.querySelectorAll<HTMLElement>(".edit-link-anchors .tn-card-choice") ];}@@ -326,7 +330,7 @@ describe("EditLinkDialog", () => {await pickDisplay("card");await type(field("text"), "Never gonna");await submit();- expect(addLinkPreview).toHaveBeenLastCalledWith(video, "card", "Never gonna");+ expect(addLinkPreview).toHaveBeenLastCalledWith(video, "card", "Never gonna", null);expect(addLink).not.toHaveBeenCalled();// A player shows no title.@@ -334,7 +338,7 @@ describe("EditLinkDialog", () => {await type(field("url"), video);expect(field("text")).toBeNull();await submit();- expect(addLinkPreview).toHaveBeenLastCalledWith(video, "embed", null);+ expect(addLinkPreview).toHaveBeenLastCalledWith(video, "embed", null, null);// A plain link, and any address that is not a web page, stays a link.await open({ target: "url", addLinkPreview });@@ -369,12 +373,12 @@ describe("EditLinkDialog", () => {await open({ currentLink: { externalLink: url }, currentTitle: url, addLinkPreview });await pickDisplay("inline");await submit();- expect(addLinkPreview).toHaveBeenLastCalledWith(url, "inline", null);+ expect(addLinkPreview).toHaveBeenLastCalledWith(url, "inline", null, null);await open({ currentLink: { externalLink: url }, currentTitle: "Page", addLinkPreview });await pickDisplay("card");await submit();- expect(addLinkPreview).toHaveBeenLastCalledWith(url, "card", "Page");+ expect(addLinkPreview).toHaveBeenLastCalledWith(url, "card", "Page", null);expect(addLink).not.toHaveBeenCalled();});@@ -389,7 +393,7 @@ describe("EditLinkDialog", () => {[ "add_link.display_plain", "add_link.display_inline", "add_link.display_card" ]);await submit();- expect(addLinkPreview).toHaveBeenLastCalledWith(url, "card", "Page");+ expect(addLinkPreview).toHaveBeenLastCalledWith(url, "card", "Page", null);await open({currentLink: { externalLink: url }, currentTitle: "Page", display: "card", addLinkPreview@@ -400,7 +404,8 @@ describe("EditLinkDialog", () => {await type(field("url"), "https://example.com/third");expect(field("text")?.value).toBe("Mine");await submit();- expect(addLinkPreview).toHaveBeenLastCalledWith("https://example.com/third", "card", "Mine");+ expect(addLinkPreview)+ .toHaveBeenLastCalledWith("https://example.com/third", "card", "Mine", null);// A plain link keeps its text for another address.await open({ currentLink: { externalLink: url }, currentTitle: "Page", addLinkPreview });@@ -408,6 +413,43 @@ describe("EditLinkDialog", () => {expect(field("text")?.value).toBe("Page");});+ it("edits a card's description, which another address takes from its page", async () => {+ const url = "https://example.com/page";+ const preview = {+ currentLink: { externalLink: url }, currentTitle: "Page", currentDescription: "About",+ addLinkPreview+ };+ await open({ ...preview, display: "inline" });+ expect(description()).toBeNull();+ await pickDisplay("card");+ expect(description()?.value).toBe("About");+ expect(description()?.getAttribute("rows")).toBe("2");+ const order = ".edit-link-text + .edit-link-description + .edit-link-display";+ expect(container.querySelector(order)).not.toBeNull();+ await type(description(), " Mine ");+ await submit();+ expect(addLinkPreview).toHaveBeenLastCalledWith(url, "card", "Page", "Mine");++ // An emptied description leaves the stored one, and only a card shows one.+ await open({ ...preview, display: "card" });+ await type(description(), " ");+ await submit();+ expect(addLinkPreview).toHaveBeenLastCalledWith(url, "card", "Page", null);+ await open({ ...preview, display: "card" });+ await pickDisplay("inline");+ expect(description()).toBeNull();+ await submit();+ expect(addLinkPreview).toHaveBeenLastCalledWith(url, "inline", "Page", null);++ await open({ ...preview, display: "card" });+ await type(field("url"), "https://example.com/other");+ expect(description()?.value).toBe("");+ // Typed after the change, even the old description stays.+ await type(description(), "About");+ await type(field("url"), "https://example.com/third");+ expect(description()?.value).toBe("About");+ });+it("offers no web link when fixing a link to a missing note", async () => {await open({ text: "Gone", fixLink: true });expect(choice()).toStrictEqual([]);@@ -573,9 +615,33 @@ describe("EditLinkBalloon", () => {expect(onClose).toHaveBeenCalledTimes(2);expect(addLink).toHaveBeenLastCalledWith("#intro", "intro", true);});++ it("applies a card on Enter in its description, but not mid-composition", async () => {+ const addLinkPreview = vi.fn<NonNullable<EditLinkOpts["addLinkPreview"]>>(async () => {});+ const form = await show({ target: "url", display: "card", addLinkPreview });+ await type(form.querySelector<HTMLInputElement>(".edit-link-url input"), "example.com");+ const textarea = form.querySelector<HTMLTextAreaElement>(".edit-link-description textarea");+ await type(textarea, "About");++ async function pressEnter(isComposing: boolean) {+ const enter = new KeyboardEvent("keydown", {+ key: "Enter", isComposing, bubbles: true, cancelable: true+ });+ await act(async () => {+ textarea?.dispatchEvent(enter);+ });+ return enter.defaultPrevented;+ }+ expect(await pressEnter(true)).toBe(false);+ expect(onClose).not.toHaveBeenCalled();+ expect(await pressEnter(false)).toBe(true);+ expect(onClose).toHaveBeenCalledOnce();+ expect(addLinkPreview)+ .toHaveBeenCalledExactlyOnceWith("https://example.com", "card", null, "About");+ });});-async function type(input: HTMLInputElement | null, value: string) {+async function type(input: HTMLInputElement | HTMLTextAreaElement | null, value: string) {if (!input) throw new Error("The field is not shown.");await act(async () => {input.value = value;diff --git a/apps/client/src/widgets/dialogs/edit_link.tsx b/apps/client/src/widgets/dialogs/edit_link.tsxindex 764fe5adfb..88140c5ad9 100644--- a/apps/client/src/widgets/dialogs/edit_link.tsx+++ b/apps/client/src/widgets/dialogs/edit_link.tsx@@ -15,6 +15,7 @@ import { logError } from "../../services/ws";import Button from "../react/Button";import { Card, CardSection, ChoiceCardSection, OptionCardSection } from "../react/Card";import FormSelect from "../react/FormSelect";+import FormTextArea from "../react/FormTextArea";import FormTextBox from "../react/FormTextBox";import FormToggle from "../react/FormToggle";import { useTriliumEvent } from "../react/hooks";@@ -75,6 +76,8 @@ export interface EditLinkOpts {* and keeps this text until another note or anchor is picked.*/currentTitle?: string;+ /** The description of the link preview being edited. */+ currentDescription?: string;/** The anchor within the note that the link being edited points at. */currentBookmark?: string;/**@@ -103,9 +106,11 @@ export interface EditLinkOpts {/*** Puts a preview of the web link in place of the link. A caller that can show previews passes* it, and the dialog then offers the choice of how a web link is displayed, except for a link- * on a selection. `title` replaces the page's own title.+ * on a selection. `title` and `description` replace the page's own.*/- addLinkPreview?(url: string, display: LinkDisplayMode, title: string | null): Promise<void>;+ addLinkPreview?(+ url: string, display: LinkDisplayMode, title: string | null, description: string | null+ ): Promise<void>;}export default function EditLinkDialog() {@@ -190,6 +195,7 @@ export function EditLinkBalloon({ opts, onClose }: { opts: EditLinkOpts; onClose/** The state and the fields of the link dialog for `opts`, shared by the modal and the balloon. */function useEditLinkForm(opts: EditLinkOpts | undefined) {const [ linkTitle, setLinkTitle ] = useState("");+ const [ linkDescription, setLinkDescription ] = useState("");const [ linkType, setLinkType ] = useState<LinkType>();const [ suggestion, setSuggestion ] = useState<Suggestion | null>(null);const [ bookmarks, setBookmarks ] = useState<string[]>([]);@@ -207,6 +213,8 @@ function useEditLinkForm(opts: EditLinkOpts | undefined) {const initialBookmarkRef = useRef("");// The title of the link preview being edited, while the title field still shows it.const previewTitleRef = useRef<string | null>(null);+ // The description of the link preview being edited, while the description field still shows it.+ const previewDescriptionRef = useRef<string | null>(null);// On mobile, focusing a field opens the keyboard, so a field waits for a tap.const autoFocus = !isMobile();@@ -227,6 +235,8 @@ function useEditLinkForm(opts: EditLinkOpts | undefined) {? opts.currentTitle ?? null : null;initialBookmarkRef.current = opts?.currentBookmark ?? "";setLinkTitle(opts?.currentTitle ?? "");+ previewDescriptionRef.current = opts?.currentDescription ?? null;+ setLinkDescription(opts?.currentDescription ?? "");// Taken as though it had just been picked, so that a dialog opened on a link and left alone// has one to apply — and so that everything a pick settles (the title, the anchors a note@@ -239,11 +249,16 @@ function useEditLinkForm(opts: EditLinkOpts | undefined) {setWebLink(text);const link = normalizeWebLink(text);setSuggestion(link ? { externalLink: link } : null);- // A preview's title is its page's, so another address takes the title of its own page.+ // A preview's title and description are its page's, so another address takes those of its+ // own page.if (previewTitleRef.current !== null && linkTitle === previewTitleRef.current) {setLinkTitle("");}previewTitleRef.current = null;+ if (linkDescription === previewDescriptionRef.current) {+ setLinkDescription("");+ }+ previewDescriptionRef.current = null;}function changeTarget(next: LinkTarget, text = "") {@@ -251,6 +266,7 @@ function useEditLinkForm(opts: EditLinkOpts | undefined) {setTarget(next);setNoteTitle("");setLinkTitle("");+ setLinkDescription("");setLinkType(opts?.hasSelection ? "hyper-link" : "reference-link");setAnchor("");if (next === "url") {@@ -403,6 +419,8 @@ function useEditLinkForm(opts: EditLinkOpts | undefined) {const showsTitle = !opts?.hasSelection && !opts?.targetOnly && !opts?.fixLink;// A video player shows no title.const showsWebLinkTitle = showsTitle && !(showsDisplay && shownDisplay === "embed");+ // Only a card shows a description.+ const showsDescription = showsTitle && showsDisplay && shownDisplay === "card";/** Applies the link picked, through `opts.addLink` or `opts.addLinkPreview`. */function applyLink() {@@ -429,7 +447,8 @@ function useEditLinkForm(opts: EditLinkOpts | undefined) {if (isPreview && opts.addLinkPreview) {// A text that only repeats the address leaves the page's own title.const title = shownDisplay !== "embed" && text && text !== url ? text : null;- void opts.addLinkPreview(url, shownDisplay, title);+ const description = showsDescription ? linkDescription.trim() || null : null;+ void opts.addLinkPreview(url, shownDisplay, title, description);return;}// An external link without a text of its own reads as its address.@@ -552,6 +571,27 @@ function useEditLinkForm(opts: EditLinkOpts | undefined) {{showsWebLinkTitle && titleSection}+ {showsDescription && (+ <OptionCardSection+ className="edit-link-description" name="link-description"+ label={t("add_link.description")}+ >+ <FormTextArea+ rows={2}+ currentValue={linkDescription}+ placeholder={t("add_link.page_description")}+ onChange={setLinkDescription}+ onKeyDown={(e) => {+ // A card shows its description as one paragraph, so+ // Enter saves the link as in the other fields.+ if (e.key !== "Enter" || e.isComposing) return;+ e.preventDefault();+ e.currentTarget.form?.requestSubmit();+ }}+ />+ </OptionCardSection>+ )}+{showsDisplay && (<OptionCardSectionclassName="edit-link-display" name="display"diff --git a/apps/client/src/widgets/type_widgets/text/CKEditor.tsx b/apps/client/src/widgets/type_widgets/text/CKEditor.tsxindex bdd6093841..bc6d29e13c 100644--- a/apps/client/src/widgets/type_widgets/text/CKEditor.tsx+++ b/apps/client/src/widgets/type_widgets/text/CKEditor.tsx@@ -33,9 +33,11 @@ export interface CKEditorApi {updateLink(notePath: string, linkTitle: string | null, externalLink?: boolean): Promise<void>;/*** Puts a preview of `url` in place of the link around the caret or the selected link preview,- * or at the selection. `title` replaces the page's own title.+ * or at the selection. `title` and `description` replace the page's own.*/- addLinkPreview(url: string, display: LinkDisplayMode, title: string | null): void;+ addLinkPreview(+ url: string, display: LinkDisplayMode, title: string | null, description: string | null+ ): void;addLinkToEditor(linkHref: string, linkTitle: string): void;addHtmlToEditor(html: string): void;addContentEmbed(noteId: string, boxSize?: BoxSize): void;@@ -215,12 +217,14 @@ export default function CKEditor({const href = externalLink ? notePath : `#${notePath}`;await replaceLinkAtSelection(editor, href, linkTitle);},- addLinkPreview(url, display, title) {+ addLinkPreview(url, display, title, description) {const editor = editorRef.current;if (!editor) return;editor.editing.view.focus();- void editor.execute("insertLinkEmbed", { url, mode: display, title: title ?? undefined });+ void editor.execute("insertLinkEmbed", {+ url, mode: display, title: title ?? undefined, description: description ?? undefined+ });},addLink(notePath, linkTitle, externalLink) {const editor = editorRef.current;diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts b/apps/client/src/widgets/type_widgets/text/EditableText.spec.tsindex 24945f2611..fae7d2009e 100644--- a/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts+++ b/apps/client/src/widgets/type_widgets/text/EditableText.spec.ts@@ -487,16 +487,18 @@ describe("getEditLinkOpts", () => {expect(api.updateLink).toHaveBeenCalledExactlyOnceWith("root/def", "Elsewhere", undefined);expect(api.addLink).not.toHaveBeenCalled();- await opts.addLinkPreview?.("https://example.com", "card", "Example");+ await opts.addLinkPreview?.("https://example.com", "card", "Example", "About");expect(api.addLinkPreview)- .toHaveBeenCalledExactlyOnceWith("https://example.com", "card", "Example");+ .toHaveBeenCalledExactlyOnceWith("https://example.com", "card", "Example", "About");});it("edits a selected link preview as a web link titled by its title, shown as it is", () => {- const api = createApi({ href: "https://example.com", text: "Example", display: "card" });+ const api = createApi({+ href: "https://example.com", text: "Example", description: "About", display: "card"+ });expect(getEditLinkOpts(api, ready, { display: "inline" })).toMatchObject({currentLink: { externalLink: "https://example.com" }, currentTitle: "Example",- display: "card"+ currentDescription: "About", display: "card"});});@@ -510,9 +512,9 @@ describe("getEditLinkOpts", () => {expect(api.addLink).toHaveBeenCalledExactlyOnceWith("https://example.com", "Example", true);expect(api.updateLink).not.toHaveBeenCalled();- await opts.addLinkPreview?.("https://example.com", "inline", null);+ await opts.addLinkPreview?.("https://example.com", "inline", null, null);expect(api.addLinkPreview)- .toHaveBeenCalledExactlyOnceWith("https://example.com", "inline", null);+ .toHaveBeenCalledExactlyOnceWith("https://example.com", "inline", null, null);});it("offers the document's anchors, and edits a link to one of them as that anchor", () => {diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsxindex c48858c5d0..0394bd6191 100644--- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx+++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx@@ -605,6 +605,7 @@ export function getEditLinkOpts(text: currentLink.text,hasSelection: false,currentTitle: currentLink.text,+ currentDescription: currentLink.description,display: currentLink.display,anchors,...parseLinkHref(currentLink.href, anchors),diff --git a/apps/server/src/assets/help/help_content.json b/apps/server/src/assets/help/help_content.jsonindex 9a3b504b48..053c46afae 100644--- a/apps/server/src/assets/help/help_content.json+++ b/apps/server/src/assets/help/help_content.json@@ -138,7 +138,7 @@"_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>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></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 three 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.</li><li>Press <kbd>Enter</kbd> or <em>Add 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. 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 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) and how it is displayed. A new address shows the title of the new page, unless you type one.</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><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 and channel name 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></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 three 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>Add 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. 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 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><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 and channel name 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>Add 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><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, chosen with the <em>Mirror the note's title</em> switch of the dialog, which is on by default:</p><ol><li>With the switch on, the link mirrors the note's title.<ol><li>This is sometimes also called \"reference link\".</li><li>The title of this link cannot be changed. Instead, it will always show the current title of the linked note.</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>With the switch off, the link has a title of its own, typed in the <em>Link title</em> field.<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 whose title does not mirror the note's, click it and press the <span class=\"tn-icon cke cke-pencil\"></span> <em>Edit link</em> button in its popup, or place the cursor inside it and press <kbd>Ctrl</kbd> + <kbd>L</kbd> or the <span class=\"tn-icon cke cke-trilium\"></span> button. The <em>Edit link</em> dialog opens on the linked note, with its anchor and the link's text; <em>Save link</em> changes the whole link. Turning <em>Mirror the note's title</em> on there turns it into a link that mirrors the title.</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/Link Previews.md b/docs/User Guide/User Guide/Note Types/Text/Link Previews.mdindex 704598751c..27d18b9e02 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@@ -55,7 +55,7 @@ Since v0.107.0, a link preview is created from the same _Add link_ dialog as any* Press <span class="tn-icon cke cke-link"></span> in the <a class="reference-link" href="Formatting%20toolbar.md">Formatting toolbar</a>, or press <kbd>Ctrl</kbd>+<kbd>K</kbd>, to open the dialog on _Web link_.* Type or paste the address, then pick the preview in _Display as_: _Inline_, _Card_ or, for a YouTube video, _YouTube embed_. _Plain link_ inserts an ordinary link. _Display as_ is not shown when text is selected, since the link then keeps the selected text.-* Optionally, type a _Link title_ to show instead of the page's own title.+* Optionally, type a _Link title_ to show instead of the page's own title. A _Card_ also offers a _Description_ to show instead of the page's own description.* Press <kbd>Enter</kbd> or _Add link_ to confirm. The link appears right away and turns into the preview once Trilium has read the page.Alternatively, use <a class="reference-link" href="Slash%20Commands.md">Slash Commands</a> and look for _link preview_ (it is also found by _embed_, _url_ or _video_). It opens the same dialog with a preview already picked: a _YouTube embed_ for a YouTube video, a _Card_ for any other page.@@ -73,7 +73,7 @@ When _Autogenerate link previews_ is turned off, the tabs are saved as a list ofClick on an inserted link preview to select it, and a small toolbar will appear with the following options:* The normal link operations (opening in a new tab, copying the link, unlinking).-* The <span class="tn-icon cke cke-pencil"></span> _Edit link_ button, which opens the _Edit link_ dialog on the link preview, as does pressing <kbd>Ctrl</kbd>+<kbd>K</kbd> while it is selected. The dialog changes its address, its _Link title_ (especially useful if the title is hidden behind a login screen) and how it is displayed. A new address shows the title of the new page, unless you type one.+* The <span class="tn-icon cke cke-pencil"></span> _Edit link_ button, which opens the _Edit link_ dialog on the link preview, as does pressing <kbd>Ctrl</kbd>+<kbd>K</kbd> while it is selected. The dialog changes its address, its _Link title_ (especially useful if the title is hidden behind a login screen), the _Description_ 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.* A way to switch between the link preview modes (Inline, Card or Embed) as well as to convert it to a normal link instead.* The Embed option is only enabled when the URL points to a supported service (YouTube today).diff --git a/packages/ckeditor5/src/plugins/internallink.spec.ts b/packages/ckeditor5/src/plugins/internallink.spec.tsindex 03340ca8b7..8529e1dab9 100644--- a/packages/ckeditor5/src/plugins/internallink.spec.ts+++ b/packages/ckeditor5/src/plugins/internallink.spec.ts@@ -213,14 +213,16 @@ describe("the link at the selection", () => {it("reads a selected link preview as a link titled by its title, shown as it is", () => {setModelData(editor.model, "<paragraph>a [<linkMention url=\"https://a.example\""- + " title=\"A\"></linkMention>]</paragraph>");- expect(getLinkAtSelection(editor))- .toStrictEqual({ href: "https://a.example", text: "A", display: "inline" });+ + " title=\"A\" description=\"About A\"></linkMention>]</paragraph>");+ expect(getLinkAtSelection(editor)).toStrictEqual(+ { href: "https://a.example", text: "A", description: "About A", display: "inline" }+ );setModelData(editor.model,"[<linkEmbed url=\"https://a.example\" embedType=\"opengraph\"></linkEmbed>]");- expect(getLinkAtSelection(editor))- .toStrictEqual({ href: "https://a.example", text: "", display: "card" });+ expect(getLinkAtSelection(editor)).toStrictEqual(+ { href: "https://a.example", text: "", description: "", display: "card" }+ );});it("replaces a selected link preview, in a paragraph of its own for a block one", async () => {diff --git a/packages/ckeditor5/src/plugins/internallink.ts b/packages/ckeditor5/src/plugins/internallink.tsindex 0268cde7ea..7b2c222b17 100644--- a/packages/ckeditor5/src/plugins/internallink.ts+++ b/packages/ckeditor5/src/plugins/internallink.ts@@ -181,6 +181,8 @@ export interface LinkAtSelection {href: string;/** The whole text of a link, or the title of a preview. */text: string;+ /** The description of a preview. A link has none. */+ description?: string;display: LinkDisplayMode;}@@ -191,6 +193,7 @@ export function getLinkAtSelection(editor: Editor): LinkAtSelection | null {return {href: preview.getAttribute('url') as string,text: (preview.getAttribute('title') as string | undefined) ?? '',+ description: (preview.getAttribute('description') as string | undefined) ?? '',display: getLinkWidgetMode(preview)};}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 b7ec5d0ff2..1221dbd32c 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@@ -75,22 +75,23 @@ describe("LinkEmbed commands", () => {expect(editor.getData()).toBe(`<p><a href="${url}">The article</a></p>`);});- it("shows the link at once, then the preview titled as asked once fetched", async () => {+ it("shows the link at once, then the preview as titled and described", async () => {const url = "https://example.com/article";const { resolveFetch } = useDeferredFetch(fetchMetadata);setModelData(editor.model, "<paragraph>see []</paragraph>");const executed = editor.execute(LINK_EMBED_COMMAND, {- url, mode: "inline", title: "My title"+ url, mode: "card", title: "My title", description: "My description"}) as unknown as Promise<void>;expect(editor.getData()).toBe(`<p>see <a href="${url}">My title</a></p>`);resolveFetch({ ...META, url });await executed;- const mention = findElement(editor, "linkMention");- expect(mention?.getAttribute("title")).toBe("My title");- expect(mention?.getAttribute("description")).toBe(META.description);- expect(editor.model.document.selection.getSelectedElement()).toBe(mention);+ const card = findElement(editor, "linkEmbed");+ expect(card?.getAttribute("title")).toBe("My title");+ expect(card?.getAttribute("description")).toBe("My description");+ expect(card?.getAttribute("image")).toBe(META.image);+ expect(editor.model.document.selection.getSelectedElement()).toBe(card);});it("replaces the link the selection is in, which is the link being edited", async () => {@@ -122,9 +123,14 @@ describe("LinkEmbed commands", () => {expect(card?.getAttribute("description")).toBe("About");expect(editor.model.document.selection.getSelectedElement()).toBe(card);- // Without a title, the stored one stays.+ await editor.execute(LINK_EMBED_COMMAND, { url, mode: "card", description: "My own" });+ expect(findElement(editor, "linkEmbed")?.getAttribute("description")).toBe("My own");++ // Without a title or a description, the stored ones stay.await editor.execute(LINK_EMBED_COMMAND, { url, mode: "inline" });- expect(findElement(editor, "linkMention")?.getAttribute("title")).toBe("Mine");+ const mention = findElement(editor, "linkMention");+ expect(mention?.getAttribute("title")).toBe("Mine");+ expect(mention?.getAttribute("description")).toBe("My own");});it("replaces a selected preview of another address, or turned into a plain link", async () => {diff --git a/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.ts b/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.tsindex 5668b070be..aefbddcdfb 100644--- a/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.ts+++ b/packages/ckeditor5/src/plugins/link_embed/link_embed_commands.ts@@ -59,26 +59,29 @@ export type MetaKey = (typeof META_KEYS)[number];/*** Puts a link to `url` at the selection, or in place of the link or the link preview the selection* is in, and turns it into a preview of the `mode` shape once the page's metadata arrives. `title`- * replaces the page's own title, and is the text of a plain link.+ * replaces the page's own title, and is the text of a plain link. `description` replaces the page's+ * own description.*- * A selected preview of `url` changes its shape and title from the metadata it stores, without- * fetching the page again.+ * A selected preview of `url` changes its shape, title and description from the metadata it+ * stores, without fetching the page again.** All the metadata is written onto the element whichever shape is chosen — an inline mention stores* the description and image it does not itself show — so that switching modes later, via the widget* toolbar's Display dropdown, never has to go back to the network.*/export class InsertLinkEmbedCommand extends Command {- override async execute(- { url, mode, title }: { url: string; mode: LinkDisplayMode; title?: string }- ) {+ override async execute({ url, mode, title, description }: {+ url: string; mode: LinkDisplayMode; title?: string; description?: string;+ }) {const editor = this.editor;const model = editor.model;const selection = model.document.selection;const selected = getSelectedLinkWidget(editor);if (selected && mode !== 'plain' && selected.getAttribute('url') === url) {model.change((writer) => {- writer.setSelection(rebuildLinkWidget(editor, writer, selected, mode, title), 'on');+ writer.setSelection(+ rebuildLinkWidget(editor, writer, selected, mode, title, description), 'on'+ );});return;}@@ -99,7 +102,7 @@ export class InsertLinkEmbedCommand extends Command {});if (mode !== 'plain') {- await replaceLinkWithPreview(editor, linkRange, url, mode, title);+ await replaceLinkWithPreview(editor, linkRange, url, mode, title, description);}}@@ -209,7 +212,7 @@ export class ChangeLinkDisplayCommand extends Command {if (targetMode === 'plain') return;const range = findAttributeRange(position, 'linkHref', href, model);- await replaceLinkWithPreview(this.editor, range, href, targetMode, undefined);+ await replaceLinkWithPreview(this.editor, range, href, targetMode);}/** Delegates to the host to avoid duplicating URL detection logic. */@@ -240,7 +243,7 @@ export class RemoveLinkEmbedCommand extends Command {/*** Replaces the link to `href` in `range` with a preview of the `mode` shape, once the page's- * metadata arrives, and selects it. `title` replaces the page's own title.+ * metadata arrives, and selects it. `title` and `description` replace the page's own.** The range is tracked as a live range while the metadata is fetched, so edits made meanwhile do* not shift what gets replaced. Nothing is replaced when the link is no longer in the range by@@ -248,7 +251,7 @@ export class RemoveLinkEmbedCommand extends Command {*/async function replaceLinkWithPreview(editor: Editor, range: ModelRange, href: string,- mode: Exclude<LinkDisplayMode, 'plain'>, title: string | undefined+ mode: Exclude<LinkDisplayMode, 'plain'>, title?: string, description?: string) {const model = editor.model;const liveRange = ModelLiveRange.fromRange(range);@@ -274,7 +277,7 @@ async function replaceLinkWithPreview(: mode === 'embed' ? getLinkEmbedHost(editor).detectEmbedType(href): metadata.embedType,title: title || metadata.title,- description: metadata.description,+ description: description || metadata.description,favicon: metadata.favicon,siteName: metadata.siteName,image: metadata.image@@ -288,11 +291,11 @@ async function replaceLinkWithPreview(/*** Replaces the link preview `element` with one of the `mode` shape, built from the metadata it- * stores, and returns it. `title` replaces its title.+ * stores, and returns it. `title` and `description` replace its own.*/function rebuildLinkWidget(editor: Editor, writer: ModelWriter, element: ModelElement,- mode: Exclude<LinkDisplayMode, 'plain'>, title?: string+ mode: Exclude<LinkDisplayMode, 'plain'>, title?: string, description?: string) {const attrs: Record<string, unknown> = {};for (const key of META_KEYS) {@@ -300,6 +303,7 @@ function rebuildLinkWidget(if (val != null) attrs[key] = val;}if (title) attrs.title = title;+ if (description) attrs.description = description;if (mode !== 'inline') {// A card is an embed that declines to play.attrs.embedType = mode === 'card' ? 'opengraph'