Implement "silent" for markdown
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ccc3ac7c66
commit
67af38f785
|
@ -21,7 +21,7 @@ Plugin.prototype.init = function (md) {
|
||||||
md.renderer.rules[this.id] = this.render.bind(this)
|
md.renderer.rules[this.id] = this.render.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function linkParser(id, state) {
|
export function linkParser(id, state, silent) {
|
||||||
let input = state.src.slice(state.pos);
|
let input = state.src.slice(state.pos);
|
||||||
const match = /^#?\[\[/.exec(input)
|
const match = /^#?\[\[/.exec(input)
|
||||||
if (!match) {
|
if (!match) {
|
||||||
|
@ -44,9 +44,11 @@ export function linkParser(id, state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (open === 0) {
|
if (open === 0) {
|
||||||
let link = state.src.slice(state.pos + prefixLength, p - 2)
|
if (!silent) {
|
||||||
let token = state.push(id, '', 0)
|
let link = state.src.slice(state.pos + prefixLength, p - 2)
|
||||||
token.meta = {match: link, tag: prefixLength === 3}
|
let token = state.push(id, '', 0)
|
||||||
|
token.meta = {match: link, tag: prefixLength === 3}
|
||||||
|
}
|
||||||
state.pos = p
|
state.pos = p
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -55,7 +57,7 @@ export function linkParser(id, state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin.prototype.parse = function (state, silent) {
|
Plugin.prototype.parse = function (state, silent) {
|
||||||
return linkParser(this.id, state)
|
return linkParser(this.id, state, silent)
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin.prototype.render = function (tokens, id, options, env) {
|
Plugin.prototype.render = function (tokens, id, options, env) {
|
||||||
|
@ -67,7 +69,7 @@ Plugin.prototype.render = function (tokens, id, options, env) {
|
||||||
return '<input type="checkbox" class="checkbox" checked>';
|
return '<input type="checkbox" class="checkbox" checked>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return '<a href="'+this.options.relativeBaseURL+ link.replace(' ', '_') + '" class="wiki-link">' + (tag ? '#' : '') + link + '</a>';
|
return '<a href="'+this.options.relativeBaseURL+encodeURIComponent(link.replace(' ', '_')) + '" class="wiki-link">' + (tag ? '#' : '') + link + '</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (options) => {
|
export default (options) => {
|
||||||
|
|
|
@ -63,4 +63,8 @@ describe('MD', function () {
|
||||||
it('parseLinks tag', function () {
|
it('parseLinks tag', function () {
|
||||||
assert.deepStrictEqual(MD.renderInline("test #[[test]]"), 'test <a href="/edit/test" class="wiki-link">#test</a>')
|
assert.deepStrictEqual(MD.renderInline("test #[[test]]"), 'test <a href="/edit/test" class="wiki-link">#test</a>')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('parseLinks double url', function () {
|
||||||
|
assert.deepStrictEqual(MD.renderInline("[[test [[link]] test2]]"), '<a href="/edit/test_%5B%5Blink%5D%5D%20test2" class="wiki-link">test [[link]] test2</a>')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user