/* neon-adoc - Asciidoctor extensions to Neon Copyright (C) 2024 Ulrich Hilger This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ package de.uhilger.neon.adoc; import java.io.File; import org.asciidoctor.Asciidoctor; import static org.asciidoctor.Asciidoctor.Factory.create; import org.asciidoctor.Attributes; import org.asciidoctor.Options; import org.asciidoctor.SafeMode; /** * Objekte der Klasse AdocWorker wandeln Asciidoc-Quelldateien in HTML und PDF um. * * @author Ulrich Hilger */ public class AdocWorker { /** * Nach HTML transformieren * @param fileName der Dateiname der Quelldatei samt absoluter Pfadangabe */ public void transform(String fileName) { transform(fileName, null); } /** * In ein Format transformieren, das von einem 'Backend' von Asciidoctor * unterstuetzt wird * @param fileName der Dateiname der Quelldatei samt absoluter Pfadangabe * @param backend das Kuerzel des Backends, z.B. der String 'pdf', wenn * nach PDF transformiert werden soll */ public void transform(String fileName, String backend) { 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.builder() .attribute("pdf-themesdir", thisDirName) .attribute("pdf-theme","custom") .attribute("pdf-fontsdir", thisDirName + "/fonts") .attribute("allow-uri-read") .sourceHighlighter("highlightjs") .build(); } else { attributes = Attributes.builder() .sourceHighlighter("highlightjs") .build(); } Options options; if(null != backend) { options = Options.builder() .inPlace(false) .safe(SafeMode.SERVER) .backend(backend).attributes(attributes).build(); } else { options = Options.builder() .inPlace(false) .safe(SafeMode.SERVER) .attributes(attributes).build(); } File adcf = new File(fileName); Asciidoctor asciidoctor = create(); asciidoctor.requireLibrary("asciidoctor-diagram"); asciidoctor.convertFile(adcf, options); } }