| | |
| | | package de.uhilger.neon.adoc; |
| | | |
| | | import java.io.File; |
| | | import java.util.Map; |
| | | import org.asciidoctor.Asciidoctor; |
| | | import static org.asciidoctor.Asciidoctor.Factory.create; |
| | | import static org.asciidoctor.AttributesBuilder.attributes; |
| | | import static org.asciidoctor.OptionsBuilder.options; |
| | | import org.asciidoctor.Attributes; |
| | | import org.asciidoctor.Options; |
| | | import org.asciidoctor.SafeMode; |
| | | |
| | | /** |
| | |
| | | * nach PDF transformiert werden soll |
| | | */ |
| | | public void transform(String fileName, String backend) { |
| | | //logger.fine("fileName: " + fileName + ", backend: " + backend); |
| | | Map<String, Object> attributes; |
| | | Attributes attributes; |
| | | File outFile = new File(fileName); |
| | | String thisDirName = outFile.getParent(); |
| | | File pdfStyles = new File(outFile.getParentFile(), "custom-theme.yml"); |
| | | if(pdfStyles.exists()) { |
| | | attributes = attributes() |
| | | attributes = Attributes.builder() |
| | | .attribute("pdf-themesdir", thisDirName) |
| | | .attribute("pdf-theme","custom") |
| | | .attribute("pdf-fontsdir", thisDirName + "/fonts") |
| | | .attribute("allow-uri-read") |
| | | .sourceHighlighter("highlightjs") |
| | | .asMap(); |
| | | .build(); |
| | | } else { |
| | | attributes = attributes() |
| | | attributes = Attributes.builder() |
| | | .sourceHighlighter("highlightjs") |
| | | .asMap(); |
| | | .build(); |
| | | } |
| | | Map<String, Object> options; |
| | | Options options; |
| | | if(null != backend) { |
| | | options = options().inPlace(false) |
| | | options = Options.builder() |
| | | .inPlace(false) |
| | | .safe(SafeMode.SERVER) |
| | | .backend(backend).attributes(attributes).asMap(); |
| | | .backend(backend).attributes(attributes).build(); |
| | | |
| | | } else { |
| | | options = options().inPlace(false) |
| | | options = Options.builder() |
| | | .inPlace(false) |
| | | .safe(SafeMode.SERVER) |
| | | .attributes(attributes).asMap(); |
| | | .attributes(attributes).build(); |
| | | } |
| | | |
| | | File adcf = new File(fileName); |
| | | //logger.fine("before asciidoctor create, adcf: " + adcf.getAbsolutePath()); |
| | | Asciidoctor asciidoctor = create(); |
| | | //logger.fine("asciidoctor created."); |
| | | asciidoctor.requireLibrary("asciidoctor-diagram"); |
| | | //logger.fine("asciidoctor requireLibrary diagram passed."); |
| | | //logger.fine("calling asciidoctor.convert for file " + adcf.getAbsolutePath()); |
| | | asciidoctor.convertFile(adcf, options); |
| | | } |
| | | } |