From bd9881b03b09a840e229935776f689dc54f82efd Mon Sep 17 00:00:00 2001 From: bernardkkt Date: Tue, 27 Apr 2021 18:17:29 +0800 Subject: [PATCH] fix(render): Fix HTML rendering when no images are referenced (#9) Unable to render HTML (thus PDF) correctly when no images are referenced in markdown (#9) * Fix incorrect output when var encoded is undefined --- markdown-to-pdf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/markdown-to-pdf.js b/markdown-to-pdf.js index 207d8f7..2d54d7e 100755 --- a/markdown-to-pdf.js +++ b/markdown-to-pdf.js @@ -109,13 +109,13 @@ async function ConvertImageRoutes(html) { while (m = rex.exec(newPaths)) { try { let image = await encodeImage(m[1]); - newPaths = newPaths.replace(new RegExp(m[1], "g"), image); + if (image != null) { newPaths = newPaths.replace(new RegExp(m[1], "g"), image); } } catch (error) { console.log('ERROR:', error); } encoded = newPaths } - return encoded; + return (encoded == null) ? newPaths : encoded; } // This converts the markdown string to it's HTML values # => h1 etc.