@@ -316,17 +316,22 @@ function actionPDF (req, res, note) {
316
316
var content = extracted . markdown
317
317
var title = models . Note . decodeTitle ( note . title )
318
318
319
+ var highlightCssPath = path . join ( config . appRootPath , '/node_modules/highlight.js/styles/github-gist.css' )
320
+
319
321
if ( ! fs . existsSync ( config . tmpPath ) ) {
320
322
fs . mkdirSync ( config . tmpPath )
321
323
}
322
- var path = config . tmpPath + '/' + Date . now ( ) + '.pdf'
324
+ var pdfPath = config . tmpPath + '/' + Date . now ( ) + '.pdf'
323
325
content = content . replace ( / \] \( \/ / g, '](' + url + '/' )
324
- markdownpdf ( ) . from . string ( content ) . to ( path , function ( ) {
325
- if ( ! fs . existsSync ( path ) ) {
326
- logger . error ( 'PDF seems to not be generated as expected. File doesn\'t exist: ' + path )
326
+ var markdownpdfOptions = {
327
+ highlightCssPath : highlightCssPath
328
+ }
329
+ markdownpdf ( markdownpdfOptions ) . from . string ( content ) . to ( pdfPath , function ( ) {
330
+ if ( ! fs . existsSync ( pdfPath ) ) {
331
+ logger . error ( 'PDF seems to not be generated as expected. File doesn\'t exist: ' + pdfPath )
327
332
return errorInternalError ( res )
328
333
}
329
- var stream = fs . createReadStream ( path )
334
+ var stream = fs . createReadStream ( pdfPath )
330
335
var filename = title
331
336
// Be careful of special characters
332
337
filename = encodeURIComponent ( filename )
@@ -336,7 +341,7 @@ function actionPDF (req, res, note) {
336
341
res . setHeader ( 'Content-Type' , 'application/pdf; charset=UTF-8' )
337
342
res . setHeader ( 'X-Robots-Tag' , 'noindex, nofollow' ) // prevent crawling
338
343
stream . pipe ( res )
339
- fs . unlinkSync ( path )
344
+ fs . unlinkSync ( pdfPath )
340
345
} )
341
346
}
342
347
0 commit comments