Skip to content

Commit e4c4cfa

Browse files
committed
Fix invalid internal href
1 parent 9415933 commit e4c4cfa

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

view.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,19 @@ export class View extends HTMLElement {
358358
Promise.resolve(this.#emit('external-link', { a, href }, true))
359359
.then(x => x ? globalThis.open(href, '_blank') : null)
360360
.catch(e => console.error(e))
361-
else Promise.resolve(this.#emit('link', { a, href }, true))
362-
.then(x => x ? this.goTo(href) : null)
363-
.catch(e => console.error(e))
361+
else {
362+
let internalHref = href
363+
if (!book.resolveHref(href_)) {
364+
const hashIndex = href_.indexOf('#')
365+
if (hashIndex >= 0) {
366+
const hash = href_.slice(hashIndex)
367+
internalHref = section?.resolveHref?.(hash) ?? href
368+
}
369+
}
370+
Promise.resolve(this.#emit('link', { a, href: internalHref }, true))
371+
.then(x => x ? this.goTo(internalHref) : null)
372+
.catch(e => console.error(e))
373+
}
364374
})
365375
}
366376
async addAnnotation(annotation, remove) {

0 commit comments

Comments
 (0)