* feat: ignore to compiled link, fixed #203 * feat: add noCompileLinks, fixed #203 * fix: remove test code
This commit is contained in:
parent
7fb5ce6c84
commit
2e00f4c993
9 changed files with 156 additions and 4 deletions
|
|
@ -7,6 +7,8 @@ import { emojify } from './emojify'
|
|||
import { isAbsolutePath, getPath } from '../router/util'
|
||||
import { isFn, merge, cached } from '../util/core'
|
||||
|
||||
const cachedLinks = {}
|
||||
|
||||
export class Compiler {
|
||||
constructor (config, router) {
|
||||
this.config = config
|
||||
|
|
@ -42,6 +44,19 @@ export class Compiler {
|
|||
})
|
||||
}
|
||||
|
||||
matchNotCompileLink(link) {
|
||||
const links = this.config.noCompileLinks
|
||||
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
const n = links[i]
|
||||
const re = cachedLinks[n] || (cachedLinks[n] = new RegExp(`^${n}$`))
|
||||
|
||||
if (re.test(link)) {
|
||||
return link
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_initRenderer () {
|
||||
const renderer = new marked.Renderer()
|
||||
const { linkTarget, router, contentBase } = this
|
||||
|
|
@ -80,11 +95,16 @@ export class Compiler {
|
|||
}
|
||||
renderer.link = function (href, title, text) {
|
||||
let blank = ''
|
||||
if (!/:|(\/{2})/.test(href)) {
|
||||
|
||||
if (!/:|(\/{2})/.test(href)
|
||||
&& !_self.matchNotCompileLink(href)
|
||||
&& !/(\s?:ignore)(\s\S+)?$/.test(title)) {
|
||||
href = router.toURL(href, null, router.getCurrentPath())
|
||||
} else {
|
||||
blank = ` target="${linkTarget}"`
|
||||
title = title && title.replace(/:ignore/g, '').trim()
|
||||
}
|
||||
|
||||
if (title) {
|
||||
title = ` title="${title}"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue