@Override public void register(Asciidoctor asciidoctor) { JavaExtensionRegistry javaExtensionRegistry = asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.treeprocessor(RemotePlantUMLTreeprocessor.class); }
private void createDocs() { String version = "2.0.0-SNAPSHOT"; Asciidoctor asciidoctor = create(); try { File file = new File("sqlg-doc/docs/" + version + "/sqlg.adoc"); File html = new File("sqlg-doc/docs/" + version + "/index.html"); Attributes attributes = new Attributes(); attributes.setBackend("html5"); attributes.setStyleSheetName("asciidoctor-default.css"); attributes.setDocType("book"); attributes.setSourceHighlighter("highlightjs"); Map<String, Object> options = OptionsBuilder.options() .attributes(attributes) .toFile(new File(html.getPath())) .headerFooter(true) .safe(SafeMode.SERVER) .asMap(); options.put("location", ":footer"); Docinfo docinfo = new Docinfo(options); asciidoctor.javaExtensionRegistry().docinfoProcessor(docinfo); asciidoctor.convertFile( file, options ); } catch (Exception e) { throw new RuntimeException(e); } }
/** * 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; }
@Override public void register(Asciidoctor asciidoctor) { JavaExtensionRegistry javaExtensionRegistry = asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.postprocessor(ArrowsAndBoxesIncludesPostProcessor.class); javaExtensionRegistry.block("arrowsAndBoxes", ArrowsAndBoxesBlock.class); }
@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(expected = IllegalArgumentException.class) public void testRegisterClassWithoutExplicitName() { asciidoctor.javaExtensionRegistry().block(AbstractTestProcessor.class); }
@Test(expected = IllegalArgumentException.class) public void testRegisterClassWithoutExplicitName() { asciidoctor.javaExtensionRegistry().inlineMacro(AbstractTestProcessor.class); }
@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(expected = IllegalArgumentException.class) public void testRegisterClassWithoutExplicitName() { asciidoctor.javaExtensionRegistry().blockMacro(AbstractTestProcessor.class); }
@Test public void a_treeprocessor_and_blockmacroprocessor_should_be_executed_in_document() { this.asciidoctor.javaExtensionRegistry() .treeprocessor(TerminalCommandTreeprocessor.class) .blockMacro("gist", GistMacro.class); String content = asciidoctor.convertFile( classpath.getResource("sample-with-terminal-command-and-gist-macro.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element contentElement = doc.getElementsByAttributeValue("class", "command").first(); assertThat(contentElement.text(), is("echo \"Hello, World!\"")); contentElement = doc.getElementsByAttributeValue("class", "command").last(); assertThat(contentElement.text(), is("gem install asciidoctor")); Element script = doc.getElementsByTag("script").first(); assertThat(script.attr("src"), is("https://gist.github.com/42.js")); }
@Test public void shouldAllowLoadingByClassName() { final JavaExtensionRegistry registry = asciidoctor.javaExtensionRegistry(); registry.postprocessor(BoldifyPostProcessor.class.getCanonicalName()); }
@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(expected = IllegalArgumentException.class) public void testRegisterClassWithNameAsClass() { asciidoctor.javaExtensionRegistry().block(TestProcessorWithName.class); }
@Test(expected = IllegalArgumentException.class) public void testRegisterClassWithNameAsClass() { asciidoctor.javaExtensionRegistry().inlineMacro(TestProcessorWithName.class); }
@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(expected = IllegalArgumentException.class) public void testRegisterClassWithNameAsClass() { asciidoctor.javaExtensionRegistry().blockMacro(TestProcessorWithName.class); }
@Test public void shouldAllowLoadingByClass() { final JavaExtensionRegistry registry = asciidoctor.javaExtensionRegistry(); registry.postprocessor(BoldifyPostProcessor.class); }
@Test public void createAstStructure() throws Exception { asciidoctor.javaExtensionRegistry().treeprocessor(ASTExtractorTreeprocessor.class); Document document = asciidoctor.loadFile(classpathResources.getResource("ast-demo.adoc"), OptionsBuilder.options().asMap()); assertThat( ASTExtractorTreeprocessor.result.toString(), is(IOUtils.readFull(new FileReader(classpathResources.getResource("ast-demo-result.txt"))).replaceAll("\\r", ""))); }
@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(expected = IllegalArgumentException.class) public void testRegisterClassAsClass() { asciidoctor.javaExtensionRegistry().block(AbstractTestProcessor.class); }