Skip to content

Commit

Permalink
better mdToHtmlify
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed Jul 15, 2018
1 parent e80ced2 commit 6add46f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/server/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ function getFile(metadata) {

function mdToHtmlify(oldContent, mdToHtml, metadata) {
let content = oldContent;
const mdLinks = new Set();

// find all markdown links
const regex = /(?:\]\()(?:\.\/)?([^'")\]\s>]+\.md)/g;
let match = regex.exec(content);
while (match !== null) {
const mdLink = match[1];
mdLinks.add(match[1]);
match = regex.exec(content);
}

// replace all markdown links to html links
mdLinks.forEach(mdLink => {
let htmlLink = mdToHtml[mdLink];
if (htmlLink) {
htmlLink = getPath(htmlLink, siteConfig.cleanUrl);
Expand All @@ -57,8 +65,7 @@ function mdToHtmlify(oldContent, mdToHtml, metadata) {
`](${htmlLink}`
);
}
match = regex.exec(content);
}
});
return content;
}

Expand Down

0 comments on commit 6add46f

Please sign in to comment.