/** * Returns an {@link Asciidoctor} instance which is created lazliy to reduce * startup time. * * @return The {@link Asciidoctor} instance. */ private Asciidoctor getAsciidoctor() { if (asciidoctor == null) { asciidoctor = AsciidoctorFactory.getAsciidoctor(); treeprocessor = new Treeprocessor(); IgnoreIncludeProcessor includeProcessor = new IgnoreIncludeProcessor(); JavaExtensionRegistry extensionRegistry = asciidoctor.javaExtensionRegistry(); extensionRegistry.treeprocessor(treeprocessor); extensionRegistry.includeProcessor(includeProcessor); } return asciidoctor; }
@Test public void should_create_anchor_elements_for_inline_macros() { //tag::include[] File lsinclude_adoc = //... //end::include[] classpathResources.getResource("ls-include.adoc"); //tag::include[] String firstFileName = new File(".").listFiles()[0].getName(); asciidoctor.javaExtensionRegistry().includeProcessor(LsIncludeProcessor.class); // <1> String result = asciidoctor.convertFile(lsinclude_adoc, OptionsBuilder.options().toFile(false)); assertThat( result, containsString(firstFileName)); //end::include[] }
@Test public void an_inner_class_should_be_registered() { TestHttpServer.start(Collections.singletonMap("http://example.com/asciidoctorclass.rb", classpath.getResource("org/asciidoctor/internal/asciidoctorclass.rb"))); JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.includeProcessor(new RubyIncludeSource(new HashMap<>())); String content = asciidoctor.convertFile( classpath.getResource("sample-with-uri-include.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element contentElement = doc.getElementsByAttributeValue("class", "language-ruby").first(); assertThat(contentElement.text(), startsWith(ASCIIDOCTORCLASS_PREFIX)); }
@Test public void a_include_instance_processor_should_be_executed_when_include_macro_is_found() { TestHttpServer.start(Collections.singletonMap("http://example.com/asciidoctorclass.rb", classpath.getResource("org/asciidoctor/internal/asciidoctorclass.rb"))); JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.includeProcessor(new UriIncludeProcessor(new HashMap<>())); String content = asciidoctor.convertFile( classpath.getResource("sample-with-uri-include.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element contentElement = doc.getElementsByAttributeValue("class", "language-ruby").first(); assertThat(contentElement.text(), startsWith(ASCIIDOCTORCLASS_PREFIX)); }
@Test public void a_include_processor_instance_should_be_executed_twice() { TestHttpServer.start(Collections.singletonMap("http://example.com/asciidoctorclass.rb", classpath.getResource("org/asciidoctor/internal/asciidoctorclass.rb"))); JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.includeProcessor(new UriIncludeProcessor(new HashMap<>())); for (int i = 0; i < 2; i++) { String content = asciidoctor.convertFile( classpath.getResource("sample-with-uri-include.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element contentElement = doc.getElementsByAttributeValue("class", "language-ruby").first(); assertThat(contentElement.text(), startsWith(ASCIIDOCTORCLASS_PREFIX)); } }
@Test public void a_include_processor_should_only_handle_its_handles() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.includeProcessor(UriIncludeProcessor.class); String content = asciidoctor.convertFile(classpath.getResource("sample-with-include.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element contentElement = doc.getElementsByAttributeValue("class", "bare").first(); assertThat(contentElement.text(), startsWith("sample-book.adoc")); }
@Test public void a_include_processor_can_handle_positional_attrs() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.includeProcessor(PositionalAttrsIncludeProcessor.class); String content = asciidoctor.convertFile(classpath.getResource("sample-with-include-pos-attrs.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element contentElement = doc.getElementsByAttributeValue("class", "paragraph IncludeBlock").first(); assertThat(contentElement.text(), startsWith("My,Positional,Attribute List")); }
@Test public void a_include_processor_as_string_should_be_executed_when_include_macro_is_found() { TestHttpServer.start(Collections.singletonMap("http://example.com/asciidoctorclass.rb", classpath.getResource("org/asciidoctor/internal/asciidoctorclass.rb"))); JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.includeProcessor("org.asciidoctor.extension.UriIncludeProcessor"); String content = asciidoctor.convertFile( classpath.getResource("sample-with-uri-include.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element contentElement = doc.getElementsByAttributeValue("class", "language-ruby").first(); assertThat(contentElement.text(), startsWith(ASCIIDOCTORCLASS_PREFIX)); }
@Test public void a_include_processor_should_be_executed_when_include_macro_is_found() { TestHttpServer.start(Collections.singletonMap("http://example.com/asciidoctorclass.rb", classpath.getResource("org/asciidoctor/internal/asciidoctorclass.rb"))); JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.includeProcessor(UriIncludeProcessor.class); String content = asciidoctor.convertFile( classpath.getResource("sample-with-uri-include.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element contentElement = doc.getElementsByAttributeValue("class", "language-ruby").first(); assertThat(contentElement.text(), startsWith(ASCIIDOCTORCLASS_PREFIX)); }
@Test public void a_include_processor_class_should_be_executed_twice() { TestHttpServer.start(Collections.singletonMap("http://example.com/asciidoctorclass.rb", classpath.getResource("org/asciidoctor/internal/asciidoctorclass.rb"))); JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.includeProcessor(UriIncludeProcessor.class); for (int i = 0; i < 2; i++) { String content = asciidoctor.convertFile( classpath.getResource("sample-with-uri-include.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element contentElement = doc.getElementsByAttributeValue("class", "language-ruby").first(); assertThat(contentElement.text(), startsWith(ASCIIDOCTORCLASS_PREFIX)); } }
javaExtensionRegistry.includeProcessor(new IncludeProcessor(new HashMap<>()) {