Skip to content

Commit 2faa653

Browse files
committed
feat: add noCompileLinks, fixed #203
1 parent 22343ba commit 2faa653

File tree

6 files changed

+82
-4
lines changed

6 files changed

+82
-4
lines changed

Diff for: docs/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ Check out the [Showcase](https://github.com/QingWei-Li/docsify/#showcase) to doc
2626
## Donate
2727

2828
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:
29+
30+
[foo](/bar)
31+
[foo2](/haha/ddd)
32+
[foo3](/haha/eee)
33+
[foo4](/ddd)

Diff for: docs/configuration.md

+18
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,21 @@ window.$docsify = {
347347
routerMode: 'history' // default: 'hash'
348348
}
349349
```
350+
351+
## noCompileLinks
352+
353+
- type: `Array`
354+
355+
356+
Sometimes we do not want docsify to handle our links. See [#203](https://github.com/QingWei-Li/docsify/issues/203)
357+
358+
359+
```js
360+
window.$docsify = {
361+
noCompileLinks: [
362+
'/foo',
363+
'/bar/.*'
364+
]
365+
}
366+
```
367+

Diff for: docs/de-de/configuration.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ window.$docsify = {
317317
```
318318

319319
## format-updated
320-
We can display the file update date through **{docsify-updated<span>}</span>** variable. And format it by `formatUpdated`.
320+
We can display the file update date through **{docsify-updated<span>}</span>** variable. And format it by `formatUpdated`.
321321
See https://github.com/lukeed/tinydate#patterns
322322
```js
323323
window.$docsify = {
@@ -340,3 +340,21 @@ window.$docsify = {
340340
externalLinkTarget: '_self' // default: '_blank'
341341
}
342342
```
343+
344+
345+
## noCompileLinks
346+
347+
- type: `Array`
348+
349+
350+
Sometimes we do not want docsify to handle our links. See [#203](https://github.com/QingWei-Li/docsify/issues/203)
351+
352+
353+
```js
354+
window.$docsify = {
355+
noCompileLinks: [
356+
'/foo',
357+
'/bar/.*'
358+
]
359+
}
360+
```

Diff for: docs/zh-cn/configuration.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ window.$docsify = {
327327
```
328328

329329
## format-updated
330-
我们可以显示文档更新日期通过 **{docsify-updated<span>}</span>** 变量. 并且格式化日期通过 `formatUpdated`.
330+
我们可以显示文档更新日期通过 **{docsify-updated<span>}</span>** 变量. 并且格式化日期通过 `formatUpdated`.
331331
参考 https://github.com/lukeed/tinydate#patterns
332332
```js
333333
window.$docsify = {
@@ -350,3 +350,21 @@ window.$docsify = {
350350
externalLinkTarget: '_self' // default: '_blank'
351351
}
352352
```
353+
354+
355+
## noCompileLinks
356+
357+
- type: `Array`
358+
359+
360+
Sometimes we do not want docsify to handle our links. See [#203](https://github.com/QingWei-Li/docsify/issues/203)
361+
362+
363+
```js
364+
window.$docsify = {
365+
noCompileLinks: [
366+
'/foo',
367+
'/bar/.*'
368+
]
369+
}
370+
```

Diff for: src/core/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const config = merge({
2121
mergeNavbar: false,
2222
formatUpdated: '',
2323
externalLinkTarget: '_blank',
24-
routerModel: 'hash'
24+
routerModel: 'hash',
25+
noCompileLinks: []
2526
}, window.$docsify)
2627

2728
const script = document.currentScript ||

Diff for: src/core/render/compiler.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { emojify } from './emojify'
77
import { isAbsolutePath, getPath } from '../router/util'
88
import { isFn, merge, cached } from '../util/core'
99

10+
const cachedLinks = {}
11+
1012
export class Compiler {
1113
constructor (config, router) {
1214
this.config = config
@@ -42,6 +44,19 @@ export class Compiler {
4244
})
4345
}
4446

47+
matchNotCompileLink(link) {
48+
const links = this.config.noCompileLinks
49+
50+
for (var i = 0; i < links.length; i++) {
51+
const n = links[i]
52+
const re = cachedLinks[n] || (cachedLinks[n] = new RegExp(`^${n}$`))
53+
54+
if (re.test(link)) {
55+
return link
56+
}
57+
}
58+
}
59+
4560
_initRenderer () {
4661
const renderer = new marked.Renderer()
4762
const { linkTarget, router, contentBase } = this
@@ -81,12 +96,15 @@ export class Compiler {
8196
renderer.link = function (href, title, text) {
8297
let blank = ''
8398

84-
if (!/:|(\/{2})/.test(href) && !/(\s?:ignore)(\s\S+)?$/.test(title)) {
99+
if (!/:|(\/{2})/.test(href)
100+
&& !_self.matchNotCompileLink(href)
101+
&& !/(\s?:ignore)(\s\S+)?$/.test(title)) {
85102
href = router.toURL(href, null, router.getCurrentPath())
86103
} else {
87104
blank = ` target="${linkTarget}"`
88105
title = title && title.replace(/:ignore/g, '').trim()
89106
}
107+
90108
if (title) {
91109
title = ` title="${title}"`
92110
}

0 commit comments

Comments
 (0)