Files
frontend/marko/components/markdown/plugins/wikilink.js
T
2018-09-13 21:15:47 +02:00

41 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
Based on the markdown-it-wikilinks, which is distributed under the MIT license.
https://github.com/jsepia/markdown-it-wikilinks @ 79fe609a03917f7df11128231118a66a559076d0
Copyright (c) 2016 Julio Sepia
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
const Plugin = require('markdown-it-regexp')
module.exports = new Plugin(/\[\[([\w'\s/]+)(\|([\w'\s/]+))?\]\]/, match => {
let label = ""
let page = ""
if (match[3] != null) {
label = match[3]
page = encodeURIComponent(match[1])
} else {
label = match[1]
page = encodeURIComponent(label)
}
if (label == "" || page == "") {
return match.input
}
return `<a class="wiki-link" href="https://wiki.aiterp.net?title=${page}">${label}</a>`
}
)