diff --git a/addon/chrome/content/styles/related.css b/addon/chrome/content/styles/related.css index 132b974..996424e 100644 --- a/addon/chrome/content/styles/related.css +++ b/addon/chrome/content/styles/related.css @@ -56,6 +56,10 @@ item-pane-custom-section .bn-link-body { width: 0; flex: 1; overflow: hidden; + + .position-label { + color: var(--fill-secondary); + } } .icon, diff --git a/src/extras/relationWorker.ts b/src/extras/relationWorker.ts index c614f62..834efe7 100644 --- a/src/extras/relationWorker.ts +++ b/src/extras/relationWorker.ts @@ -28,7 +28,7 @@ async function rebuildLinkForNote( links: LinkModel[], ) { console.log("rebuildLinkForNote", fromLibID, fromKey, links); - + const collection = db.link.where({ fromLibID, fromKey }); const oldOutboundLinks = await collection.toArray(); collection.delete().then((deleteCount) => { diff --git a/src/modules/workspace/link.ts b/src/modules/workspace/link.ts index 8e84d65..2ad86be 100644 --- a/src/modules/workspace/link.ts +++ b/src/modules/workspace/link.ts @@ -122,16 +122,20 @@ async function renderSection( .getGlobal("require")("components/icons") .getCSSItemTypeIcon("note"); - const label = doc.createElement("span"); + const label = doc.createElement("div"); label.className = "label"; - let content = targetItem.getNoteTitle(); + const title = doc.createElement("span"); + title.textContent = targetItem.getNoteTitle(); + const position = doc.createElement("span"); + position.className = "position-label"; if (typeof linkData.toLine === "number") { - content += ` > Line ${linkData.toLine}`; + position.textContent = `>Line ${linkData.toLine}`; } if (typeof linkData.toSection === "string") { - content += `#${linkData.toSection}`; + position.textContent = `#${linkData.toSection}`; } - label.append(content); + label.append(title, position); + label.title = linkData.url; const box = doc.createElement("div"); box.addEventListener("click", () => @@ -159,10 +163,6 @@ async function renderSection( setCount(count); } -function handleShowItem(id: number) { - ZoteroPane.selectItem(id); -} - function makeSetCount(setL10nArgs: (str: string) => void) { return (count: number) => { setL10nArgs(`{"count": "${count}"}`); diff --git a/src/utils/relation.ts b/src/utils/relation.ts index 6ee4188..de7880f 100644 --- a/src/utils/relation.ts +++ b/src/utils/relation.ts @@ -73,11 +73,12 @@ async function updateNoteLinkRelation(noteID: number) { const lines = addon.api.note.getLinesInNote(note); const linkToData: LinkModel[] = []; for (let i = 0; i < lines.length; i++) { - const linkMatches = lines[i].match(/zotero:\/\/note\/\w+\/\w+\//g); + const linkMatches = lines[i].match(/href="zotero:\/\/note\/[^"]+"/g); if (!linkMatches) { continue; } - for (const link of linkMatches) { + for (const match of linkMatches) { + const link = decodeHTMLEntities(match.slice(6, -1)); const { noteItem, libraryID, noteKey, lineIndex, sectionName } = getNoteLinkParams(link); if (noteItem && noteItem.isNote() && noteItem.id !== note.id) { @@ -140,6 +141,13 @@ async function getNoteLinkInboundRelation( }); } +function decodeHTMLEntities(text: string) { + return text + .replace(/&/g, "&") + .replace(/</g, "<") + .replace(/>/g, ">"); +} + interface LinkModel { fromLibID: number; fromKey: string;