Skip to content

Build your personal knowledge base with Trilium Notes

client: improve test coverage

Adorian Doran38ddabd41cda
diff --git a/packages/trilium-core/src/share/content_renderer.spec.ts b/packages/trilium-core/src/share/content_renderer.spec.ts
index 62c8dd75bb..7cf8361142 100644
--- a/packages/trilium-core/src/share/content_renderer.spec.ts
+++ b/packages/trilium-core/src/share/content_renderer.spec.ts
@@ -862,7 +862,8 @@ describe("content_renderer", () => {
+ `<a class="reference-link" href="#root/headingLink1?block=h">Intro</a></h2>`
+ `<p><a class="reference-link" href="#root/headingLink1?block=h">a</a>`
+ `<a class="reference-link" href="#root/headingLink1?block=p">b</a>`
- + `<a class="reference-link" href="#root/headingLink1?block=gone">c</a></p>`
+ + `<a class="reference-link" href="#root/headingLink1?block=gone">c</a>`
+ + `<a class="reference-link" href="#root/headingLink1">d</a></p>`
+ `<p data-trilium-block-id="p">Text</p>`
});
@@ -870,8 +871,8 @@ describe("content_renderer", () => {
expect(content).toContain(`<a class="reference-link type-text"`
+ ` href="./headingLink1?block=h"><span>Lists &amp; more</span></a>`);
- // A link to another block, or to one that is gone, shows the note.
- expect(content.match(/<span class="tn-icon bx bx-note"><\/span>/g)).toHaveLength(2);
+ // A link to another block, to one that is gone or to the whole note shows the note.
+ expect(content.match(/<span class="tn-icon bx bx-note"><\/span>/g)).toHaveLength(3);
});
it("names a heading without text, inside an included note too", () => {
diff --git a/packages/trilium-core/src/share/content_renderer.ts b/packages/trilium-core/src/share/content_renderer.ts
index 0efb690b3b..aea5525b97 100644
--- a/packages/trilium-core/src/share/content_renderer.ts
+++ b/packages/trilium-core/src/share/content_renderer.ts
@@ -879,15 +879,8 @@ function cleanUpReferenceLinks(
// `handleAttachmentLink()` removes the `href` of a link whose target is missing.
let noteId = "";
- // The link of an included note was rewritten already, to `./shareId` and its parameters.
if (linkEl.hasAttribute("href")) {
- if (href.startsWith("#")) {
- noteId = getNoteIdFromLink(href);
- } else if (href.startsWith("./")) {
- noteId = getNoteIdFromLink(href.slice(2));
- } else {
- noteId = href.slice(href.lastIndexOf("/") + 1);
- }
+ noteId = href.startsWith("#") ? getNoteIdFromLink(href) : href.slice(href.lastIndexOf("/") + 1);
}
const note = noteId ? getNote(noteId) : undefined;
if (!note) {