Issue #275: Activate Syntax Highlighting with Coderay in Asciidoc templates

This commit is contained in:
Mario Zupan
2016-12-15 17:32:27 +01:00
parent b8b632905d
commit 6fa894938b
4 changed files with 149 additions and 5 deletions

View File

@ -45,6 +45,7 @@ import java.io.InputStream;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
import static org.asciidoctor.Asciidoctor.Factory.create;
@ -83,7 +84,7 @@ public class AsciiDoctorTemplateResolver extends TemplateResolver {
if (adocFile.isPresent()) {
try (FileReader reader = new FileReader(adocFile.get().toFile())) {
StringWriter writer = new StringWriter();
asciidoctor.convert(reader, writer, Maps.newHashMap());
asciidoctor.convert(reader, writer, createAttributes());
return new ByteArrayInputStream(writer.getBuffer().toString().getBytes());
}
}
@ -94,6 +95,16 @@ public class AsciiDoctorTemplateResolver extends TemplateResolver {
}
}
private Map<String, Object> createAttributes() {
Map<String, Object> attributes = Maps.newHashMap();
attributes.put("source-highlighter", "coderay");
Map<String, Object> options = Maps.newHashMap();
options.put("attributes", attributes);
return options;
}
private Optional<Path> find(Path path, String resourceName) throws IOException {
return Files.walk(path)
.filter(Files::isRegularFile)