imzbf / md-editor-v3

Markdown editor for vue3, developed in jsx and typescript, dark theme、beautify content by prettier、render articles directly、paste or clip the picture and upload it...
https://imzbf.github.io/md-editor-v3
MIT License
1.51k stars 144 forks source link

期望渲染超链接时,能提供一个配置项设置target属性 #642

Closed geedys closed 3 weeks ago

geedys commented 3 weeks ago

A great idea

我项目中在electron环境中,预览md文档时,由于a元素没有target属性,默认会在electron窗口中打开。 如果target=“_blank”, 则可以由外部浏览器打开链接。

//electron: 以下调用需要页面中超链接的 target 属性为 _blank
mainWindow.webContents.setWindowOpenHandler((details) => {
     shell.openExternal(details.url)
     return {action: 'deny'}
})

目前的解决方案:

<MdEditor :sanitize="replaceLink"/>
const replaceLink = (html) => {
    return html.replace(/<a/g, '<a target="_blank"')
}
imzbf commented 3 weeks ago

参考这个:https://github.com/imzbf/md-editor-v3/issues/496#issuecomment-2076109854