Skip to content

Build your personal knowledge base with Trilium Notes

fix(server): bookmarks not processed due to self-closing tag

Elian Doranbdf4e40577b7
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index e284c16b78..ef322e1fb1 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -860,6 +860,9 @@
"no_inherited_attributes": "No inherited attributes.",
"none": "none"
},
+ "auto_link_attribute_list": {
+ "title": "System Links"
+ },
"note_info_widget": {
"note_id": "Note ID",
"created": "Created",
diff --git a/apps/server/src/services/notes.spec.ts b/apps/server/src/services/notes.spec.ts
index f19b9be4b7..38d99fc7d7 100644
--- a/apps/server/src/services/notes.spec.ts
+++ b/apps/server/src/services/notes.spec.ts
@@ -31,4 +31,12 @@ describe("findBookmarks", () => {
const content = `<a id="same"></a><a id="same"></a>`;
expect(findBookmarks(content)).toEqual(["same"]);
});
+
+ it("matches self-closing bookmark anchors (CKEditor empty elements)", () => {
+ const content = `<p>Text</p><a id="my-bookmark"></a><p>More</p>`;
+ // CKEditor may also output without closing tag
+ const contentNoClose = `<p>Text</p><a id="my-bookmark"><p>More</p>`;
+ expect(findBookmarks(content)).toEqual(["my-bookmark"]);
+ expect(findBookmarks(contentNoClose)).toEqual(["my-bookmark"]);
+ });
});
diff --git a/apps/server/src/services/notes.ts b/apps/server/src/services/notes.ts
index 719afbe225..56499f0288 100644
--- a/apps/server/src/services/notes.ts
+++ b/apps/server/src/services/notes.ts
@@ -459,7 +459,7 @@ function findImageLinks(content: string, foundLinks: FoundLink[]) {
* Bookmarks are stored as labels on the note so they can be looked up without parsing content.
*/
export function findBookmarks(content: string): string[] {
- const re = /<a\s+id="([^"]+)"[^>]*><\/a>/g;
+ const re = /<a\s+id="([^"]+)"[^>]*>(<\/a>)?/g;
const bookmarks: string[] = [];
let match;