Skip to content

Commit f69e77d

Browse files
committed
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 <sheogorath@shivering-isles.com>
1 parent 7c7cc28 commit f69e77d

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/response.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,18 @@ function actionInfo (req, res, note) {
327327
}
328328

329329
function actionPDF (req, res, note) {
330+
var url = config.serverURL || 'http://' + req.get('host')
330331
var body = note.content
331332
var extracted = models.Note.extractMeta(body)
333+
var content = extracted.markdown
332334
var title = models.Note.decodeTitle(note.title)
333335

334336
if (!fs.existsSync(config.tmpPath)) {
335337
fs.mkdirSync(config.tmpPath)
336338
}
337339
var path = config.tmpPath + '/' + Date.now() + '.pdf'
338-
markdownpdf().from.string(extracted.markdown).to(path, function () {
340+
content = content.replace(/\]\(\//g, '](' + url + '/')
341+
markdownpdf().from.string(content).to(path, function () {
339342
var stream = fs.createReadStream(path)
340343
var filename = title
341344
// Be careful of special characters

0 commit comments

Comments
 (0)