Skip to content

Commit

Permalink
fix: wrong OutboundLink insertion position (close: #496)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed May 24, 2018
1 parent 11b1830 commit af96f28
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/markdown/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module.exports = (md, externalAttrs) => {
let hasOpenRouterLink = false
let hasOpenExternalLink = false

md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
const token = tokens[idx]
Expand All @@ -17,11 +18,8 @@ module.exports = (md, externalAttrs) => {
Object.entries(externalAttrs).forEach(([key, val]) => {
token.attrSet(key, val)
})

if (/_blank/i.test(externalAttrs['target'])) {
// add OutBoundLink to content if it opens in _blank
tokens[idx + 1].type = 'html_block'
tokens[idx + 1].content += '<OutboundLink/>'
hasOpenExternalLink = true
}
} else if (isSourceLink) {
hasOpenRouterLink = true
Expand Down Expand Up @@ -59,6 +57,11 @@ module.exports = (md, externalAttrs) => {
token.tag = 'router-link'
hasOpenRouterLink = false
}
if (hasOpenExternalLink) {
hasOpenExternalLink = false
// add OutBoundLink to the beforeend of this link if it opens in _blank.
return '<OutboundLink/>' + self.renderToken(tokens, idx, options)
}
return self.renderToken(tokens, idx, options)
}
}

0 comments on commit af96f28

Please sign in to comment.