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 a0e1f87
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 = [];

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

// replace to their website html links
new Set(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 a0e1f87

Please sign in to comment.