Skip to content

Commit f4cf928

Browse files
committed
fix(ui): ssr treats all anchor links as external (#395)
1 parent 06de7ed commit f4cf928

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

ui/src/util/extendLink.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import slugify from './slugify'
22

3-
export default function extendLink (md, { noopener = true, noreferrer = true }) {
3+
export default function extendLink(md, { noopener = true, noreferrer = true }) {
44
md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
5-
const token = tokens[ idx ]
5+
const token = tokens[idx]
66

77
const hrefIndex = token.attrIndex('href')
88

9-
if (token.attrs[ hrefIndex ][ 1 ][ 0 ] === '#') {
9+
if (token.attrs[hrefIndex][1][0] === '#') {
1010
if (typeof location !== 'undefined') {
11-
token.attrs[ hrefIndex ][ 1 ] = location.pathname + token.attrs[ hrefIndex ][ 1 ]
11+
token.attrs[hrefIndex][1] = location.pathname + token.attrs[hrefIndex][1]
1212
}
1313
}
1414

15-
if (token.attrs[ hrefIndex ][ 1 ] === '') {
15+
if (token.attrs[hrefIndex][1] === '') {
1616
token.attrSet('class', 'q-markdown--link q-markdown--link-local')
17-
if (tokens[ idx + 1 ] && tokens[ idx + 1 ].type === 'text' && tokens[ idx + 1 ].content) {
18-
token.attrSet('id', slugify(tokens[ idx + 1 ].content))
17+
if (tokens[idx + 1] && tokens[idx + 1].type === 'text' && tokens[idx + 1].content) {
18+
token.attrSet('id', slugify(tokens[idx + 1].content))
1919
}
20-
}
21-
else if (token.attrs[ hrefIndex ][ 1 ][ 0 ] === '/'
22-
|| token.attrs[ hrefIndex ][ 1 ].startsWith('..')) {
20+
} else if (
21+
token.attrs[hrefIndex][1][0] === '/' ||
22+
token.attrs[hrefIndex][1][0] === '#' ||
23+
token.attrs[hrefIndex][1].startsWith('..')
24+
) {
2325
token.attrSet('class', 'q-markdown--link q-markdown--link-local')
24-
}
25-
else {
26+
} else {
2627
token.attrSet('class', 'q-markdown--link q-markdown--link-external')
2728
token.attrSet('target', '_blank')
2829
if (noopener === true || noreferrer === true) {

0 commit comments

Comments
 (0)