a case study in simplicity: allow dashes in markdown wiki links
This commit is contained in:
parent
6c87e69cbe
commit
c019f2421f
2 changed files with 15 additions and 13 deletions
|
@ -35,17 +35,7 @@ const md = require("markdown-it")({
|
||||||
if (finalString.match(numberRegex)) finalString = `_${finalString}`;
|
if (finalString.match(numberRegex)) finalString = `_${finalString}`;
|
||||||
return finalString;
|
return finalString;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
.use(require("markdown-it-wikilinks")({
|
|
||||||
makeAllLinksAbsolute: true,
|
|
||||||
baseURL: "/glossary#",
|
|
||||||
uriSuffix: "",
|
|
||||||
htmlAttributes: {
|
|
||||||
class: "wikilink"
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// E X P O R T
|
// 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 markdownFile = fs.readFileSync(`./documents/${path}.md`, "utf-8");
|
||||||
const markdownFileDetails = fm(markdownFile);
|
const markdownFileDetails = fm(markdownFile);
|
||||||
const renderedMarkdown = md.render(markdownFileDetails.body);
|
const renderedMarkdown = md.render(markdownFileDetails.body);
|
||||||
const updatedMarkdown = partialFinder(renderedMarkdown);
|
const updatedMarkdown = wikiFinder(partialFinder(renderedMarkdown));
|
||||||
|
|
||||||
if (markdownFileDetails.attributes.meta) {
|
if (markdownFileDetails.attributes.meta) {
|
||||||
const customMetadata = {};
|
const customMetadata = {};
|
||||||
|
@ -146,3 +136,16 @@ function partialFinder(markdownBody) {
|
||||||
|
|
||||||
return 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 ?
|
||||||
|
`<a href="${href}" class="link--glossary">${label}</a>` :
|
||||||
|
match.input;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
"make-promises-safe": "^1.1.0",
|
"make-promises-safe": "^1.1.0",
|
||||||
"markdown-it": "^8.4.2",
|
"markdown-it": "^8.4.2",
|
||||||
"markdown-it-anchor": "^5.0.2",
|
"markdown-it-anchor": "^5.0.2",
|
||||||
"markdown-it-wikilinks": "^1.0.1",
|
|
||||||
"nanocomponent": "^6.5.2",
|
"nanocomponent": "^6.5.2",
|
||||||
"prismjs": "^1.15.0",
|
"prismjs": "^1.15.0",
|
||||||
"redis": "^2.8.0",
|
"redis": "^2.8.0",
|
||||||
|
|
Loading…
Reference in a new issue