|
1 | 1 | import slugify from './slugify' |
2 | 2 |
|
3 | | -export default function extendLink (md, { noopener = true, noreferrer = true }) { |
| 3 | +export default function extendLink(md, { noopener = true, noreferrer = true }) { |
4 | 4 | md.renderer.rules.link_open = (tokens, idx, options, env, self) => { |
5 | | - const token = tokens[ idx ] |
| 5 | + const token = tokens[idx] |
6 | 6 |
|
7 | 7 | const hrefIndex = token.attrIndex('href') |
8 | 8 |
|
9 | | - if (token.attrs[ hrefIndex ][ 1 ][ 0 ] === '#') { |
| 9 | + if (token.attrs[hrefIndex][1][0] === '#') { |
10 | 10 | 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] |
12 | 12 | } |
13 | 13 | } |
14 | 14 |
|
15 | | - if (token.attrs[ hrefIndex ][ 1 ] === '') { |
| 15 | + if (token.attrs[hrefIndex][1] === '') { |
16 | 16 | 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)) |
19 | 19 | } |
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 | + ) { |
23 | 25 | token.attrSet('class', 'q-markdown--link q-markdown--link-local') |
24 | | - } |
25 | | - else { |
| 26 | + } else { |
26 | 27 | token.attrSet('class', 'q-markdown--link q-markdown--link-external') |
27 | 28 | token.attrSet('target', '_blank') |
28 | 29 | if (noopener === true || noreferrer === true) { |
|
0 commit comments