Skip to content

Commit

Permalink
feat: add noCompileLinks, fixed #203
Browse files Browse the repository at this point in the history
  • Loading branch information
QingWei-Li committed Jul 10, 2017
1 parent 22343ba commit 2faa653
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
18 changes: 18 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/.*'
]
}
```

20 changes: 19 additions & 1 deletion docs/de-de/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ window.$docsify = {
```

## format-updated
We can display the file update date through **{docsify-updated<span>}</span>** variable. And format it by `formatUpdated`.
We can display the file update date through **{docsify-updated<span>}</span>** variable. And format it by `formatUpdated`.
See https://github.com/lukeed/tinydate#patterns
```js
window.$docsify = {
Expand All @@ -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/.*'
]
}
```
20 changes: 19 additions & 1 deletion docs/zh-cn/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ window.$docsify = {
```

## format-updated
我们可以显示文档更新日期通过 **{docsify-updated<span>}</span>** 变量. 并且格式化日期通过 `formatUpdated`.
我们可以显示文档更新日期通过 **{docsify-updated<span>}</span>** 变量. 并且格式化日期通过 `formatUpdated`.
参考 https://github.com/lukeed/tinydate#patterns
```js
window.$docsify = {
Expand All @@ -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/.*'
]
}
```
3 changes: 2 additions & 1 deletion src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const config = merge({
mergeNavbar: false,
formatUpdated: '',
externalLinkTarget: '_blank',
routerModel: 'hash'
routerModel: 'hash',
noCompileLinks: []
}, window.$docsify)

const script = document.currentScript ||
Expand Down
20 changes: 19 additions & 1 deletion src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}"`
}
Expand Down

0 comments on commit 2faa653

Please sign in to comment.