67 lines
2.7 KiB
JavaScript
67 lines
2.7 KiB
JavaScript
/*
|
|
* Wiki - A wiki with editor
|
|
* Copyright (c) 2021 Peter Stuifzand
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import assert from 'assert'
|
|
import MarkdownIt from "markdown-it";
|
|
import MarkdownItWikilinks2 from "../src/wikilinks2";
|
|
|
|
const MD = new MarkdownIt({
|
|
linkify: false,
|
|
highlight: function (str, lang) {
|
|
if (lang === 'mermaid') {
|
|
return '<div class="mermaid">' + str + '</div>';
|
|
}
|
|
return '';
|
|
}
|
|
})
|
|
|
|
MD.use(MarkdownItWikilinks2({
|
|
baseURL: 'http://localhost/',
|
|
uriSuffix: '',
|
|
relativeBaseURL: '/edit/',
|
|
htmlAttributes: {
|
|
class: 'wiki-link'
|
|
},
|
|
}))
|
|
|
|
describe('MD', function () {
|
|
it('parseLinks', function () {
|
|
assert.deepStrictEqual(MD.renderInline("#[[TODO]]"), '<input type="checkbox" class="checkbox">')
|
|
assert.deepStrictEqual(MD.renderInline("#[[TODO]] #[[DONE]]"), '<input type="checkbox" class="checkbox"> <input type="checkbox" class="checkbox" checked>')
|
|
})
|
|
it('parseLinks 2', function () {
|
|
assert.deepStrictEqual(MD.renderInline("#[[TODO]] #[[DONE]]"), '<input type="checkbox" class="checkbox"> <input type="checkbox" class="checkbox" checked>')
|
|
})
|
|
it('parseLinks 3', function () {
|
|
assert.deepStrictEqual(MD.renderInline("test #[[TODO]] test2"), 'test <input type="checkbox" class="checkbox"> test2')
|
|
})
|
|
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>')
|
|
})
|
|
it('parseLinks 5', function () {
|
|
assert.deepStrictEqual(MD.renderInline("test [[test]]"), 'test <a href="/test" class="wiki-link">test</a>')
|
|
})
|
|
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>')
|
|
})
|
|
|
|
it('parseLinks tag', function () {
|
|
assert.deepStrictEqual(MD.renderInline("test #[[test]]"), 'test <a href="/test" class="wiki-link">#test</a>')
|
|
})
|
|
})
|