From fc2e34c2a5c61c9e50ee6a356c24b72d52bd0b91 Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Tue, 16 Oct 2018 10:12:15 -0400 Subject: [PATCH] fix markdown rendering --- app/components/markdown.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/components/markdown.js b/app/components/markdown.js index 83dd6a4..ba48286 100644 --- a/app/components/markdown.js +++ b/app/components/markdown.js @@ -62,22 +62,22 @@ function partialFinder(markdownBody) { const regexToFindPartials = /<\w+ ?\/>/g; const partials = markdownBody.match(regexToFindPartials); - if (!partials) return markdownBody; + if (partials) { + for (const partial of partials) { + const filename = decamelize(partial, "-").replace("<", "") + .replace("/>", "") + .trim(); + const fileExistsTest = exists(`./app/components/${filename}.js`); // `local` results in error if used here and file !exist - for (const partial of partials) { - const filename = decamelize(partial, "-").replace("<", "") - .replace("/>", "") - .trim(); - const fileExistsTest = exists(`./app/components/${filename}.js`); // `local` results in error if used here and file !exist + if (!fileExistsTest) + markdownBody = markdownBody.replace(partial, ""); - if (!fileExistsTest) - markdownBody = markdownBody.replace(partial, ""); + else { + const partialFunction = require(path.join(__dirname, "..", `./components/${filename}.js`)); - else { - const partialFunction = require(path.join(__dirname, "..", `./components/${filename}.js`)); - - if (filename === "glossary-toc") markdownBody = markdownBody.replace(partial, partialFunction); - else markdownBody = markdownBody.replace(partial, `${partialFunction.default()}
`); + if (filename === "glossary-toc") markdownBody = markdownBody.replace(partial, partialFunction); + else markdownBody = markdownBody.replace(partial, `
${partialFunction.default()}
`); + } } }