@Override public void register(Asciidoctor asciidoctor) { //null means extension is enabled (by default) if(System.getProperty(DISABLE_ALL_EXT_KEY) != null) { return; } ExtensionGroup cukedoctorExtensionGroup = asciidoctor.createGroup(CUKEDOCTOR_EXTENSION_GROUP_NAME); cukedoctorExtensionGroup.postprocessor(CukedoctorScriptExtension.class); if(System.getProperty(FILTER_DISABLE_EXT_KEY) == null){ cukedoctorExtensionGroup.postprocessor(CukedoctorFilterExtension.class); } if(System.getProperty(MINMAX_DISABLE_EXT_KEY) == null){ cukedoctorExtensionGroup.blockMacro("minmax", CukedoctorMinMaxExtension.class); } if(System.getProperty(THEME_DISABLE_EXT_KEY) == null){ cukedoctorExtensionGroup.postprocessor(CukedoctorThemeExtension.class); } if(System.getProperty(FOOTER_DISABLE_EXT_KEY) == null){ cukedoctorExtensionGroup.postprocessor(CukedoctorFooterExtension.class); } if(System.getProperty(STYLE_DISABLE_EXT_KEY) == null){ cukedoctorExtensionGroup.postprocessor(CukedoctorStyleExtension.class); } cukedoctorExtensionGroup.register(); }
@Override public void register(Asciidoctor asciidoctor) { //null means extension is enabled (by default) if(System.getProperty(DISABLE_ALL_EXT_KEY) != null) { return; } ExtensionGroup cukedoctorExtensionGroup = asciidoctor.createGroup(CUKEDOCTOR_EXTENSION_GROUP_NAME); cukedoctorExtensionGroup.postprocessor(CukedoctorScriptExtension.class); if(System.getProperty(FILTER_DISABLE_EXT_KEY) == null){ cukedoctorExtensionGroup.postprocessor(CukedoctorFilterExtension.class); } if(System.getProperty(MINMAX_DISABLE_EXT_KEY) == null){ cukedoctorExtensionGroup.blockMacro("minmax", CukedoctorMinMaxExtension.class); } if(System.getProperty(THEME_DISABLE_EXT_KEY) == null){ cukedoctorExtensionGroup.postprocessor(CukedoctorThemeExtension.class); } if(System.getProperty(FOOTER_DISABLE_EXT_KEY) == null){ cukedoctorExtensionGroup.postprocessor(CukedoctorFooterExtension.class); } if(System.getProperty(STYLE_DISABLE_EXT_KEY) == null){ cukedoctorExtensionGroup.postprocessor(CukedoctorStyleExtension.class); } cukedoctorExtensionGroup.register(); }
@Test public void a_block_macro_extension_instance_should_be_executed_when_macro_is_detected() { this.asciidoctor.createGroup() .blockMacro(new GistMacro("gist", new HashMap<String, Object>())) .register(); String content = asciidoctor.convertFile( classpath.getResource("sample-with-gist-macro.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element script = doc.getElementsByTag("script").first(); assertThat(script.attr("src"), is("https://gist.github.com/123456.js")); }
@Test public void a_block_macro_as_instance_extension_should_be_executed_when_macro_is_detected() { Map<String, Object> options = new HashMap<>(); options.put(ContentModel.KEY, ContentModel.RAW); this.asciidoctor.createGroup() .blockMacro(new GistMacro("gist", options)) .register(); String content = asciidoctor.convertFile( classpath.getResource("sample-with-gist-macro.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element script = doc.getElementsByTag("script").first(); assertThat(script.attr("src"), is("https://gist.github.com/123456.js")); }
@Test public void a_block_macro_extension_should_be_executed_when_macro_is_detected() { this.asciidoctor.createGroup() .blockMacro("gist", GistMacro.class) .register(); String content = asciidoctor.convertFile( classpath.getResource("sample-with-gist-macro.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element script = doc.getElementsByTag("script").first(); assertThat(script.attr("src"), is("https://gist.github.com/123456.js")); }
@Test public void a_block_macro_as_string_extension_should_be_executed_when_macro_is_detected() { this.asciidoctor.createGroup() .blockMacro("gist", "org.asciidoctor.extension.GistMacro") .register(); String content = asciidoctor.convertFile( classpath.getResource("sample-with-gist-macro.ad"), options().toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element script = doc.getElementsByTag("script").first(); assertThat(script.attr("src"), is("https://gist.github.com/123456.js")); }
@Test public void a_treeprocessor_and_blockmacroprocessor_should_be_executed_in_document() { this.asciidoctor.createGroup() .treeprocessor(TerminalCommandTreeprocessor.class) .blockMacro("gist", GistMacro.class) .register(); 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"); System.out.println(content); Element script = doc.getElementsByTag("script").first(); assertThat(script.attr("src"), is("https://gist.github.com/42.js")); 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")); }