Apply relativeBaseURL to parse urls

This commit is contained in:
Peter Stuifzand 2021-10-29 22:43:34 +02:00
parent a4bff99cee
commit ccc3ac7c66
3 changed files with 25 additions and 5 deletions

View File

@ -67,7 +67,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="/' + link.replace(' ', '_') + '" class="wiki-link">' + (tag ? '#' : '') + link + '</a>'; return '<a href="'+this.options.relativeBaseURL+ link.replace(' ', '_') + '" class="wiki-link">' + (tag ? '#' : '') + link + '</a>';
} }
export default (options) => { export default (options) => {

View File

@ -51,16 +51,16 @@ describe('MD', function () {
assert.deepStrictEqual(MD.renderInline("test #[[TODO]] test2"), 'test <input type="checkbox" class="checkbox"> test2') assert.deepStrictEqual(MD.renderInline("test #[[TODO]] test2"), 'test <input type="checkbox" class="checkbox"> test2')
}) })
it('parseLinks 4', function () { it('parseLinks 4', function () {
assert.deepStrictEqual(MD.renderInline("test [[test]] [[test2]] [[test3]]"), 'test <a href="/test" class="wiki-link">test</a> <a href="/test2" class="wiki-link">test2</a> <a href="/test3" class="wiki-link">test3</a>') assert.deepStrictEqual(MD.renderInline("test [[test]] [[test2]] [[test3]]"), 'test <a href="/edit/test" class="wiki-link">test</a> <a href="/edit/test2" class="wiki-link">test2</a> <a href="/edit/test3" class="wiki-link">test3</a>')
}) })
it('parseLinks 5', function () { it('parseLinks 5', function () {
assert.deepStrictEqual(MD.renderInline("test [[test]]"), 'test <a href="/test" class="wiki-link">test</a>') assert.deepStrictEqual(MD.renderInline("test [[test]]"), 'test <a href="/edit/test" class="wiki-link">test</a>')
}) })
it('parseLinks 6', function () { it('parseLinks 6', function () {
assert.deepStrictEqual(MD.renderInline("test [[test]] [[test2]]"), 'test <a href="/test" class="wiki-link">test</a> <a href="/test2" class="wiki-link">test2</a>') assert.deepStrictEqual(MD.renderInline("test [[test]] [[test2]]"), 'test <a href="/edit/test" class="wiki-link">test</a> <a href="/edit/test2" class="wiki-link">test2</a>')
}) })
it('parseLinks tag', function () { it('parseLinks tag', function () {
assert.deepStrictEqual(MD.renderInline("test #[[test]]"), 'test <a href="/test" class="wiki-link">#test</a>') assert.deepStrictEqual(MD.renderInline("test #[[test]]"), 'test <a href="/edit/test" class="wiki-link">#test</a>')
}) })
}) })

View File

@ -114,4 +114,24 @@ describe('linkParser', function () {
}] }]
}) })
}) })
it('parse text and two links', function () {
let state = {src: '1234 [[hello [[world]] Link2]]', pos: 5, tokens: []};
state.__proto__.push = function (id, s, x) {
let token = {id, s, x};
this.tokens.push(token)
return token
}
assert.deepStrictEqual(linkParser('test', state), true);
assert.deepStrictEqual(state, {
src: '1234 [[hello [[world]] Link2]]',
pos: 30,
tokens: [{
id: 'test',
s: '',
x: 0,
meta: {match:'hello [[world]] Link2', tag: false}
}]
})
})
}) })