private List<InputStream> convertToInputStreams(List<File> source) throws IOException { List<InputStream> inputStreams = new ArrayList<>(); Asciidoctor asciidoctor = Factory.create(); ExtensionGroup group = asciidoctor.createGroup(); Preprocessor preprocessor = new Preprocessor(); group.preprocessor(preprocessor); Options options = new Options(); options.setToFile(false); options.setSafe(SafeMode.UNSAFE); group.register(); for (File file : source) { inputStreams.add(processSingleFile(file, asciidoctor, group, preprocessor, options)); } return inputStreams; }
@Test public void a_preprocessor_instance_should_be_executed_before_document_is_rendered() { this.asciidoctor.createGroup() .preprocessor(new ChangeAttributeValuePreprocessor(new HashMap<String, Object>())) .register(); String content = asciidoctor.convertFile( classpath.getResource("changeattribute.adoc"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); assertThat(doc.getElementsByTag("p").first().text(), is("sample Alex")); }
@Test public void a_preprocessor_should_be_executed_before_document_is_rendered() { this.asciidoctor.createGroup() .preprocessor(ChangeAttributeValuePreprocessor.class) .register(); String content = asciidoctor.convertFile( classpath.getResource("changeattribute.adoc"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); assertThat(doc.getElementsByTag("p").first().text(), is("sample Alex")); }
@Test public void a_preprocessor_as_string_should_be_executed_before_document_is_rendered() { this.asciidoctor.createGroup() .preprocessor("org.asciidoctor.extension.ChangeAttributeValuePreprocessor") .register(); String content = asciidoctor.convertFile( classpath.getResource("changeattribute.adoc"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); assertThat(doc.getElementsByTag("p").first().text(), is("sample Alex")); }