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

This commit is contained in:
Elian Doran
2026-04-18 10:14:58 +03:00
parent 79d639108b
commit bdf4e40577
3 changed files with 12 additions and 1 deletions

View File

@@ -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",

View File

@@ -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"]);
});
});

View File

@@ -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;