Skip to content

Commit ec78c4f

Browse files
authored
Merge pull request #857 from hackmdio/fix/pdf-links
Fix broken images in PDF caused by misconfigred server URL
2 parents 050146e + f69e77d commit ec78c4f

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)