diff --git a/docs/README.md b/docs/README.md index 1eb166029..946c6b5d2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -26,3 +26,8 @@ Check out the [Showcase](https://github.com/QingWei-Li/docsify/#showcase) to doc ## Donate Please consider donating if you think docsify is helpful to you or that my work is valuable. I am happy if you can help me [buy a cup of coffee](https://github.com/QingWei-Li/donate). :heart: + +[foo](/bar) +[foo2](/haha/ddd) +[foo3](/haha/eee) +[foo4](/ddd) \ No newline at end of file diff --git a/docs/configuration.md b/docs/configuration.md index 5dece4507..111e9ba36 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -347,3 +347,21 @@ window.$docsify = { routerMode: 'history' // default: 'hash' } ``` + +## noCompileLinks + +- type: `Array` + + +Sometimes we do not want docsify to handle our links. See [#203](https://github.com/QingWei-Li/docsify/issues/203) + + +```js +window.$docsify = { + noCompileLinks: [ + '/foo', + '/bar/.*' + ] +} +``` + diff --git a/docs/de-de/configuration.md b/docs/de-de/configuration.md index 1cd539bbc..24fd1afc1 100644 --- a/docs/de-de/configuration.md +++ b/docs/de-de/configuration.md @@ -317,7 +317,7 @@ window.$docsify = { ``` ## format-updated -We can display the file update date through **{docsify-updated}** variable. And format it by `formatUpdated`. +We can display the file update date through **{docsify-updated}** variable. And format it by `formatUpdated`. See https://github.com/lukeed/tinydate#patterns ```js window.$docsify = { @@ -340,3 +340,21 @@ window.$docsify = { externalLinkTarget: '_self' // default: '_blank' } ``` + + +## noCompileLinks + +- type: `Array` + + +Sometimes we do not want docsify to handle our links. See [#203](https://github.com/QingWei-Li/docsify/issues/203) + + +```js +window.$docsify = { + noCompileLinks: [ + '/foo', + '/bar/.*' + ] +} +``` diff --git a/docs/zh-cn/configuration.md b/docs/zh-cn/configuration.md index 903e31855..b8ccce452 100644 --- a/docs/zh-cn/configuration.md +++ b/docs/zh-cn/configuration.md @@ -327,7 +327,7 @@ window.$docsify = { ``` ## format-updated -我们可以显示文档更新日期通过 **{docsify-updated}** 变量. 并且格式化日期通过 `formatUpdated`. +我们可以显示文档更新日期通过 **{docsify-updated}** 变量. 并且格式化日期通过 `formatUpdated`. 参考 https://github.com/lukeed/tinydate#patterns ```js window.$docsify = { @@ -350,3 +350,21 @@ window.$docsify = { externalLinkTarget: '_self' // default: '_blank' } ``` + + +## noCompileLinks + +- type: `Array` + + +Sometimes we do not want docsify to handle our links. See [#203](https://github.com/QingWei-Li/docsify/issues/203) + + +```js +window.$docsify = { + noCompileLinks: [ + '/foo', + '/bar/.*' + ] +} +``` diff --git a/src/core/config.js b/src/core/config.js index 65f727ab9..95f81e0bc 100644 --- a/src/core/config.js +++ b/src/core/config.js @@ -21,7 +21,8 @@ const config = merge({ mergeNavbar: false, formatUpdated: '', externalLinkTarget: '_blank', - routerModel: 'hash' + routerModel: 'hash', + noCompileLinks: [] }, window.$docsify) const script = document.currentScript || diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 0cece37be..313d50782 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -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 @@ -81,12 +96,15 @@ export class Compiler { renderer.link = function (href, title, text) { let blank = '' - if (!/:|(\/{2})/.test(href) && !/(\s?:ignore)(\s\S+)?$/.test(title)) { + 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}"` }