From f69e77de424ea763a87a04c9d66196d9353c8690 Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Sun, 24 Jun 2018 01:00:20 +0200 Subject: Fix broken images in PDF caused by misconfigred server URL As it turns out, if the serverURL can't be generated correctly, HackMD will use relative paths in image upload. This causes broken links in PDF. With this commit we force absolute links during PDF creation which hopefully fixes the problem. Signed-off-by: Sheogorath --- lib/response.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/response.js') diff --git a/lib/response.js b/lib/response.js index 4cfa9a74..a3c988fc 100644 --- a/lib/response.js +++ b/lib/response.js @@ -327,15 +327,18 @@ function actionInfo (req, res, note) { } function actionPDF (req, res, note) { + var url = config.serverURL || 'http://' + req.get('host') var body = note.content var extracted = models.Note.extractMeta(body) + var content = extracted.markdown var title = models.Note.decodeTitle(note.title) if (!fs.existsSync(config.tmpPath)) { fs.mkdirSync(config.tmpPath) } var path = config.tmpPath + '/' + Date.now() + '.pdf' - markdownpdf().from.string(extracted.markdown).to(path, function () { + content = content.replace(/\]\(\//g, '](' + url + '/') + markdownpdf().from.string(content).to(path, function () { var stream = fs.createReadStream(path) var filename = title // Be careful of special characters -- cgit v1.2.3