Skip to content

Commit

Permalink
渲染链接默认在新标签打开
Browse files Browse the repository at this point in the history
  • Loading branch information
purocean committed Aug 22, 2018
1 parent b25dae2 commit f4c9f43
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions frontend/src/components/MyPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const MyPlugin = (md) => {
const LinkTargetBlank = (tokens, idx, options, env, slf) => {
if (tokens[idx].attrIndex('target') < 0) {
tokens[idx].attrPush(['target', '_blank'])
}

return slf.renderToken(tokens, idx, options, env, slf)
}

md.renderer.rules.link_open = LinkTargetBlank
}

export default MyPlugin
9 changes: 8 additions & 1 deletion frontend/src/components/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import MarkdownItAttrs from 'markdown-it-attrs'
import MultimdTable from 'markdown-it-multimd-table'
import RunPlugin from './RunPlugin'
import SourceLinePlugin from './SourceLinePlugin'
import MyPlugin from './MyPlugin'
import Highlight from 'highlight.js'
import MermaidPlugin from './MermaidPlugin'
Expand Down Expand Up @@ -83,7 +84,13 @@ export default {
generateSource: umlCode => {
return 'api/plantuml/png?data=' + encodeURIComponent(umlCode)
}
}).use(RunPlugin).use(katex).use(SourceLinePlugin).use(MarkdownItAttrs).use(MultimdTable, {enableMultilineRows: true})
})
.use(RunPlugin)
.use(katex)
.use(SourceLinePlugin)
.use(MarkdownItAttrs)
.use(MyPlugin)
.use(MultimdTable, {enableMultilineRows: true})
}
},
mounted () {
Expand Down

0 comments on commit f4c9f43

Please sign in to comment.