HarryChen0506 / react-markdown-editor-lite

a light-weight Markdown editor based on React. 一款轻量的基于React的markdown编辑器
https://harrychen0506.github.io/react-markdown-editor-lite/
MIT License
1.03k stars 160 forks source link

[BUG]怎么样能让渲染出来的a标签在新的窗口打开? #265

Closed hexiaochen666 closed 1 year ago

hexiaochen666 commented 2 years ago

怎么样能让渲染出来的a标签在新的窗口打开?

crtan7 commented 1 year ago

import iterator from 'markdown-it-for-inline'

 .use(iterator, 'url_new_win', 'link_open', function (tokens, idx) {
            var aIndex = tokens[idx].attrIndex('target');

            if (aIndex < 0) {
                tokens[idx].attrPush(['target', '_blank']);
            } else {
                tokens[idx].attrs[aIndex][1] = '_blank';
            }
  })
xstnet commented 1 year ago

不如直接写标签 方法1:

<base target="_blank"/>

方法2:

<a target="_blank" href="xxxxx">xxxx</a>
sylingd commented 1 year ago

取决于你所使用的渲染器,与编辑器无关