diff --git a/app/views/redirect.js b/app/views/redirect.js index 0ac7d63..1593f45 100644 --- a/app/views/redirect.js +++ b/app/views/redirect.js @@ -35,17 +35,7 @@ const md = require("markdown-it")({ if (finalString.match(numberRegex)) finalString = `_${finalString}`; return finalString; } - }) - .use(require("markdown-it-wikilinks")({ - makeAllLinksAbsolute: true, - baseURL: "/glossary#", - uriSuffix: "", - htmlAttributes: { - class: "wikilink" - } - })); - - + }); // E X P O R T @@ -78,7 +68,7 @@ module.exports = exports = (state, emit) => { // eslint-disable-line const markdownFile = fs.readFileSync(`./documents/${path}.md`, "utf-8"); const markdownFileDetails = fm(markdownFile); const renderedMarkdown = md.render(markdownFileDetails.body); - const updatedMarkdown = partialFinder(renderedMarkdown); + const updatedMarkdown = wikiFinder(partialFinder(renderedMarkdown)); if (markdownFileDetails.attributes.meta) { const customMetadata = {}; @@ -146,3 +136,16 @@ function partialFinder(markdownBody) { return markdownBody; } + + +function wikiFinder(markdownBody) { + return markdownBody.replace(/\[\[([\w\s/-]+)\]\]/g, (match, p1) => { + const label = p1.trim(), + href = encodeURI("/glossary#" + label.replace(/\s+/g, '-')); + + return label ? + `${label}` : + match.input; + } + ); +} diff --git a/package.json b/package.json index 65a8a44..1dbb845 100755 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "make-promises-safe": "^1.1.0", "markdown-it": "^8.4.2", "markdown-it-anchor": "^5.0.2", - "markdown-it-wikilinks": "^1.0.1", "nanocomponent": "^6.5.2", "prismjs": "^1.15.0", "redis": "^2.8.0",