- markdownIt.renderer.rules.link_open = function (tokens, idx, options, env, self) {
- // If you are sure other plugins can't add `target` - drop check below
- const aIndex = tokens[idx].attrIndex('target')
+ markdownIt.renderer.rules.link_open = function (tokens, index, options, env, self) {
+ const token = tokens[index]
+
+ const targetIndex = token.attrIndex('target')
+ if (targetIndex < 0) token.attrPush([ 'target', '_blank' ])
+ else token.attrs[targetIndex][1] = '_blank'