@Override public void register(Asciidoctor asciidoctor) { asciidoctor.javaExtensionRegistry() .preprocessor(new DefaultAttributesPreprocessor()); asciidoctor.rubyExtensionRegistry() .loadClass(RestDocsExtensionRegistry.class .getResourceAsStream("/extensions/operation_block_macro.rb")) .blockMacro("operation", "OperationBlockMacro"); }
@Test public void currentLineNumberShouldBeReturned() { JavaExtensionRegistry javaExtensionRegistry = asciidoctor .javaExtensionRegistry(); javaExtensionRegistry.preprocessor(NumberLinesPreprocessor.class); File inputFile = classpath.getResource("rendersample.asciidoc"); asciidoctor.convertFile(inputFile, new HashMap<String, Object>()); File outpuFile = new File(inputFile.getParent(), "rendersample.asciidoc"); assertThat(outpuFile.exists(), is(true)); }
@Test public void hasMoreLinesShouldBeReturned() { JavaExtensionRegistry javaExtensionRegistry = asciidoctor .javaExtensionRegistry(); javaExtensionRegistry.preprocessor(HasMoreLinesPreprocessor.class); asciidoctor.convertFile( classpath.getResource("rendersample.asciidoc"), new HashMap<String, Object>()); File inputFile = classpath.getResource("rendersample.asciidoc"); asciidoctor.convertFile(inputFile, new HashMap<String, Object>()); File outpuFile = new File(inputFile.getParent(), "rendersample.asciidoc"); assertThat(outpuFile.exists(), is(true)); }
@Test public void isNextLineEmptyShouldBeReturned() { JavaExtensionRegistry javaExtensionRegistry = asciidoctor .javaExtensionRegistry(); javaExtensionRegistry.preprocessor(NextLineEmptyPreprocessor.class); asciidoctor.convertFile( classpath.getResource("rendersample.asciidoc"), new HashMap<String, Object>()); File inputFile = classpath.getResource("rendersample.asciidoc"); asciidoctor.convertFile(inputFile, new HashMap<String, Object>()); File outpuFile = new File(inputFile.getParent(), "rendersample.asciidoc"); assertThat(outpuFile.exists(), is(true)); }
@Test public void a_preprocessor_instance_should_be_executed_before_document_is_rendered() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.preprocessor(new ChangeAttributeValuePreprocessor(new HashMap<>())); 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() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.preprocessor(ChangeAttributeValuePreprocessor.class); 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() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.preprocessor("org.asciidoctor.extension.ChangeAttributeValuePreprocessor"); 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 should_render_comments_as_notes() { //tag::include[] File comment_adoc = //... //end::include[] classpathResources.getResource("comment.adoc"); //tag::include[] File comment_with_note_adoc = //... //end::include[] classpathResources.getResource("comment-with-note.adoc"); //tag::include[] asciidoctor.javaExtensionRegistry().preprocessor(CommentPreprocessor.class); // <1> String result1 = asciidoctor.convertFile(comment_adoc, OptionsBuilder.options().toFile(false)); String result2 = asciidoctor.convertFile(comment_with_note_adoc, OptionsBuilder.options().toFile(false)); assertThat(result1, is(result2)); // <2> //end::include[] }