Skip to content

Build your personal knowledge base with Trilium Notes

fix(share): reference links outside share appear as [missing note]

Elian Doran8b3afc1f4925
diff --git a/apps/server/src/share/content_renderer.spec.ts b/apps/server/src/share/content_renderer.spec.ts
index 57c4e3bc29..da0833c585 100644
--- a/apps/server/src/share/content_renderer.spec.ts
+++ b/apps/server/src/share/content_renderer.spec.ts
@@ -148,11 +148,8 @@ describe("content_renderer", () => {
`
});
const result = getContent(note);
- expect(result.content).toStrictEqual(trimIndentation`\
- <p>
- <a class="reference-link">[missing note]</a>
- </p>
- `);
+ const content = (result.content as string).replaceAll(/\s/g, "");
+ expect(content).toStrictEqual("<p>Foo</p>");
});
it("properly escapes note title", () => {
diff --git a/apps/server/src/share/content_renderer.ts b/apps/server/src/share/content_renderer.ts
index 96e228cc04..70d7f2b820 100644
--- a/apps/server/src/share/content_renderer.ts
+++ b/apps/server/src/share/content_renderer.ts
@@ -320,13 +320,13 @@ function renderText(result: Result, note: SNote | BNote) {
continue;
}
- if (linkEl.classList.contains("reference-link")) {
- cleanUpReferenceLinks(linkEl, getNote);
- }
-
if (href?.startsWith("#")) {
handleAttachmentLink(linkEl, href, getNote, getAttachment);
}
+
+ if (linkEl.classList.contains("reference-link")) {
+ cleanUpReferenceLinks(linkEl, getNote);
+ }
}
// Apply syntax highlight.
@@ -402,8 +402,8 @@ function cleanUpReferenceLinks(linkEl: HTMLElement, getNote: GetNoteFunction) {
const noteId = href.split("/").at(-1);
const note = noteId ? getNote(noteId) : undefined;
if (!note) {
- console.warn("Unable to find note ", noteId);
- linkEl.innerHTML = "[missing note]";
+ // If a note is not found, simply replace it with a text.
+ linkEl.replaceWith(new TextNode(linkEl.innerText));
} else if (note.isProtected) {
linkEl.innerHTML = "[protected]";
} else {