From af96f28ee6bea8df6c26704442a73ce4003aee29 Mon Sep 17 00:00:00 2001
From: ULIVZ <472590061@qq.com>
Date: Fri, 25 May 2018 01:48:15 +0800
Subject: [PATCH] fix: wrong OutboundLink insertion position (close: #496)
---
lib/markdown/link.js | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/lib/markdown/link.js b/lib/markdown/link.js
index 79c23928be..99ca1aefd9 100644
--- a/lib/markdown/link.js
+++ b/lib/markdown/link.js
@@ -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]
@@ -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 += ''
+ hasOpenExternalLink = true
}
} else if (isSourceLink) {
hasOpenRouterLink = true
@@ -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 '' + self.renderToken(tokens, idx, options)
+ }
return self.renderToken(tokens, idx, options)
}
}