From f4cf92869ff3115c99f2873d3a161139aea5d159 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 31 Dec 2024 07:32:58 -0700 Subject: [PATCH] fix(ui): ssr treats all anchor links as external (#395) --- ui/src/util/extendLink.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ui/src/util/extendLink.js b/ui/src/util/extendLink.js index 11a4f38..53353b7 100644 --- a/ui/src/util/extendLink.js +++ b/ui/src/util/extendLink.js @@ -1,28 +1,29 @@ import slugify from './slugify' -export default function extendLink (md, { noopener = true, noreferrer = true }) { +export default function extendLink(md, { noopener = true, noreferrer = true }) { md.renderer.rules.link_open = (tokens, idx, options, env, self) => { - const token = tokens[ idx ] + const token = tokens[idx] const hrefIndex = token.attrIndex('href') - if (token.attrs[ hrefIndex ][ 1 ][ 0 ] === '#') { + if (token.attrs[hrefIndex][1][0] === '#') { if (typeof location !== 'undefined') { - token.attrs[ hrefIndex ][ 1 ] = location.pathname + token.attrs[ hrefIndex ][ 1 ] + token.attrs[hrefIndex][1] = location.pathname + token.attrs[hrefIndex][1] } } - if (token.attrs[ hrefIndex ][ 1 ] === '') { + if (token.attrs[hrefIndex][1] === '') { token.attrSet('class', 'q-markdown--link q-markdown--link-local') - if (tokens[ idx + 1 ] && tokens[ idx + 1 ].type === 'text' && tokens[ idx + 1 ].content) { - token.attrSet('id', slugify(tokens[ idx + 1 ].content)) + if (tokens[idx + 1] && tokens[idx + 1].type === 'text' && tokens[idx + 1].content) { + token.attrSet('id', slugify(tokens[idx + 1].content)) } - } - else if (token.attrs[ hrefIndex ][ 1 ][ 0 ] === '/' - || token.attrs[ hrefIndex ][ 1 ].startsWith('..')) { + } else if ( + token.attrs[hrefIndex][1][0] === '/' || + token.attrs[hrefIndex][1][0] === '#' || + token.attrs[hrefIndex][1].startsWith('..') + ) { token.attrSet('class', 'q-markdown--link q-markdown--link-local') - } - else { + } else { token.attrSet('class', 'q-markdown--link q-markdown--link-external') token.attrSet('target', '_blank') if (noopener === true || noreferrer === true) {