Skip to content

Commit afe06f5

Browse files
committed
feat(linked-mentions): Add link connections for linked mentions section.
1 parent 92b8288 commit afe06f5

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

assets/obsidian-styles.txt.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,10 @@
267267
content: "" !important;
268268
visibility: hidden !important;
269269
}
270+
271+
.search-result-file-match {
272+
display: block;
273+
cursor: pointer;
274+
text-decoration: none;
275+
color: var(--text-muted);
276+
}

src/html-generation/html-generator.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,35 @@ export class HTMLGenerator {
495495
// use the headers inner text as the id
496496
headerEl.setAttribute("id", headerEl.textContent?.replaceAll(" ", "_") ?? "");
497497
});
498+
499+
const backlinkNodes = file.document.querySelectorAll('.tree-item.search-result');
500+
if (backlinkNodes?.length > 0) {
501+
backlinkNodes.forEach(node => {
502+
const title = (node.querySelector('.tree-item-inner') as HTMLElement).innerText;
503+
let targetFile = app.metadataCache.getFirstLinkpathDest(title, file.markdownFile.path);
504+
if (targetFile) {
505+
let targetPath = new Path(targetFile.path);
506+
if (htmlCompatibleExt.includes(targetPath.extensionName)) targetPath.setExtension("html");
507+
if (InvioSettingTab.settings.makeNamesWebStyle) targetPath.makeWebStyle();
508+
const finalPath = targetPath.makeUnixStyle().asString;
509+
510+
// Setup matched link route
511+
const matchedTextNodes = node.querySelectorAll('.search-result-file-match');
512+
if (matchedTextNodes) {
513+
matchedTextNodes.forEach(element => {
514+
const matchedANodes: HTMLElement = document.createElement('a');
515+
matchedANodes.classList.add('search-result-file-match');
516+
matchedANodes.setAttribute("target", "_self");
517+
matchedANodes.setAttribute('href', finalPath);
518+
matchedANodes.innerHTML = element.innerHTML;
519+
element.parentElement.replaceChild(matchedANodes, element);
520+
});
521+
}
522+
}
523+
})
524+
}
525+
526+
498527
}
499528

500529
private static getPageOnlyMeta(file: TFile) {

0 commit comments

Comments
 (0)