@@ -316,17 +316,22 @@ function actionPDF (req, res, note) {
316316 var content = extracted . markdown
317317 var title = models . Note . decodeTitle ( note . title )
318318
319+ var highlightCssPath = path . join ( config . appRootPath , '/node_modules/highlight.js/styles/github-gist.css' )
320+
319321 if ( ! fs . existsSync ( config . tmpPath ) ) {
320322 fs . mkdirSync ( config . tmpPath )
321323 }
322- var path = config . tmpPath + '/' + Date . now ( ) + '.pdf'
324+ var pdfPath = config . tmpPath + '/' + Date . now ( ) + '.pdf'
323325 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 )
327332 return errorInternalError ( res )
328333 }
329- var stream = fs . createReadStream ( path )
334+ var stream = fs . createReadStream ( pdfPath )
330335 var filename = title
331336 // Be careful of special characters
332337 filename = encodeURIComponent ( filename )
@@ -336,7 +341,7 @@ function actionPDF (req, res, note) {
336341 res . setHeader ( 'Content-Type' , 'application/pdf; charset=UTF-8' )
337342 res . setHeader ( 'X-Robots-Tag' , 'noindex, nofollow' ) // prevent crawling
338343 stream . pipe ( res )
339- fs . unlinkSync ( path )
344+ fs . unlinkSync ( pdfPath )
340345 } )
341346}
342347
0 commit comments