From 20d6c0adf506d9021b12d82f075e9daec58c0f25 Mon Sep 17 00:00:00 2001 From: Brian Dominick Date: Sat, 4 Nov 2017 22:59:08 -0400 Subject: [PATCH] Split conversion action; add CLI system call for asciidoctor-pdf This resolves issue #24 Dividing convert calls between PDF backend and non-PDF, with all PDF calls using system asciidoctor-pdf. I don't love this solution, but it's good enough for now. --- lib/liquidoc.rb | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/liquidoc.rb b/lib/liquidoc.rb index aaeba0c..44fb694 100755 --- a/lib/liquidoc.rb +++ b/lib/liquidoc.rb @@ -568,18 +568,25 @@ def asciidocify doc, build doc.add_attrs!(@passed_attrs) @logger.debug "Final pre-parse attributes: #{doc.attributes}" # Perform the aciidoctor convert - Asciidoctor.convert_file( - doc.index, - to_file: to_file, - attributes: doc.attributes, - require: "pdf", - backend: back, - doctype: build.doctype, - safe: "server", - sourcemap: true, - verbose: @verbose, - mkdirs: true - ) + unless back == "pdf" + Asciidoctor.convert_file( + doc.index, + to_file: to_file, + attributes: doc.attributes, + require: "pdf", + backend: back, + doctype: build.doctype, + safe: "unsafe", + sourcemap: true, + verbose: @verbose, + mkdirs: true + ) + else # For PDFs, we're calling the asciidoctor-pdf CLI, as the main dependency does not seem to perform the same way + attributes = '-a ' + doc.attributes.map{|k,v| "#{k}='#{v}'"}.join(' -a ') + command = "asciidoctor-pdf -o #{to_file} -b pdf -d #{build.doctype} -S unsafe #{attributes} -a no-header-footer --trace #{doc.index}" + @logger.debug "Running #{command}" + system command + end @logger.info "Rendered file #{to_file}." end