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: fix some issues
Adorian Doran143d9d9e8325
diff --git a/apps/client/src/services/link.spec.ts b/apps/client/src/services/link.spec.tsindex 7c811d5882..a4b5bf5e7c 100644--- a/apps/client/src/services/link.spec.ts+++ b/apps/client/src/services/link.spec.ts@@ -792,6 +792,11 @@ describe("goToLinkExt", () => {click("#root/abcdefghijkl?block=h", undefined, { shiftKey: true });expect(openInCurrentNoteContext).toHaveBeenCalledTimes(4);expect(triggerCommand).toHaveBeenCalledOnce();+ // So does a link that asks for a popup or a new tab.+ click("#root/abcdefghijkl?block=h&popup");+ click("#root/abcdefghijkl?block=h", $("<a target='_blank'>").appendTo(content));+ expect(triggerCommand).toHaveBeenLastCalledWith("openInPopup", expect.anything());+ expect(openTabWithNoteWithHoisting).toHaveBeenCalledOnce();expect(showBlockReference).toHaveBeenCalledOnce();split.remove();});@@ -1340,6 +1345,15 @@ describe("block references", () => {.toBe("Live heading");expect(linkService.getReferenceLinkTitleSync(href("gone"), "Stored", live)).toBe("block_reference.broken");++ // The editor of an excerpt holds only some blocks; the others are read from the note.+ const excerpt = document.createElement("div");+ excerpt.innerHTML = content;+ const $outside = $("<span>");+ await linkService.loadReferenceLinkTitle($outside, href("h"), undefined, undefined, excerpt);+ expect($outside.html()).toBe("Saved");+ expect($outside.hasClass("block-reference-broken")).toBe(false);+ expect(linkService.getReferenceLinkTitleSync(href("h"), "Stored", excerpt)).toBe("Saved");});it("adds no label to a reference to the blocks of a note that cannot be read", async () => {diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.tsindex 2af403f405..ff513ac9d2 100644--- a/apps/client/src/services/link.ts+++ b/apps/client/src/services/link.ts@@ -589,7 +589,7 @@ export function goToLinkExt(evt: MouseEvent | JQuery.ClickEvent | JQuery.MouseDo}// A link to blocks of the note it is in acts as a link within a page.- if (isPlainLeftClick && $link && viewScope?.block+ if (isPlainLeftClick && !openInPopup && !targetIsBlank && $link && viewScope?.block&& showBlocksInPlace($link, noteId, viewScope.block)) {return true;}@@ -757,9 +757,12 @@ async function loadReferenceLinkTitle(const note = subjectId ? await froca.getNote(subjectId, true) : null;if (viewScope?.block && note && (content || noteId === hostNoteId)) {- const label = content- ? getBlockReferenceLabel(content, viewScope.block)- : await loadBlockReferenceLabel(note, viewScope.block);+ const liveLabel = content ? getBlockReferenceLabel(content, viewScope.block) : null;+ // The editor of an excerpt holds only some blocks of the note, so the others are read+ // from the saved note.+ const label = liveLabel && !liveLabel.isBroken+ ? liveLabel+ : await loadBlockReferenceLabel(note, viewScope.block) ?? liveLabel;if (label) {$el.text(label.text).toggleClass("block-reference-broken", label.isBroken);if (!label.isHeading) {@@ -858,11 +861,16 @@ function getReferenceLinkTitleSync(return storedTitle || MISSING_NOTE_TITLE;}+ const note = froca.getNoteFromCache(viewScope?.card || noteId);if (content && viewScope?.block) {- return getBlockReferenceLabel(content, viewScope.block).text;+ const label = getBlockReferenceLabel(content, viewScope.block);+ // As in `loadReferenceLinkTitle()`, blocks outside an excerpt are read from the saved note.+ const savedLabel = label.isBroken && note+ ? getCachedBlockReferenceLabel(note, viewScope.block)+ : null;+ return (savedLabel ?? label).text;}- const note = froca.getNoteFromCache(viewScope?.card || noteId);if (!note) {return storedTitle || MISSING_NOTE_TITLE;}diff --git a/apps/client/src/widgets/react/Card.spec.tsx b/apps/client/src/widgets/react/Card.spec.tsxindex 3749c9689c..a72d8b954f 100644--- a/apps/client/src/widgets/react/Card.spec.tsx+++ b/apps/client/src/widgets/react/Card.spec.tsx@@ -239,6 +239,20 @@ describe("ChoiceCardSection", () => {expect(collapsed.querySelector(".tn-card-choice-expander.bx-chevron-right")).not.toBeNull();collapsed.querySelector<HTMLElement>(".tn-card-choice-expander")?.click();expect(onExpandedChange).toHaveBeenLastCalledWith(true);++ // The arrow that the expander points to expands the choice, and the other collapses it.+ onExpandedChange.mockClear();+ const press = (section: Element | null | undefined, key: string) => !section?.dispatchEvent(+ new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true }));+ const collapsedParent = collapsed.querySelector(".tn-card-choice");+ expect([ collapsedParent, parent, leaf ].map((section) =>+ section?.getAttribute("aria-expanded"))).toStrictEqual([ "false", "true", null ]);+ expect([+ press(collapsedParent, "ArrowLeft"), press(collapsedParent, "ArrowRight"),+ press(parent, "ArrowRight"), press(parent, "ArrowLeft"), press(leaf, "ArrowLeft")+ ]).toStrictEqual([ false, true, false, true, false ]);+ expect(onExpandedChange.mock.calls).toStrictEqual([ [ true ], [ false ] ]);+ expect(onCheck).toHaveBeenCalledOnce();});});diff --git a/apps/client/src/widgets/react/Card.tsx b/apps/client/src/widgets/react/Card.tsxindex 5b88ea4d02..f67b25eb3b 100644--- a/apps/client/src/widgets/react/Card.tsx+++ b/apps/client/src/widgets/react/Card.tsx@@ -319,12 +319,22 @@ export function ChoiceCardSection({style={style}role="radio"aria-checked={isChecked}+ aria-expanded={onExpandedChange && isExpandable ? isExpanded : undefined}tabIndex={0}onClick={onCheck}onKeyDown={(event) => {if (event.key === "Enter" || event.key === " ") {event.preventDefault();onCheck();+ return;+ }++ // As in a tree, the arrow that the expander points to expands the choice.+ const isArrow = event.key === "ArrowRight" || event.key === "ArrowLeft";+ const shouldExpand = (event.key === "ArrowRight") !== !!glob.isRtl;+ if (onExpandedChange && isExpandable && isArrow && shouldExpand !== isExpanded) {+ event.preventDefault();+ onExpandedChange(shouldExpand);}}}>diff --git a/apps/server/src/assets/help/help_content.json b/apps/server/src/assets/help/help_content.jsonindex 66e99775c3..512703126b 100644--- a/apps/server/src/assets/help/help_content.json+++ b/apps/server/src/assets/help/help_content.json@@ -118,7 +118,7 @@"_help_oSuaNgyyKnhu": "<aside class=\"admonition note\"><p>This feature used to be called <em>Bookmarks</em> (as it is the official name in the editor we are using), but in order not to collide with the concept of <a class=\"reference-link\" href=\"#root/_help_u3YFHC9tQlpm\">Bookmarks</a>, we have renamed it to <em>Anchors.</em></p></aside><p>Anchors allows creating <a href=\"#root/_help_QEAPj01N5f7w\">links</a> to a certain part of a note, such as referencing a particular heading or section within a note.</p><p>This feature was introduced in TriliumNext v0.94.0 and augmented in v0.103.0 to support linking across notes.</p><h2>Interaction</h2><ul><li>To create an anchor:<ul><li>Place the cursor at the desired position where to place the anchor.</li><li>Look for the <span class=\"tn-icon bx bx-plus\"></span> button in the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, and then press the <span class=\"tn-icon cke cke-bookmark\"></span> button.</li><li>Alternatively, use <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a> and look for <em>anchor</em>.</li></ul></li><li>To place a link to an anchor in the same note:<ul><li>Place the cursor at the desired position of the link, or select the text to turn into a link.</li><li>Press <kbd>Ctrl</kbd>+<kbd>K</kbd> or the <span class=\"tn-icon cke cke-link\"></span> button in the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, then select <em>Headings & anchors</em> at the top of the <a href=\"#root/_help_QEAPj01N5f7w\"><em>Add link</em> dialog</a>.</li><li>Under <em>Anchors</em>, click the desired anchor to check it. Optionally, type a <em>Link title</em>; without one, the link shows the anchor's name.</li><li>Press <kbd>Enter</kbd> or <em>Add link</em> to confirm.</li></ul></li><li>Clicking a link to an anchor of the same note scrolls to the anchor and briefly highlights the block that holds it, while editing as well as in read-only notes and on shared pages.</li><li>To change a link to an anchor, place the cursor inside it and press <kbd>Ctrl</kbd>+<kbd>K</kbd>. Since v0.107.0, the <em>Edit link</em> dialog opens on <em>Headings & anchors</em>, with the linked anchor checked.</li></ul><aside class=\"admonition tip\"><p>To link to a heading of the same note, no anchor is needed: pick the heading under <em>Headings</em> in the same dialog. See <a href=\"#root/_help_klC3ilXa9kUE\">Linking to a heading</a> for details.</p></aside><h2>Linking across notes</h2><p>Trilium v0.103.0 introduces cross-note Anchors, which makes it possible to create <a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a> which point to a specific anchor in that document.</p><h3>Compatibility with documents from previous versions</h3><p>For notes created prior to Trilium v0.103.0, you might notice that the Anchors might not be identified. This limitation is intentional in order not to have to re-process all the notes, looking for anchors.</p><p>To fix this, simply go that note and make any change (e.g. inserting a space), this will trigger the recalculation of the links.</p><h3>Linking to anchors through the <em>Add link</em> dialog</h3><ol><li>Create an anchor in the target note using the same process as described above.</li><li>In another note, press <kbd>Ctrl</kbd>+<kbd>L</kbd> to insert an internal link. Select the target note containing Anchors.</li><li>If the target note contains Anchors, a section will appear underneath the note selector with the list of Anchors.</li><li>Add the link normally.</li></ol><p>Clicking on a reference link pointing to an anchor will automatically scroll to the desired section.</p><h3>Linking to anchors through the bookmark toolbar</h3><ol><li>Create an anchor in the target note using the same process as described above.</li><li>Click on the anchor to reveal the anchor's floating toolbar.</li><li>Click on the <span class=\"tn-icon cke cke-trilium-copy\"></span> <em>Copy anchor reference link</em> button.</li><li>Go to the note where to insert the link and press <kbd>Ctrl</kbd>+<kbd>V</kbd>.</li></ol><aside class=\"admonition note\"><p>Use this method only to insert <a class=\"reference-link\" href=\"#root/_help_hrZ1D00cLbal\">Internal (reference) links</a> between two documents. To link to an anchor on the same note, use the <em>Add link</em> dialog (<kbd>Ctrl</kbd>+<kbd>K</kbd>) and select <em>Headings & anchors</em> at its top instead.</p></aside>","_help_oI7GoyilXXAr": "<h2>Automatic replacements</h2><p>As you type in a text note, certain character sequences are replaced with the typographic symbol they represent. Typing <code>(c)</code> gives you <code>©</code>, <code>...</code> gives you <code>…</code>, and <code>\"quote\"</code> gives you <code>“quote”</code>.</p><p>These replacements are not applied inside code blocks or inline code, and pasted text is never affected, only text you type. If you have pasted a code snippet, or written one inside a code block, its characters are left exactly as they are.</p><h3>Undoing a replacement</h3><p>Once an automatic replacement takes place, it can be undone by:</p><ul><li>Pressing <kbd>Backspace</kbd> immediately after a replacement undoes it and restores what you typed.<ul><li>Note that this consumes the undo, so a further <kbd>Ctrl</kbd>+<kbd>Z</kbd> might delete your typed text.</li><li>Pressing <kbd>Space</kbd> or changing the cursor position disables this functionality.</li></ul></li><li>Pressing <kbd>Ctrl</kbd>+<kbd>Z</kbd>, which works even after pressing space.</li></ul><h3>Replacement groups & configuration</h3><p>Each group can be turned off in <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Text notes</em> → <em>Automatic replacements</em>.</p><figure class=\"table\"><table><thead><tr><th>Group</th><th>What it replaces</th></tr></thead><tbody><tr><td>Punctuation</td><td><code>...</code> with an ellipsis (<code>…</code>), and <code>--</code> and <code>---</code> <em>surrounded by spaces</em> with an en dash (<code>–</code>) and an em dash (<code>—</code>)</td></tr><tr><td>Mathematical symbols</td><td>fractions such as <code>1/2</code> with <code>½</code>, and the operators <code><=</code>, <code>>=</code>, <code>!=</code>, <code><-</code> and <code>-></code> with <code>≤</code>, <code>≥</code>, <code>≠</code>, <code>←</code> and <code>→</code></td></tr><tr><td>Copyright and trademark</td><td><code>(c)</code>, <code>(r)</code> and <code>(tm)</code> with <code>©</code>, <code>®</code> and <code>™</code></td></tr><tr><td>Quotation marks</td><td>straight quotes with typographic ones — see below</td></tr></tbody></table></figure><h2>Quotation marks</h2><p>Quotation marks are configured separately from the rest, with one setting for the <strong>double</strong> quote key and one for the <strong>single</strong> quote key, because which pair belongs on which key differs between conventions: British typography traditionally sets a quotation in <code>‘…’</code> where American sets it in <code>“…”</code>.</p><p>Each offers:</p><ul><li><em>Based on the note's content language</em> (the default) — English gives <code>“quote”</code>, German <code>„quote“</code>, French <code>« quote »</code>, Japanese <code>「quote」</code>. See <a class=\"reference-link\" href=\"#root/_help_veGu4faJErEM\">Content language & Right-to-left support</a> for how a note's language is decided.</li><li><em>Disabled,</em> straight quotes stay straight.</li><li>A specific pair_:_ <code>“…”</code>, <code>‘…’</code>, <code>„…“</code>, <code>„…”</code>, <code>«…»</code>, <code>« … »</code>, <code>‹…›</code>, <code>「…」</code>, <code>『…』</code>. Choosing one applies it to every note, regardless of its content language.</li></ul><h2>Custom replacements</h2><p>You can add your own under <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Text notes</em> → <em>Automatic replacements</em> → <em>Custom replacements</em>. Type the text to replace and the replacement, then press Enter. Existing ones are shown as chips and removed with the × on each.</p><p>A custom replacement is applied when the text is typed as a whole word and followed by a space, so longer words that begin with it are left alone — a <code>TN</code> replacement does not rewrite the end of <code>BTN</code>, and <code>TNT</code> can still be typed.</p><p>Capitalization follows what you type, unless the replacement has capitals of its own:</p><figure class=\"table\"><table><thead><tr><th><strong>Replacement you defined</strong></th><th><strong>You type</strong></th><th><strong>You get</strong></th></tr></thead><tbody><tr><td><code>teh</code> → <code>the</code></td><td><code>teh</code> / <code>Teh</code> / <code>TEH</code></td><td><code>the</code> / <code>The</code> / <code>THE</code></td></tr><tr><td><code>TN</code> → <code>Trilium Notes</code></td><td><code>TN</code> or <code>tn</code></td><td><code>Trilium Notes</code> (unchanged, it has capitals)</td></tr></tbody></table></figure><p>Of note:</p><ul><li>The text to replace is matched literally; it is not a pattern.</li><li>Typing a \"text to replace\" that already exists in the list of replacements will update the existing one instead. It's not possible to have multiple replacements for the same text.</li><li>The same “text to replace” with different capitalization (e.g. <code>TN</code> and <code>tn</code> co-existing) doesn't work because it would interfere with the capitalization rules above.</li></ul><h2>Characters that only look replaced (ligatures)</h2><p>If you see <code>!=</code> displayed as <code>≠</code> or <code>-></code> as <code>→</code> inside a code block, that is not a replacement since replacements never run there (unless a code block is applied to an existing text). It is a <em>font ligature</em>: the default monospace font draws certain character pairs as a single symbol. The underlying text is unchanged, and copying it out gives you back <code>!=</code> and <code>-></code>.</p><p>This can be turned off with <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a><em>→ Appearance → Fonts → Programming ligatures.</em></p>","_help_NwBbFdNZ9h7O": "<h2>Block quotes</h2><p>As the name suggests, block quotes can be useful to cite one or more paragraphs.</p><p>To create a block quote, press <span class=\"tn-icon cke cke-quote\"></span> from the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>. It's also possible to type <kbd>></kbd>, followed by a space to create one (but only if the cursor is at the beginning of a line).</p><p>Inside the quote block, other block items can be inserted such as tables, images, or even other block quotes or admonitions.</p><h2>Admonitions</h2><p>Admonitions are a way to highlight information to the reader. Other names for it include <em>call-outs</em> and <em>info/warning/alert boxes</em>.</p><figure class=\"image image-style-align-center\"><img style=\"aspect-ratio:959/547;\" src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/1_Block%20quotes%20%26%20admonitions_image.png\" width=\"959\" height=\"547\"></figure><p>From a functional point of view, admonitions act very similarly to a block quote, just with different styling. This includes the ability to insert other elements in it such as headings, tables, images, etc.</p><h3>Inserting a new admonition</h3><p>In the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>:</p><p><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Block%20quotes%20%26%20admonitions_image.png\"></p><p>It's possible to insert an admonition simply by typing:</p><ul><li><code>!!! note</code></li><li><code>!!! tip</code></li><li><code>!!! important</code></li><li><code>!!! caution</code></li><li><code>!!! warning</code></li></ul><p>In addition to that, it's also possible to type <code>!!!</code> followed by any text, case in which a default admonition type will appear (note) with the entered text inside it.</p><h3>Interaction</h3><p>By design, admonitions act very similar to block quotes.</p><ul><li>Selecting a text and pressing the admonition button will turn that text into an admonition.</li><li>If selecting multiple admonitions, pressing the admonition button will automatically merge them into one.</li></ul><p>Inside an admonition:</p><ul><li>Pressing <kbd>Backspace</kbd> while the admonition is empty will remove it.</li><li>Pressing <kbd>Enter</kbd> will start a new paragraph. Pressing it twice will exit out of the admonition.</li><li>Headings and other block content including tables can be inserted inside the admonition.</li></ul><h3>Types of admonitions</h3><p>There are currently five types of admonitions: <em>Note</em>, <em>Tip</em>, <em>Important</em>, <em>Caution</em>, <em>Warning</em>.</p><p>These types were inspired by GitHub's support for this feature and there are currently no plans for adjusting it or allowing the user to customize them.</p><h3>Markdown support</h3><p>See <a class=\"reference-link\" href=\"#root/_help_rJ9grSgoExl9\">Supported syntax</a>.</p>",- "_help_klC3ilXa9kUE": "<p>Block references are <a href=\"#root/_help_QEAPj01N5f7w\">links</a> to a block of a text note, such as a paragraph, a heading, a list item or a table, or to a range of consecutive blocks. A block reference can be pasted in another note as a link, or turned into an <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a> that shows only the referenced blocks.</p><h2>Copying a reference</h2><ol><li>Place the cursor in the block to reference. To reference several consecutive blocks, select them.</li><li>Right-click the block handle, the sequence of dots to the left of the block (see <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>). Alternatively, right-click the text and open the <em>Copy</em> submenu.</li><li>Select <em>Copy reference to this block</em>, or <em>Copy reference to these blocks</em> for a selection. The referenced blocks flash briefly.</li><li>Go to the note where to insert the link and press <kbd>Ctrl</kbd>+<kbd>V</kbd>.</li></ol><p>Inside a <a class=\"reference-link\" href=\"#root/_help_EK2ckIZ74tbT\">Content tabs</a> block, the reference points to the whole block. To link to a single tab, use <em>Copy link to tab</em> instead. Inside a <a class=\"reference-link\" href=\"#root/_help_wYDzQ1fBFgfT\">Multicolumn layout</a>, the reference points to the blocks in the column, and an include shows them without the layout around them.</p><p>The link shows the title of the note, followed by the beginning of the referenced text. A link to blocks of the same note shows only the beginning of the referenced text, and a link to a heading of the same note shows the whole heading.</p><p>If the note is <a href=\"#root/_help_R9pX4DGra2Vt\">shared</a>, the menu of the block handle also offers <em>Copy public link to this block</em>. It copies the web address of the shared page with the reference added, to send to people who read the note outside Trilium. Opening the address scrolls the shared page to the referenced blocks and flashes them. On a shared page, a link to blocks of another shared note does the same.</p><p>The <em>Paste</em> submenu of the context menu offers two more ways to insert a copied reference:</p><ul><li><em>Paste reference as a link</em> inserts only the link, even when the reference was copied as plain text or along with other content.</li><li><em>Paste reference as an excerpt</em> inserts an include of the referenced blocks, as described below.</li></ul><p>In a browser, the context menu of the text editor opens only when right-clicking selected text. Elsewhere the browser shows its own menu.</p><h2>Linking to a heading</h2><p>Since v0.107.0, a link to a heading of the same note can be created from the <em>Add link</em> dialog:</p><ul><li>Place the cursor at the desired position of the link, or select the text to turn into a link.</li><li>Press <kbd>Ctrl</kbd>+<kbd>K</kbd> or the <span class=\"tn-icon cke cke-link\"></span> button in the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, then select <em>Headings & anchors</em> at the top of the dialog.</li><li>Under <em>Headings</em>, click the desired heading to check it. Sub-headings are listed under their heading, which can be collapsed. Optionally, type a <em>Link title</em>.</li><li>Press <kbd>Enter</kbd> or <em>Add link</em> to confirm.</li></ul><p>When the link title is not set, the link displays the text of the heading. If the heading gets changed, the link is renamed automatically to the new text, shortly after you stop typing. A link with a title of its own keeps that title.</p><p>The link is a block reference to the heading, so it keeps working when the heading is moved. To change the 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>K</kbd> works too. The dialog opens on <em>Headings & anchors</em>, with the heading checked. Emptying the <em>Link title</em> there makes the link display the text of the heading again.</p><h2>Following a reference</h2><p>Clicking a block reference opens the note, scrolls to the referenced blocks and flashes them. If a referenced block was deleted, an error message is shown instead, along with the blocks of the range that still exist.</p><p>A link to blocks of the note it is in, such as a link to a heading, scrolls to them and flashes them without leaving the note, as a link within a web page does. This works in read-only notes and on shared pages too. While editing, clicking the link shows its popup: press <em>Jump to heading</em> there, or <em>Open note</em> for other blocks.</p><h2>Including the referenced blocks</h2><p>To show the referenced blocks inside another note, right-click the link in a note being edited and select <em>Convert link to note excerpt</em>, or paste the copied reference with <em>Paste</em> → <em>Paste reference as an excerpt</em>. The include shows only the referenced blocks, not the rest of the note, and marks them with an <em>Excerpt</em> badge in its title. It starts at the <em>Full</em> box size, so all the referenced blocks are visible. To see the whole note, press the <span class=\"tn-icon bx bx-link-external\"></span> button in the same title, which opens the note in a new tab. Converting the include back to a link keeps the reference.</p><p>To edit the referenced blocks without leaving the note, press the <span class=\"tn-icon bx bx-pencil\"></span> <em>Edit excerpt</em> button in the title of the include, or turn on <em>Editable</em> (<span class=\"tn-icon bx bx-edit-alt\"></span>) in its toolbar, as for any <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>. Press the button again to stop editing. The changes are saved to the referenced blocks, and the rest of the note stays as it is. The button is grayed out where the blocks cannot be edited, such as in a read-only note. An excerpt has no <em>Fullscreen</em> button.</p><p>If a referenced block was deleted, the include shows <em>Broken reference</em>.</p><h2>Limitations</h2><ul><li>References can be copied only from a note being edited, and not in the mobile layout.</li><li>An include of a range that covers only part of a list or a quote, such as from its second item to a paragraph after it, cannot be edited in place.</li><li>Deleting a block breaks the references to it.</li><li>Block references are not kept when exporting to Markdown. On a <a href=\"#root/_help_R9pX4DGra2Vt\">shared page</a>, a block reference opens the whole note.</li></ul>",+ "_help_klC3ilXa9kUE": "<p>Block references are <a href=\"#root/_help_QEAPj01N5f7w\">links</a> to a block of a text note, such as a paragraph, a heading, a list item or a table, or to a range of consecutive blocks. A block reference can be pasted in another note as a link, or turned into an <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a> that shows only the referenced blocks.</p><h2>Copying a reference</h2><ol><li>Place the cursor in the block to reference. To reference several consecutive blocks, select them.</li><li>Right-click the block handle, the sequence of dots to the left of the block (see <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>). Alternatively, right-click the text and open the <em>Copy</em> submenu.</li><li>Select <em>Copy reference to this block</em>, or <em>Copy reference to these blocks</em> for a selection. The referenced blocks flash briefly.</li><li>Go to the note where to insert the link and press <kbd>Ctrl</kbd>+<kbd>V</kbd>.</li></ol><p>Inside a <a class=\"reference-link\" href=\"#root/_help_EK2ckIZ74tbT\">Content tabs</a> block, the reference points to the whole block. To link to a single tab, use <em>Copy link to tab</em> instead. Inside a <a class=\"reference-link\" href=\"#root/_help_wYDzQ1fBFgfT\">Multicolumn layout</a>, the reference points to the blocks in the column, and an include shows them without the layout around them.</p><p>The link shows the title of the note, followed by the beginning of the referenced text. A link to blocks of the same note shows only the beginning of the referenced text, and a link to a heading of the same note shows the whole heading.</p><p>If the note is <a href=\"#root/_help_R9pX4DGra2Vt\">shared</a>, the menu of the block handle also offers <em>Copy public link to this block</em>. It copies the web address of the shared page with the reference added, to send to people who read the note outside Trilium. Opening the address scrolls the shared page to the referenced blocks and flashes them. On a shared page, a link to blocks of another shared note does the same.</p><p>The <em>Paste</em> submenu of the context menu offers two more ways to insert a copied reference:</p><ul><li><em>Paste reference as a link</em> inserts only the link, even when the reference was copied as plain text or along with other content.</li><li><em>Paste reference as an excerpt</em> inserts an include of the referenced blocks, as described below.</li></ul><p>In a browser, the context menu of the text editor opens only when right-clicking selected text. Elsewhere the browser shows its own menu.</p><h2>Linking to a heading</h2><p>Since v0.107.0, a link to a heading of the same note can be created from the <em>Add link</em> dialog:</p><ul><li>Place the cursor at the desired position of the link, or select the text to turn into a link.</li><li>Press <kbd>Ctrl</kbd>+<kbd>K</kbd> or the <span class=\"tn-icon cke cke-link\"></span> button in the <a class=\"reference-link\" href=\"#root/_help_nRhnJkTT8cPs\">Formatting toolbar</a>, then select <em>Headings & anchors</em> at the top of the dialog.</li><li>Under <em>Headings</em>, click the desired heading to check it. Sub-headings are listed under their heading, which can be collapsed with the arrow in front of it, or with <kbd>←</kbd> and <kbd>→</kbd> while it is focused. Optionally, type a <em>Link title</em>.</li><li>Press <kbd>Enter</kbd> or <em>Add link</em> to confirm.</li></ul><p>When the link title is not set, the link displays the text of the heading. If the heading gets changed, the link is renamed automatically to the new text, shortly after you stop typing. A link with a title of its own keeps that title.</p><p>The link is a block reference to the heading, so it keeps working when the heading is moved. To change the 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>K</kbd> works too. The dialog opens on <em>Headings & anchors</em>, with the heading checked. Emptying the <em>Link title</em> there makes the link display the text of the heading again.</p><h2>Following a reference</h2><p>Clicking a block reference opens the note, scrolls to the referenced blocks and flashes them. If a referenced block was deleted, an error message is shown instead, along with the blocks of the range that still exist.</p><p>A link to blocks of the note it is in, such as a link to a heading, scrolls to them and flashes them without leaving the note, as a link within a web page does. This works in read-only notes and on shared pages too. While editing, clicking the link shows its popup: press <em>Jump to heading</em> there, or <em>Open note</em> for other blocks.</p><h2>Including the referenced blocks</h2><p>To show the referenced blocks inside another note, right-click the link in a note being edited and select <em>Convert link to note excerpt</em>, or paste the copied reference with <em>Paste</em> → <em>Paste reference as an excerpt</em>. The include shows only the referenced blocks, not the rest of the note, and marks them with an <em>Excerpt</em> badge in its title. It starts at the <em>Full</em> box size, so all the referenced blocks are visible. To see the whole note, press the <span class=\"tn-icon bx bx-link-external\"></span> button in the same title, which opens the note in a new tab. Converting the include back to a link keeps the reference.</p><p>To edit the referenced blocks without leaving the note, press the <span class=\"tn-icon bx bx-pencil\"></span> <em>Edit excerpt</em> button in the title of the include, or turn on <em>Editable</em> (<span class=\"tn-icon bx bx-edit-alt\"></span>) in its toolbar, as for any <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a>. Press the button again to stop editing. The changes are saved to the referenced blocks, and the rest of the note stays as it is. The button is grayed out where the blocks cannot be edited, such as in a read-only note. An excerpt has no <em>Fullscreen</em> button.</p><p>If a referenced block was deleted, the include shows <em>Broken reference</em>.</p><h2>Limitations</h2><ul><li>References can be copied only from a note being edited, and not in the mobile layout.</li><li>An include of a range that covers only part of a list or a quote, such as from its second item to a paragraph after it, cannot be edited in place.</li><li>Deleting a block breaks the references to it.</li><li>Block references are not kept when exporting to Markdown. On a <a href=\"#root/_help_R9pX4DGra2Vt\">shared page</a>, a block reference opens the whole note.</li></ul>","_help_4n4oQUVbnOxa": "<p>Collapsible blocks are sections of content that can be expanded and collapsed, letting you hide detail until it's needed.</p><p>A collapsible block consists of:</p><ul><li><strong>An always-visible header</strong>, containing:<ul><li><strong>An arrow</strong> that expands or collapses the block when clicked.</li><li><strong>A summary line</strong> that acts as the block's title. With the cursor in the summary line, press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> to expand or collapse the block.</li><li><strong>A drag handle</strong> for repositioning the block within the note.</li></ul></li><li><strong>The body</strong>, which is hidden while the block is collapsed. It can hold any kind of content, including nested collapsible blocks. To break out of a collapsible block and continue typing outside it, press <kbd>Enter</kbd> twice at the end of the block.</li></ul><p>You can use the arrow keys to move freely with the cursor between the summary line, the block's body, and the text around the block.</p><h2>Inserting a collapsible block</h2><p>In the formatting bar, go to <em>Insert</em> → <em>Collapsible Block</em>.</p><aside class=\"admonition tip\"><p>Place multiple collapsible blocks one after another to create an accordion, where each block can be expanded or collapsed independently.</p></aside>","_help_veGu4faJErEM": "<p><img src=\"{{helpAssets}}/User%20Guide/Note%20Types/Text/Content%20language%20%26%20Right-to-left%20support_image.jpg\"></p><p>The content language determines:</p><ul><li>The spell-checking of the note, when in a browser. The desktop installation has a dedicated spellchecking section.</li><li>Whether the text is displayed from right-to-left, for languages such as Arabic, Hebrew, etc.</li><li>How typed quotes are <a href=\"#root/_help_oI7GoyilXXAr\">automatically replaced</a> (e.g. English uses <code>“text”</code>, whereas some languages use <code>«text»</code>). This applies only if <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Text</em> → <em>Single/Double quotation marks</em> is set to <em>Based on note's content language</em>.</li><li>Which languages are offered by the <a class=\"reference-link\" href=\"#root/_help_VRoP0g1uHHc2\">In-editor AI assistant</a> for translation.</li><li>The language and the text direction the content is marked with on a <a href=\"#root/_help_R9pX4DGra2Vt\">shared page</a>, which screen readers and browsers follow.</li></ul><h2>Setting the language of a single note</h2><p>To set the language of the content of a <a class=\"reference-link\" href=\"#root/_help_iPIMuisry3hd\">Text</a> note, there is a language selector in the <a class=\"reference-link\" href=\"#root/_help_AlJ73vBCjWDw\">Status bar</a> indicated by a <span class=\"tn-icon bx bx-globe\"></span> icon.</p><h2>Adjusting the list of languages</h2><p>By default, no language is configured. To configure them, go to <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Language & Region</em> → <em>Content languages</em>, or select the <em>Configure languages...</em> item when setting the language. The enabled languages are listed by their native names, sorted alphabetically, which is also the order the language selector shows them in. Here you can:</p><ul><li>Add a language by pressing the <span class=\"tn-icon bx bx-plus\"></span> <em>Add a language</em> button (<em>Add another language</em> once one is enabled), which also shows how many languages are left, and then selecting it.</li><li>Press the <span class=\"tn-icon bx bx-x\"></span> button beside a language to remove it from the list.</li></ul><h2>Default content language</h2><p>Notes that do not have a language of their own follow <a class=\"reference-link\" href=\"#root/_help_4TIF1oA4VQRO\">Options</a> → <em>Language & Region</em> → <em>Default content language</em>. It is set to English initially, and can be set to any content language, or to <em>Based on the application's language</em>.</p><p>If a note has a language set, it always takes precedence over the default.</p>","_help_EK2ckIZ74tbT": "<p>Content tabs group several titled panels of content into one block that shows a single panel at a time. They suit content that comes in variants (such as installation steps for each operating system or the same snippet in several programming languages).</p><p>A tabs block consists of:</p><ul><li><strong>A single row of tab titles</strong>, above the panel or, when the tabs are aligned at the bottom, below it. The title of the panel that is showing is highlighted.</li><li><strong>The panel of the active tab.</strong> A panel can hold any kind of content (including nested tabs blocks).</li></ul><h2>Inserting a tabs block</h2><ul><li>In the formatting bar, go to <em>Insert</em> → <em>Tabs</em>.</li><li>Alternatively, type <code>/tabs</code> and press <kbd>Enter</kbd>, as described in <a class=\"reference-link\" href=\"#root/_help_ZlN4nump6EbW\">Slash Commands</a>.</li></ul><p>A new block contains two tabs, named “Tab 1” and “Tab 2”. Any content that was selected prior to inserting the tabs will be moved into the first tab. The title of the first tab is selected, so typing replaces it.</p><h2>Scrolling through the titles</h2><p>When the titles of a block do not fit on their row, a <span class=\"tn-icon bx bx-chevron-left\"></span> button and a <span class=\"tn-icon bx bx-chevron-right\"></span> button appear at its ends:</p><ul><li>To scroll the titles, click one of the buttons. Holding a button down scrolls the titles continuously until it is released.</li><li>On a touch screen, the titles can also be swiped sideways.</li></ul><p>Whenever another tab is shown (for example by clicking its title, by moving the cursor into it or by following a link to it), the row scrolls so that its whole title is visible. This works the same while editing, in read-only notes and on shared pages.</p><h2>Editing tabs</h2><ul><li>To show a tab, click its title or move the cursor into it.</li><li>To move from a title into its panel, press <kbd>Enter</kbd>.</li><li>The label of a tab can be formatted just like normal text, including support for <a class=\"reference-link\" href=\"#root/_help_hD8GawVuazff\">Icons</a>.</li></ul><p>While the cursor is inside a tabs block, a toolbar appears above it with the following buttons:</p><ul><li><span class=\"tn-icon cke cke-plus\"></span> <em>(Add tab)</em> inserts a tab after the current one and selects its title.</li><li><span class=\"tn-icon cke cke-remove\"></span> <em>(Remove tab)</em> removes the current tab. Removing the last tab removes the whole block.</li><li><span class=\"tn-icon cke cke-chevron-right bx-flip-horizontal\"></span> <em>(Move tab left)</em> and <span class=\"tn-icon cke cke-chevron-right\"></span> (<em>Move tab right)</em> change the order of the tabs.</li><li><span class=\"tn-icon cke cke-link\"></span> <em>(Copy link to tab)</em> copies a link to the current tab, as described below.</li><li><span class=\"tn-icon cke cke-trilium-tabs\"></span> <em>(Tab alignment)</em> places the tab titles above the panel (<em>Align tabs at top</em>, the default) or below it (<em>Align tabs at bottom</em>).</li></ul><p>The tab that is showing is not saved with the note: every tabs block opens on its first tab.</p><h3>Adding tabs</h3><p>While the cursor is in a tab, either in its title or in its panel, you can use these key combinations:</p><ul><li><kbd>Ctrl</kbd> + <kbd>Enter</kbd>: Add a tab after the current one.</li><li><kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Enter</kbd>: Add a tab before the current one.</li></ul><p>The new tab is shown and its title is selected, so typing replaces it.</p><p><kbd>Ctrl</kbd> + <kbd>Enter</kbd> keeps its usual function on a link, in a to-do item and in the title of a collapsible block, and <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Enter</kbd> in a to-do item.</p><h3>Reordering tabs</h3><p>While the cursor is in a tab, either in its title or in its panel, you can use these key combinations:</p><ul><li><kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>Right</kbd>: Move the tab to the right.</li><li><kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>Left</kbd>: Move the tab to the left.</li><li><kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>Home</kbd>: Make it the first tab.</li><li><kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>End</kbd>: Make it the last tab.</li></ul><h2>Moving content between tabs</h2><p>To move content to another tab, select it in the panel, and then use these key combinations:</p><ul><li><kbd>Ctrl</kbd> + <kbd>Right</kbd>: Move to the tab on the right.</li><li><kbd>Ctrl</kbd> + <kbd>Left</kbd>: Move to the tab on the left.</li><li><kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>End</kbd>: Move to the last tab.</li><li><kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>Home</kbd>: Move to the first tab.</li></ul><p>The tab that receives the content is shown, with the content still selected, so pressing the key again moves it on to the next tab. Paragraphs, list items, tables and other blocks move whole, even when only part of them is selected. Content moved to a tab on the left goes to the end of that tab, and content moved to a tab on the right goes to its start, so it keeps its place in the reading order.</p><p>Without a selection, or with a selection in a tab title, these keys keep their usual function: moving the cursor by word, or selecting up to the start or end of the tab.</p><p>When a tabs block and a <a class=\"reference-link\" href=\"#root/_help_wYDzQ1fBFgfT\">Multicolumn layout</a> are nested in one another, the key combinations act on the one closest to the cursor.</p><h2>Reading tabs</h2><p>In <a class=\"reference-link\" href=\"#root/_help_CoFPLs3dRlXc\">Read-Only Notes</a> and on <a class=\"reference-link\" href=\"#root/_help_R9pX4DGra2Vt\">Sharing</a>, tabs blocks work as tabs as well:</p><ul><li>To show a tab, click its title, or focus it and press <kbd>Enter</kbd> or <kbd>Space</kbd>.</li><li>To move between the titles of a block, use the arrow keys, <kbd>Home</kbd> and <kbd>End</kbd>.</li></ul><p>A tab without a title shows “Tab title” in place of one.</p><p>In read-only notes, a title too long for its tab fades out where it is cut off. To read the rest of it, swipe it sideways or drag it with the mouse.</p><h2>Linking to a tab</h2><p>A link can point to a single tab, much like a link to a block (see <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>):</p><ol><li>Place the cursor in the tab, either in its title or in its panel.</li><li>Press <em>Copy link to tab</em> (<span class=\"tn-icon cke cke-link\"></span>) in the toolbar of the tabs block. Alternatively, right-click the text and select <em>Copy</em> → <em>Copy link to this tab</em>. The tab flashes briefly.</li><li>Go to the note where to insert the link and press <kbd>Ctrl</kbd>+<kbd>V</kbd>.</li></ol><p>The link shows the title of the note, followed by the title of the tab. Clicking it opens the note, shows the tab and flashes it. As with any block reference, the link can be turned into an <a class=\"reference-link\" href=\"#root/_help_nBAXQFj20hS1\">Include Note</a> that shows only that tab.</p><p>Links to a tab can be copied only from a note being edited. On a <a href=\"#root/_help_R9pX4DGra2Vt\">shared page</a>, such a link opens the whole note.</p><h2>Content in hidden tabs</h2><p>Content inside a tab that is not showing is still reachable (both while editing and while reading). The tab that holds it is shown when:</p><ul><li>searching the note with <kbd>Ctrl</kbd>+<kbd>F</kbd> highlights a match inside it;</li><li>a link points to an anchor or a block inside it (see <a class=\"reference-link\" href=\"#root/_help_oSuaNgyyKnhu\">Anchors</a> and <a class=\"reference-link\" href=\"#root/_help_klC3ilXa9kUE\">Block references</a>);</li><li>an entry of the <a class=\"reference-link\" href=\"#root/_help_BFvAtE74rbP6\">Table of contents</a> or the <a class=\"reference-link\" href=\"#root/_help_AxshuNRegLAv\">Highlights list</a> points inside it;</li><li>on a shared page, the address of the page points to a heading or an anchor inside it.</li></ul><p>Tab titles are not headings, so they do not appear in the table of contents; headings inside a panel do.</p><h2>Printing and exporting</h2><ul><li>When printing or <a href=\"#root/_help_NRnIZmSMc5sj\">exporting to PDF</a>, every tab is printed, one after another, each with its title above its panel, whatever the tab alignment.</li><li>Markdown export and import write tabs blocks in the content tabs syntax of Material for MkDocs, described in <a class=\"reference-link\" href=\"#root/_help_rJ9grSgoExl9\">Supported syntax</a>. <a class=\"reference-link\" href=\"#root/_help_6RM1Q7ppFVoj\">Markdown</a> notes use the same syntax, show the blocks as tabs in their preview and insert them with <code>/tabs</code>. That syntax has no tab alignment, so tabs aligned at the bottom are exported as regular tabs.</li><li>Anywhere the tabs cannot work as tabs (such as an HTML export opened elsewhere), a tabs block reads as a sequence of titled sections.</li></ul>",diff --git a/apps/server/src/assets/translations/en/server.json b/apps/server/src/assets/translations/en/server.jsonindex f673d0d5a9..52e5acf48c 100644--- a/apps/server/src/assets/translations/en/server.json+++ b/apps/server/src/assets/translations/en/server.json@@ -356,6 +356,7 @@"included-note-requires-credentials": "This included note is password-protected and cannot be displayed here.","content-not-available": "This content is not available.","broken-block-reference": "Broken reference",+ "untitled-block": "Block","play-video": "Play video"},"onenote_import": {diff --git a/docs/User Guide/User Guide/Note Types/Text/Block references.md b/docs/User Guide/User Guide/Note Types/Text/Block references.mdindex 88a523b1d2..a7b0f6cdd0 100644--- a/docs/User Guide/User Guide/Note Types/Text/Block references.md+++ b/docs/User Guide/User Guide/Note Types/Text/Block references.md@@ -27,7 +27,7 @@ Since v0.107.0, a link to a heading of the same note can be created from the _Ad* Place the cursor at the desired position of the link, or select the text to turn into a link.* Press <kbd>Ctrl</kbd>+<kbd>K</kbd> or the <span class="tn-icon cke cke-link"></span> button in the <a class="reference-link" href="Formatting%20toolbar.md">Formatting toolbar</a>, then select _Headings & anchors_ at the top of the dialog.-* Under _Headings_, click the desired heading to check it. Sub-headings are listed under their heading, which can be collapsed. Optionally, type a _Link title_.+* Under _Headings_, click the desired heading to check it. Sub-headings are listed under their heading, which can be collapsed with the arrow in front of it, or with <kbd>←</kbd> and <kbd>→</kbd> while it is focused. Optionally, type a _Link title_.* Press <kbd>Enter</kbd> or _Add link_ to confirm.When the link title is not set, the link displays the text of the heading. If the heading gets changed, the link is renamed automatically to the new text, shortly after you stop typing. A link with a title of its own keeps that title.diff --git a/packages/ckeditor5/src/plugins/copy_anchor_link.spec.ts b/packages/ckeditor5/src/plugins/copy_anchor_link.spec.tsindex 5c1a417fce..c3fa1bc6c8 100644--- a/packages/ckeditor5/src/plugins/copy_anchor_link.spec.ts+++ b/packages/ckeditor5/src/plugins/copy_anchor_link.spec.ts@@ -37,7 +37,7 @@ describe("CopyAnchorLinkButton", () => {getButton().fire("execute");const href = "#root/noteAbc?bookmark=my%20anchor";- expect(getReferenceLinkTitleSync).toHaveBeenCalledWith(href, undefined);+ expect(getReferenceLinkTitleSync).toHaveBeenCalledWith(href, undefined, undefined);expect(copyHtml).toHaveBeenCalledWith(`<a class="reference-link" href="${href}">Some title</a>`, href);});diff --git a/packages/ckeditor5/src/plugins/internallink.spec.ts b/packages/ckeditor5/src/plugins/internallink.spec.tsindex 82240b4253..023de63374 100644--- a/packages/ckeditor5/src/plugins/internallink.spec.ts+++ b/packages/ckeditor5/src/plugins/internallink.spec.ts@@ -221,6 +221,20 @@ describe("the headings of the document", () => {{ element: root?.getChild(4), level: 3, text: "Deep down", blockId: undefined }]);});++ it("reads a reference link in a heading as its title", async () => {+ const editor = await createTestEditor([ Essentials, Paragraph, Heading, InternalLinkPlugin ], {+ referenceLink: {+ getTitle: async () => "Target",+ getTitleSync: (href, storedTitle) => storedTitle ?? `Title of ${href}`+ }+ });+ setModelData(editor.model, "<heading1>See <reference href=\"#root/a\"></reference>.</heading1>"+ + "<heading2>[]<reference href=\"#root/b\" storedTitle=\"Stored\"></reference></heading2>");++ expect(getHeadings(editor).map((heading) => heading.text))+ .toStrictEqual([ "See Title of #root/a.", "Stored" ]);+ });});describe("the link at the selection", () => {diff --git a/packages/ckeditor5/src/plugins/internallink.ts b/packages/ckeditor5/src/plugins/internallink.tsindex b4b18f3ae2..198abba74a 100644--- a/packages/ckeditor5/src/plugins/internallink.ts+++ b/packages/ckeditor5/src/plugins/internallink.ts@@ -321,10 +321,18 @@ export function getHeadings(editor: Editor): DocumentHeading[] {continue;}- // An inline element, such as a soft break, separates words.+ // A reference link reads as its title, as the editor shows it. Another inline element, such+ // as a soft break, separates words.let text = '';for (const child of model.createRangeIn(item).getItems()) {- text += child.is('$textProxy') ? child.data : ' ';+ if (child.is('$textProxy')) {+ text += child.data;+ } else if (child.is('element', 'reference')) {+ text += getReferenceTitleSync(editor, child.getAttribute('href') as string,+ child.getAttribute('storedTitle') as string | undefined);+ } else {+ text += ' ';+ }}text = text.replace(/\s+/g, ' ').trim();diff --git a/packages/ckeditor5/src/plugins/note_link_toolbar.spec.ts b/packages/ckeditor5/src/plugins/note_link_toolbar.spec.tsindex 854517fa32..6d2e0102b6 100644--- a/packages/ckeditor5/src/plugins/note_link_toolbar.spec.ts+++ b/packages/ckeditor5/src/plugins/note_link_toolbar.spec.ts@@ -175,20 +175,37 @@ describe("links within the note", () => {linkTo("#root/def?block=h");expect(navigate("#root/def?block=h")).toEqual([ 0, [] ]);+ const click = (element: HTMLElement | null | undefined, init: MouseEventInit = {}) => {+ let isCanceled = false;+ const record = (event: Event) => {+ isCanceled = event.defaultPrevented;+ // A click left to the host would open the address in the test page.+ event.preventDefault();+ };+ element?.addEventListener("click", record);+ element?.dispatchEvent(new MouseEvent("click", { cancelable: true, ...init }));+ element?.removeEventListener("click", record);+ return [ isCanceled, takeFlashed(editor) ];+ };+ const modifiers = [ { ctrlKey: true }, { metaKey: true }, { shiftKey: true } ];+ // A click with Ctrl, Cmd or Shift is left to the host, which opens a tab or a window.+ preview.render();+ linkTo("#root/x/abc?block=h");+ expect(click(preview.element)).toEqual([ true, [ "Intro" ] ]);+ expect(modifiers.map((init) => click(preview.element, init)))+ .toEqual([ [ false, [] ], [ false, [] ], [ false, [] ] ]);+const referencePreview =editor.ui.componentFactory.create("referenceLinkPreview") as ButtonView;referencePreview.render();- const click = () => {- const event = new MouseEvent("click", { cancelable: true });- referencePreview.element?.dispatchEvent(event);- return [ event.defaultPrevented, takeFlashed(editor) ];- };// Without a reference, the button has no address to follow.- expect(click()).toEqual([ false, [] ]);+ expect(click(referencePreview.element)).toEqual([ false, [] ]);setModelData(editor.model, content.replace("[]", "")+ "<paragraph>[<reference href=\"#root/abc?block=h\"></reference>]</paragraph>");expect(referencePreview.label).toBe("Jump to heading");- expect(click()).toEqual([ true, [ "Intro" ] ]);+ expect(click(referencePreview.element)).toEqual([ true, [ "Intro" ] ]);+ expect(modifiers.map((init) => click(referencePreview.element, init)))+ .toEqual([ [ false, [] ], [ false, [] ], [ false, [] ] ]);const cancel = vi.fn();referencePreview.fire("navigate", "#root/def", cancel);expect(cancel).not.toHaveBeenCalled();diff --git a/packages/ckeditor5/src/plugins/note_link_toolbar.ts b/packages/ckeditor5/src/plugins/note_link_toolbar.tsindex 7623f9d52f..b445f93fdf 100644--- a/packages/ckeditor5/src/plugins/note_link_toolbar.ts+++ b/packages/ckeditor5/src/plugins/note_link_toolbar.ts@@ -179,9 +179,16 @@ function getLinkedAnchor(editor: Editor, href: string) {/*** Scrolls to the block or the anchor of the note that `href` links to and flashes it, as a link- * within a page does. Returns whether `href` links into the note.+ * within a page does. Returns whether it does. A click with Ctrl, Cmd or Shift is left to the+ * host, which opens the link in a new tab or window.*/function jumpInNote(editor: Editor, href: string) {+ // The `navigate` event of `LinkUI` does not pass the click, so it is read from `window`.+ const click = window.event;+ if (click instanceof MouseEvent && (click.ctrlKey || click.metaKey || click.shiftKey)) {+ return false;+ }+const root = editor.editing.view.getDomRoot() as HTMLElement;const block = getLinkedBlock(editor, href);if (block) {diff --git a/packages/share-theme/src/content/in_page_links.ts b/packages/share-theme/src/content/in_page_links.tsindex 7969bb4f8b..a7952b5b13 100644--- a/packages/share-theme/src/content/in_page_links.ts+++ b/packages/share-theme/src/content/in_page_links.ts@@ -1,11 +1,5 @@import { resolveBlockReference } from "@triliumnext/commons/src/lib/block_reference.js";-/** Loads the module, shared with the app, that scrolls to blocks and anchors and flashes them. */-const loadBlockJump = () =>- import("@triliumnext/ckeditor5/src/plugins/block_reference/block_reference_read_only.js");--type BlockJump = Awaited<ReturnType<typeof loadBlockJump>>;-/*** Makes a link to blocks of the page, or to an element of it by `id` such as an anchor, scroll to* its target and flash it, as the app does. The address changes as for a link within the page.@@ -29,6 +23,13 @@ export default function setupInPageLinks() {});}+/** Loads the module, shared with the app, that scrolls to blocks and anchors and flashes them. */+function loadBlockJump() {+ return import("@triliumnext/ckeditor5/src/plugins/block_reference/block_reference_read_only.js");+}++type BlockJump = Awaited<ReturnType<typeof loadBlockJump>>;+/** What shows the target of `link` when it is on this page, or `null`. */function getInPageTarget(link: HTMLAnchorElement): ((jump: BlockJump) => unknown) | null {const url = new URL(link.href);diff --git a/packages/trilium-core/src/share/content_renderer.spec.ts b/packages/trilium-core/src/share/content_renderer.spec.tsindex e412040512..62c8dd75bb 100644--- a/packages/trilium-core/src/share/content_renderer.spec.ts+++ b/packages/trilium-core/src/share/content_renderer.spec.ts@@ -874,6 +874,27 @@ describe("content_renderer", () => {expect(content.match(/<span class="tn-icon bx bx-note"><\/span>/g)).toHaveLength(2);});+ it("names a heading without text, inside an included note too", () => {+ buildShareNote({+ id: "includedHead",+ title: "Included",+ content: `<h2 data-trilium-block-id="i">Inner heading</h2>`+ + `<p><a class="reference-link" href="#root/includedHead?block=i">x</a></p>`+ });+ const note = buildShareNote({+ id: "emptyHeading",+ content: `<h2 data-trilium-block-id="e"> </h2>`+ + `<p><a class="reference-link" href="#root/emptyHeading?block=e">x</a></p>`+ + `<section class="include-note" data-note-id="includedHead"></section>`+ });++ const links = parse(String(getContent(note).content)).querySelectorAll("a");+ expect(links.map((link) => link.innerHTML)).toStrictEqual([+ `<span>${t("content_renderer.untitled-block")}</span>`,+ "<span>Inner heading</span>"+ ]);+ });+it("does not treat an external URL's query string as a note ID", () => {const target = buildShareNote({ id: "extIdTarget1", title: "Target" });const href = `https://example.com/${target.noteId}?x=1`;diff --git a/packages/trilium-core/src/share/content_renderer.ts b/packages/trilium-core/src/share/content_renderer.tsindex 07fdb08fbe..0efb690b3b 100644--- a/packages/trilium-core/src/share/content_renderer.ts+++ b/packages/trilium-core/src/share/content_renderer.ts@@ -658,6 +658,8 @@ function renderText(result: Result, note: SNote | BNote, options: ShareRenderOptembedsAsReferenceLinks: options.embedsAsReferenceLinks,expandNestedEmbeds: options.expandNestedEmbeds};+ // The links of an embedded note, which `getContent()` processed with that note as their host.+ const embeddedLinks = new Set<HTMLElement>();for (const embedEl of document.querySelectorAll(".include-note")) {const embed = resolveContentEmbed((name) => embedEl.getAttribute(name), embedContext);if (!embed) continue;@@ -707,7 +709,11 @@ function renderText(result: Result, note: SNote | BNote, options: ShareRenderOpt});if (typeof embeddedResult.content !== "string") continue;- replaceEmbedContent(embedEl, parse(embeddedResult.content, parseOpts).childNodes);+ const embeddedContent = parse(embeddedResult.content, parseOpts);+ for (const linkEl of embeddedContent.querySelectorAll("a")) {+ embeddedLinks.add(linkEl);+ }+ replaceEmbedContent(embedEl, embeddedContent.childNodes);}result.isEmpty = document.textContent?.trim().length === 0 && document.querySelectorAll("img").length === 0;@@ -715,6 +721,10 @@ function renderText(result: Result, note: SNote | BNote, options: ShareRenderOptif (!result.isEmpty) {// Process attachment links.for (const linkEl of document.querySelectorAll("a")) {+ if (embeddedLinks.has(linkEl)) {+ continue;+ }+const href = linkEl.getAttribute("href");// Preserve in-page anchors (footnotes, bookmarks): a link to a note starts with `#root`.@@ -899,7 +909,8 @@ function cleanUpReferenceLinks(/*** The text of the heading in `content` whose block `href` links to, or `null`. The labels of the- * block references in the heading are left out, as in the app.+ * block references in the heading are left out, and a heading without text reads as "Block", as+ * in the app.*/function getLinkedHeadingText(content: HTMLElement, href: string) {const block = new URLSearchParams(href.split("?")[1]).get("block");@@ -916,7 +927,7 @@ function getLinkedHeadingText(content: HTMLElement, href: string) {for (const link of heading.querySelectorAll(`a.reference-link[href*="block="]`)) {link.remove();}- return heading.textContent.replace(/\s+/g, " ").trim();+ return heading.textContent.replace(/\s+/g, " ").trim() || t("content_renderer.untitled-block");}/** Returns the ID of the note a link such as `#root/abc/def?viewMode=source` points to. */