Erweiterung von neon zur Transformation von Asciidoc
ulrich
4 days ago cf173715c28c6ac820df44009dd5bc3222af46fb
an AsciidoctorJ Version 3 angepasst
2 files modified
38 ■■■■■ changed files
src/de/uhilger/neon/adoc/AdocFilter.java 6 ●●●●● patch | view | raw | blame | history
src/de/uhilger/neon/adoc/AdocWorker.java 32 ●●●●● patch | view | raw | blame | history
src/de/uhilger/neon/adoc/AdocFilter.java
@@ -38,13 +38,11 @@
  @Override
  public void doFilter(HttpExchange exchange, Chain chain) throws IOException {
    URI uri = exchange.getRequestURI();
    //String path = uri.getPath();
    try {
      String path = new HttpHelper().getFileName(exchange);
      if(path.endsWith(".adoc")) {
      String fileName = new HttpHelper().getFileName(exchange);
      if(fileName.endsWith(".adoc")) {
        HttpContext ctx = exchange.getHttpContext();
        String fileBase = ctx.getAttributes().get(FileServer.ATTR_FILE_BASE).toString();
        String fileName = path.substring(ctx.getPath().length());
        String query = uri.getQuery();
        if (query instanceof String && query.contains("pdf=true")) {
          processAdocFile(new File(fileBase, fileName), true);
src/de/uhilger/neon/adoc/AdocWorker.java
@@ -18,11 +18,10 @@
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;
/**
@@ -48,43 +47,40 @@
   * 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);    
  }  
}