* 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
|
|
@ -362,3 +362,21 @@ window.$docsify = {
|
||||||
routerMode: 'history' // default: 'hash'
|
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/.*'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -341,3 +341,21 @@ window.$docsify = {
|
||||||
externalLinkTarget: '_self' // default: '_blank'
|
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/.*'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -25,3 +25,27 @@ Generelle Tipps wie:
|
||||||
wird wie folgt gerendert:
|
wird wie folgt gerendert:
|
||||||
|
|
||||||
?> *TODO* unit test
|
?> *TODO* unit test
|
||||||
|
|
||||||
|
## Ignore to compile link
|
||||||
|
|
||||||
|
Some time we will put some other relative path to the link, you have to need to tell docsify you don't need to compile this link. For example
|
||||||
|
|
||||||
|
```md
|
||||||
|
[link](/demo/)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
It will be compiled to `<a href="/#/demo/">link</a>` and will be loaded `/demo/README.md`. Maybe you want to jump to `/demo/index.html`.
|
||||||
|
|
||||||
|
Now you can do that
|
||||||
|
|
||||||
|
```md
|
||||||
|
[link](/demo/ ":ignore")
|
||||||
|
```
|
||||||
|
You will get `<a href="/demo/">link</a>`html. Do not worry, you can still set title for link.
|
||||||
|
|
||||||
|
```md
|
||||||
|
[link](/demo/ ":ignore title")
|
||||||
|
|
||||||
|
<a href="/demo/" title="title">link</a>
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -25,3 +25,28 @@ General tips like:
|
||||||
are rendered as:
|
are rendered as:
|
||||||
|
|
||||||
?> *TODO* unit test
|
?> *TODO* unit test
|
||||||
|
|
||||||
|
## Ignore to compile link
|
||||||
|
|
||||||
|
Some time we will put some other relative path to the link, you have to need to tell docsify you don't need to compile this link. For example
|
||||||
|
|
||||||
|
```md
|
||||||
|
[link](/demo/)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
It will be compiled to `<a href="/#/demo/">link</a>` and will be loaded `/demo/README.md`. Maybe you want to jump to `/demo/index.html`.
|
||||||
|
|
||||||
|
Now you can do that
|
||||||
|
|
||||||
|
```md
|
||||||
|
[link](/demo/ ":ignore")
|
||||||
|
```
|
||||||
|
You will get `<a href="/demo/">link</a>`html. Do not worry, you can still set title for link.
|
||||||
|
|
||||||
|
```md
|
||||||
|
[link](/demo/ ":ignore title")
|
||||||
|
|
||||||
|
<a href="/demo/" title="title">link</a>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -352,3 +352,21 @@ window.$docsify = {
|
||||||
externalLinkTarget: '_self' // default: '_blank'
|
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/.*'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -24,3 +24,28 @@ docsify 扩展了一些 Markdown 语法,可以让文档更易读。
|
||||||
|
|
||||||
?> *TODO* 完善示例
|
?> *TODO* 完善示例
|
||||||
|
|
||||||
|
|
||||||
|
## Ignore to compile link
|
||||||
|
|
||||||
|
Some time we will put some other relative path to the link, you have to need to tell docsify you don't need to compile this link. For example
|
||||||
|
|
||||||
|
```md
|
||||||
|
[link](/demo/)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
It will be compiled to `<a href="/#/demo/">link</a>` and will be loaded `/demo/README.md`. Maybe you want to jump to `/demo/index.html`.
|
||||||
|
|
||||||
|
Now you can do that
|
||||||
|
|
||||||
|
```md
|
||||||
|
[link](/demo/ ":ignore")
|
||||||
|
```
|
||||||
|
You will get `<a href="/demo/">link</a>`html. Do not worry, you can still set title for link.
|
||||||
|
|
||||||
|
```md
|
||||||
|
[link](/demo/ ":ignore title")
|
||||||
|
|
||||||
|
<a href="/demo/" title="title">link</a>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ const config = merge({
|
||||||
mergeNavbar: false,
|
mergeNavbar: false,
|
||||||
formatUpdated: '',
|
formatUpdated: '',
|
||||||
externalLinkTarget: '_blank',
|
externalLinkTarget: '_blank',
|
||||||
routerModel: 'hash'
|
routerModel: 'hash',
|
||||||
|
noCompileLinks: []
|
||||||
}, window.$docsify)
|
}, window.$docsify)
|
||||||
|
|
||||||
const script = document.currentScript ||
|
const script = document.currentScript ||
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import { emojify } from './emojify'
|
||||||
import { isAbsolutePath, getPath } from '../router/util'
|
import { isAbsolutePath, getPath } from '../router/util'
|
||||||
import { isFn, merge, cached } from '../util/core'
|
import { isFn, merge, cached } from '../util/core'
|
||||||
|
|
||||||
|
const cachedLinks = {}
|
||||||
|
|
||||||
export class Compiler {
|
export class Compiler {
|
||||||
constructor (config, router) {
|
constructor (config, router) {
|
||||||
this.config = config
|
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 () {
|
_initRenderer () {
|
||||||
const renderer = new marked.Renderer()
|
const renderer = new marked.Renderer()
|
||||||
const { linkTarget, router, contentBase } = this
|
const { linkTarget, router, contentBase } = this
|
||||||
|
|
@ -80,11 +95,16 @@ export class Compiler {
|
||||||
}
|
}
|
||||||
renderer.link = function (href, title, text) {
|
renderer.link = function (href, title, text) {
|
||||||
let blank = ''
|
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())
|
href = router.toURL(href, null, router.getCurrentPath())
|
||||||
} else {
|
} else {
|
||||||
blank = ` target="${linkTarget}"`
|
blank = ` target="${linkTarget}"`
|
||||||
|
title = title && title.replace(/:ignore/g, '').trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (title) {
|
if (title) {
|
||||||
title = ` title="${title}"`
|
title = ` title="${title}"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,9 @@ export function parseQuery (query) {
|
||||||
query.split('&').forEach(function (param) {
|
query.split('&').forEach(function (param) {
|
||||||
const parts = param.replace(/\+/g, ' ').split('=')
|
const parts = param.replace(/\+/g, ' ').split('=')
|
||||||
|
|
||||||
res[parts[0]] = decode(parts[1])
|
res[parts[0]] = parts[1] && decode(parts[1])
|
||||||
})
|
})
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,7 +26,9 @@ export function stringifyQuery (obj) {
|
||||||
const qs = []
|
const qs = []
|
||||||
|
|
||||||
for (const key in obj) {
|
for (const key in obj) {
|
||||||
qs.push(`${encode(key)}=${encode(obj[key])}`.toLowerCase())
|
qs.push(obj[key]
|
||||||
|
? `${encode(key)}=${encode(obj[key])}`.toLowerCase()
|
||||||
|
: encode(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
return qs.length ? `?${qs.join('&')}` : ''
|
return qs.length ? `?${qs.join('&')}` : ''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue