@Override public void process(Document document, PreprocessorReader reader, String target, Map<String, Object> attributes) { StringBuilder content = readContent(target); reader.push_include(content.toString(), target, target, 1, attributes); }
@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_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"))); this.asciidoctor.createGroup() .includeProcessor(new UriIncludeProcessor(new HashMap<String, Object>())) .register(); 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)); }