You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
/*
|
|
|
|
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>`
|
|
}
|
|
)
|
|
|