Skip to content

Commit eef8ba5

Browse files
laudepRokt33r
authored andcommitted
feat: Handle internal links to headings within notes
1 parent 67c2bd2 commit eef8ba5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/lib/platform.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,27 @@ import { openExternal } from './electronOnly'
33

44
export const appIsElectron = isElectron()
55

6+
const isInternalLink = (link: string) => link[0] === '#'
7+
8+
const openInternalLink = (link: string) => {
9+
const extractedId = link.slice(1)
10+
const targetId = `user-content-${extractedId}`
11+
const targetElement = window.document.getElementById(targetId)
12+
if (targetElement != null) {
13+
targetElement.scrollIntoView()
14+
}
15+
}
16+
617
export const openNew = (url: string) => {
718
if (url.length === 0) {
819
return
920
}
1021

22+
if (isInternalLink(url)) {
23+
openInternalLink(url)
24+
return
25+
}
26+
1127
if (appIsElectron) {
1228
openExternal(url)
1329
} else {

0 commit comments

Comments
 (0)