org.asciidoctor.SafeMode Java Examples
The following examples show how to use
org.asciidoctor.SafeMode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RobotsDocinfoProcessorTest.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void should_create_anchor_elements_for_inline_macros() { //tag::include[] String src = "= Irrelevant content"; asciidoctor.javaExtensionRegistry() .docinfoProcessor(RobotsDocinfoProcessor.class); // <1> String result = asciidoctor.convert( src, OptionsBuilder.options() .headerFooter(true) // <2> .safe(SafeMode.SERVER) // <3> .toFile(false)); org.jsoup.nodes.Document document = Jsoup.parse(result); // <4> Element metaElement = document.head().children().last(); assertThat(metaElement.tagName(), is("meta")); assertThat(metaElement.attr("name"), is("robots")); assertThat(metaElement.attr("content"), is("index,follow")); //end::include[] }
Example #2
Source File: AbstractAsciiDocMojo.java From helidon-build-tools with Apache License 2.0 | 6 votes |
private Map<String, Object> asciiDoctorOptions( Map<String, Object> attributes, Path inputRelativePath, File outputDirectory, Path baseDirPath, boolean runPreprocessing) { final OptionsBuilder optionsBuilder = OptionsBuilder.options() .attributes( AttributesBuilder .attributes() .attributes(attributes)) .safe(SafeMode.UNSAFE) .headerFooter(false) .baseDir(baseDirPath.toFile()) .eruby(""); if (outputDirectory != null) { optionsBuilder.option("preincludeOutputPath", outputDirectory.toPath().resolve(inputRelativePath)); } if (runPreprocessing) { optionsBuilder.option("preprocessOutputType", outputType()); } return optionsBuilder.asMap(); }
Example #3
Source File: AsciidocEngine.java From helidon-build-tools with Apache License 2.0 | 6 votes |
/** * Read a document's header. * @param source the document to read the header from * @return the header as {@code Map<String, Object>}, never {@code null} */ public Map<String, Object> readDocumentHeader(File source){ checkValidFile(source, "source"); final OptionsBuilder optionsBuilder = OptionsBuilder.options() .attributes( AttributesBuilder .attributes() .attributes(attributes)) .safe(SafeMode.UNSAFE) .headerFooter(false) .eruby("") .baseDir(source.getParentFile()) .option("parse_header_only", true); if (backend != null) { optionsBuilder.backend(this.backend); } Document doc = asciidoctor.loadFile(source, optionsBuilder.asMap()); Map<String, Object> headerMap = new HashMap<>(); String h1 = parseSection0Title(source); if (h1 != null) { headerMap.put("h1", h1); } headerMap.putAll(doc.getAttributes()); return headerMap; }
Example #4
Source File: Swagger2ToDocTest.java From singleton with Eclipse Public License 2.0 | 6 votes |
@Test public void convertV1Doc() { Asciidoctor asciidoctor = create(); Options options = new Options(); options.setInPlace(true); options.setBackend("html5"); options.setSafe(SafeMode.SAFE); options.setToDir(baseOutputDir + "/html5/v1"); options.setMkDirs(true); options.setDocType("docbook"); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("toc", "left"); attributes.put("toclevels", "3"); attributes.put("generated", "./generated/v1"); options.setAttributes(attributes); asciidoctor.convertFile(new File(baseOutputDir + "/index.adoc"), options); }
Example #5
Source File: WhenRubyExtensionIsRegistered.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void ruby_includeprocessor_should_be_registered() { asciidoctor.rubyExtensionRegistry() .loadClass(getClass().getResourceAsStream("/ruby-extensions/response-include-processor.rb")) .includeProcessor("ResponseIncludeProcessor"); String content = asciidoctor.convert( "The response to everything is\n" + "\n" + "include::response[]" + "", options().toFile(false).safe(SafeMode.SAFE).get()); final Document document = Jsoup.parse(content); assertThat( document.getElementsByClass("paragraph").get(1).getElementsByTag("p").get(0).toString(), is("<p>42</p>")); }
Example #6
Source File: WhenRubyExtensionGroupIsRegistered.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void ruby_includeprocessor_should_be_registered() { asciidoctor.createGroup() .loadRubyClass(getClass().getResourceAsStream("/ruby-extensions/response-include-processor.rb")) .rubyIncludeProcessor("ResponseIncludeProcessor") .register(); String content = asciidoctor.convert( "The response to everything is\n" + "\n" + "include::response[]" + "", options().toFile(false).safe(SafeMode.SAFE).get()); final Document document = Jsoup.parse(content); assertThat( document.getElementsByClass("paragraph").get(1).getElementsByTag("p").get(0).toString(), is("<p>42</p>")); }
Example #7
Source File: CukedoctorMojo.java From cukedoctor with Apache License 2.0 | 6 votes |
private void generateDocumentation(DocumentAttributes documentAttributes, File adocFile, Asciidoctor asciidoctor) { OptionsBuilder ob = OptionsBuilder.options() .safe(SafeMode.UNSAFE) .backend(documentAttributes.getBackend()) .attributes(documentAttributes.toMap()); getLog().info("Document attributes:\n"+documentAttributes.toMap()); ExtensionGroup cukedoctorExtensionGroup = asciidoctor.createGroup(CUKEDOCTOR_EXTENSION_GROUP_NAME); if ("pdf".equals(documentAttributes.getBackend())) { cukedoctorExtensionGroup.unregister(); //remove auxiliary files FileUtil.removeFile(adocFile.getParent() + "/" + outputFileName + "-theme.yml"); } asciidoctor.convertFile(adocFile, ob); getLog().info("Generated documentation at: " + adocFile.getParent()); }
Example #8
Source File: WhenJavaExtensionGroupIsRegistered.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void should_unregister_all_current_registered_extensions() throws IOException { this.asciidoctor.createGroup() .postprocessor(CustomFooterPostProcessor.class) .register(); Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html")) .safe(SafeMode.UNSAFE).get(); asciidoctor.unregisterAllExtensions(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8"); Element footer = doc.getElementById("footer-text"); assertThat(footer.text(), not(containsString("Copyright Acme, Inc."))); }
Example #9
Source File: WhenJavaExtensionGroupIsRegistered.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void a_postprocessor_instance_should_be_executed_after_document_is_rendered() throws IOException { this.asciidoctor.createGroup() .postprocessor(new CustomFooterPostProcessor(new HashMap<String, Object>())) .register(); Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html")) .safe(SafeMode.UNSAFE).get(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8"); Element footer = doc.getElementById("footer-text"); assertThat(footer.text(), containsString("Copyright Acme, Inc.")); }
Example #10
Source File: WhenJavaExtensionGroupIsRegistered.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void a_postprocessor_should_be_executed_after_document_is_rendered() throws IOException { this.asciidoctor.createGroup() .postprocessor(CustomFooterPostProcessor.class) .register(); Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html")) .safe(SafeMode.UNSAFE).get(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8"); Element footer = doc.getElementById("footer-text"); assertThat(footer.text(), containsString("Copyright Acme, Inc.")); }
Example #11
Source File: WhenJavaExtensionGroupIsRegistered.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void a_docinfoprocessor_should_be_executed_and_add_meta_in_footer() { Map<String, Object> options = new HashMap<String, Object>(); options.put("location", ":footer"); MetaRobotsDocinfoProcessor metaRobotsDocinfoProcessor = new MetaRobotsDocinfoProcessor(options); this.asciidoctor.createGroup() .docinfoProcessor(metaRobotsDocinfoProcessor) .register(); String content = asciidoctor.convertFile( classpath.getResource("simple.adoc"), options().headerFooter(true).safe(SafeMode.SERVER).toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element footer = doc.getElementById("footer"); // Since Asciidoctor 1.5.3 the docinfo in the footer is a sibling to the footer element assertTrue("robots".equals(footer.nextElementSibling().attr("name"))); }
Example #12
Source File: WhenJavaExtensionGroupIsRegistered.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void a_postprocessor_as_string_should_be_executed_after_document_is_rendered() throws IOException { this.asciidoctor.createGroup() .postprocessor("org.asciidoctor.extension.CustomFooterPostProcessor") .register(); Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html")) .safe(SafeMode.UNSAFE).get(); asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options); File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8"); Element footer = doc.getElementById("footer-text"); assertThat(footer.text(), containsString("Copyright Acme, Inc.")); }
Example #13
Source File: WhenJavaExtensionIsRegistered.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void should_create_toc_with_treeprocessor() { asciidoctor.javaExtensionRegistry().treeprocessor(new Treeprocessor() { @Override public org.asciidoctor.ast.Document process(org.asciidoctor.ast.Document document) { List<StructuralNode> blocks = document.getBlocks(); for (StructuralNode block : blocks) { for (StructuralNode block2 : block.getBlocks()) { if (block2 instanceof Section) System.out.println(((Section) block2).getId()); } } return document; } }); String content = asciidoctor.convertFile( classpath.getResource("documentwithtoc.adoc"), options().headerFooter(true).toFile(false).safe(SafeMode.UNSAFE).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element toc = doc.getElementById("toc"); assertThat(toc, notNullValue()); Elements elements = toc.getElementsByAttributeValue("href", "#TestId"); assertThat(elements.size(), is(1)); }
Example #14
Source File: WhenJavaExtensionIsRegistered.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test @Ignore public void extensions_should_be_correctly_added_using_extension_registry() throws IOException { // To avoid registering the same extension over and over for all tests, // service is instantiated manually. new ArrowsAndBoxesExtension().register(asciidoctor); Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html")) .safe(SafeMode.UNSAFE).get(); asciidoctor.convertFile(classpath.getResource("arrows-and-boxes-example.ad"), options); File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8"); Element arrowsJs = doc.select("script[src=http://www.headjump.de/javascripts/arrowsandboxes.js").first(); assertThat(arrowsJs, is(notNullValue())); Element arrowsCss = doc.select("link[href=http://www.headjump.de/stylesheets/arrowsandboxes.css").first(); assertThat(arrowsCss, is(notNullValue())); Element arrowsAndBoxes = doc.select("pre[class=arrows-and-boxes").first(); assertThat(arrowsAndBoxes, is(notNullValue())); }
Example #15
Source File: WhenJavaExtensionIsRegistered.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void a_docinfoprocessor_should_be_executed_and_add_meta_in_footer() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); Map<String, Object> options = new HashMap<>(); options.put("location", ":footer"); MetaRobotsDocinfoProcessor metaRobotsDocinfoProcessor = new MetaRobotsDocinfoProcessor(options); javaExtensionRegistry.docinfoProcessor(metaRobotsDocinfoProcessor); String content = asciidoctor.convertFile( classpath.getResource("simple.adoc"), options().headerFooter(true).safe(SafeMode.SERVER).toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element footer = doc.getElementById("footer"); // Since Asciidoctor 1.5.3 the docinfo in the footer is a sibling to the footer element assertTrue("robots".equals(footer.nextElementSibling().attr("name"))); }
Example #16
Source File: OptionsTest.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void convert_to_dedicated_file() throws Exception { //tag::optionToFile[] File targetFile = //... //end::optionToFile[] temporaryFolder.newFile("toFileExample.html"); //tag::optionToFile[] asciidoctor.convert( "Hello World", OptionsBuilder.options() .toFile(targetFile) // <1> .safe(SafeMode.UNSAFE) // <2> .get()); assertTrue(targetFile.exists()); assertThat( IOUtils.toString(new FileReader(targetFile)), containsString("<p>Hello World")); //end::optionToFile[] }
Example #17
Source File: Swagger2ToDocTest.java From singleton with Eclipse Public License 2.0 | 6 votes |
@Test public void convertV2Doc() { Asciidoctor asciidoctor = create(); Options options = new Options(); options.setInPlace(true); options.setBackend("html5"); options.setSafe(SafeMode.SAFE); options.setToDir(baseOutputDir + "/html5/v2"); options.setMkDirs(true); options.setDocType("docbook"); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("toc", "left"); attributes.put("toclevels", "3"); attributes.put("generated", "./generated/v2"); options.setAttributes(attributes); asciidoctor.convertFile(new File(baseOutputDir + "/index.adoc"), options); }
Example #18
Source File: OptionsTest.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void convert_in_unsafe_mode() throws Exception { //tag::unsafeConversion[] File sourceFile = //end::unsafeConversion[] /* We don't want to show the reader that we're getting the document via a classpath resources instance, nor do we want to expose the filesystem structure of our build. The reader should not care where the content comes from. //tag::unsafeConversion[] new File("includingcontent.adoc"); //end::unsafeConversion[] */ classpathResources.getResource("includingcontent.adoc"); //tag::unsafeConversion[] String result = asciidoctor.convertFile( sourceFile, OptionsBuilder.options() .safe(SafeMode.UNSAFE) // <1> .toFile(false) // <2> .get()); assertThat(result, containsString("This is included content")); //end::unsafeConversion[] }
Example #19
Source File: OptionsTest.java From asciidoctorj with Apache License 2.0 | 6 votes |
@Test public void options_for_pdf_document() throws Exception { //tag::optionsPDFBackend[] File targetFile = // ... //end::optionsPDFBackend[] temporaryFolder.newFile("test.pdf"); assertTrue(targetFile.exists()); //tag::optionsPDFBackend[] asciidoctor.convert( "Hello World", OptionsBuilder.options() .backend("pdf") .toFile(targetFile) .safe(SafeMode.UNSAFE) .get()); assertThat(targetFile.length(), greaterThan(0L)); //end::optionsPDFBackend[] }
Example #20
Source File: WhenRubyExtensionIsRegistered.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test public void ruby_docinfoprocessor_should_be_registered() { final String rubyExtPath = classpath.getResource("ruby-extensions").getAbsolutePath(); final AsciidoctorJRuby asciidoctor = AsciidoctorJRuby.Factory.create(singletonList(rubyExtPath)); asciidoctor.rubyExtensionRegistry() .requireLibrary("view-result-docinfoprocessor.rb") .docinfoProcessor("ViewResultDocinfoProcessor"); String content = asciidoctor.convert( "= View Result Sample \n" + " \n" + ".This will have a link next to it\n" + "---- \n" + "* always displayed \n" + "* always displayed 2 \n" + "---- \n" + " \n" + "[.result] \n" + "==== \n" + "* hidden till clicked \n" + "* hidden till clicked 2 \n" + "==== ", options().toFile(false).safe(SafeMode.SAFE).headerFooter(true).get()); final Document document = Jsoup.parse(content); final Iterator<Element> elems = document.getElementsByTag("style").iterator(); boolean found = false; while (elems.hasNext()) { final Element styleElem = elems.next(); if (styleElem.toString().contains(".listingblock a.view-result")) { found = true; } } assertTrue("Could not find style element that should have been added by docinfo processor:\n" + document, found); }
Example #21
Source File: WhenJavaExtensionIsRegistered.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test public void a_docinfoprocessor_should_be_executed_and_add_meta_in_header_by_default() { JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.docinfoProcessor(MetaRobotsDocinfoProcessor.class.getCanonicalName()); String content = asciidoctor.convertFile( classpath.getResource("simple.adoc"), options().headerFooter(true).safe(SafeMode.SERVER).toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element metaRobots = doc.getElementsByAttributeValueContaining("name", "robots").first(); assertThat(metaRobots, is(notNullValue())); }
Example #22
Source File: WhenJavaExtensionGroupIsRegistered.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test public void a_docinfoprocessor_should_be_executed_and_add_meta_in_header_by_default() { asciidoctor.createGroup() .docinfoProcessor(MetaRobotsDocinfoProcessor.class.getCanonicalName()) .register(); String content = asciidoctor.convertFile( classpath.getResource("simple.adoc"), options().headerFooter(true).safe(SafeMode.SERVER).toFile(false).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element metaRobots = doc.getElementsByAttributeValueContaining("name", "robots").first(); assertThat(metaRobots, is(notNullValue())); }
Example #23
Source File: WhenJavaExtensionGroupIsRegistered.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test public void should_create_toc_with_treeprocessor() throws Exception { this.asciidoctor.createGroup() .treeprocessor(new Treeprocessor() { @Override public Document process(Document document) { List<StructuralNode> blocks=document.getBlocks(); for (StructuralNode block : blocks) { for (StructuralNode block2 : block.getBlocks()) { if(block2 instanceof Section) System.out.println(((Section) block2).getId()); } } return document; } }) .register(); String content = asciidoctor.convertFile( classpath.getResource("documentwithtoc.adoc"), options().headerFooter(true).toFile(false).safe(SafeMode.UNSAFE).get()); org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8"); Element toc = doc.getElementById("toc"); assertThat(toc, notNullValue()); Elements elements = toc.getElementsByAttributeValue("href", "#TestId"); assertThat(elements.size(), is(1)); }
Example #24
Source File: WhenRubyExtensionGroupIsRegistered.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test public void ruby_docinfoprocessor_should_be_registered() { final String rubyExtPath = classpath.getResource("ruby-extensions").getAbsolutePath(); final Asciidoctor asciidoctor = JRubyAsciidoctor.create(singletonList(rubyExtPath)); asciidoctor.createGroup() .requireRubyLibrary("view-result-docinfoprocessor.rb") .rubyDocinfoProcessor("ViewResultDocinfoProcessor") .register(); String content = asciidoctor.convert( "= View Result Sample \n" + " \n" + ".This will have a link next to it\n" + "---- \n" + "* always displayed \n" + "* always displayed 2 \n" + "---- \n" + " \n" + "[.result] \n" + "==== \n" + "* hidden till clicked \n" + "* hidden till clicked 2 \n" + "==== ", options().toFile(false).safe(SafeMode.SAFE).headerFooter(true).get()); final Document document = Jsoup.parse(content); final Iterator<Element> elems = document.getElementsByTag("style").iterator(); boolean found = false; while (elems.hasNext()) { final Element styleElem = elems.next(); if (styleElem.toString().contains(".listingblock a.view-result")) { found = true; } } assertTrue("Could not find style element that should have been added by docinfo processor:\n" + document, found); }
Example #25
Source File: SimpleAsciidoctorRendering.java From asciidoctorj with Apache License 2.0 | 5 votes |
public static void main(String[] args) { Asciidoctor asciidoctor = Asciidoctor.Factory.create(); // <1> asciidoctor.convertFile( // <2> new File(args[0]), OptionsBuilder.options() // <3> .toFile(true) .safe(SafeMode.UNSAFE)); }
Example #26
Source File: OrderTest.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test public void should_invoke_syntax_highlighter() throws Exception { File sources_adoc = //... classpathResources.getResource("syntax-highlighting-order.adoc"); File toDir = // ... tempDir.newFolder(); asciidoctor.syntaxHighlighterRegistry() .register(OrderDocumentingHighlighter.class, "order"); asciidoctor.convertFile(sources_adoc, OptionsBuilder.options() .headerFooter(true) .toDir(toDir) .safe(SafeMode.UNSAFE) .attributes(AttributesBuilder.attributes() .sourceHighlighter("order") .copyCss(true) .linkCss(true))); try (PrintWriter out = new PrintWriter(new FileWriter("build/resources/test/order.txt"))) { for (String msg: OrderDocumentingHighlighter.messages) { out.println(". " + msg); } } }
Example #27
Source File: WhenAsciidoctorAPICallIsCalled.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test public void api_parameters_should_be_transformed_to_cli_command() { AttributesBuilder attributesBuilder = AttributesBuilder.attributes() .attribute("myAtribute", "myValue").sectionNumbers(true) .copyCss(false); OptionsBuilder optionsBuilder = OptionsBuilder.options() .backend("docbook").templateDirs(new File("a"), new File("b")) .safe(SafeMode.UNSAFE).attributes(attributesBuilder.get()); List<String> command = AsciidoctorUtils.toAsciidoctorCommand( optionsBuilder.asMap(), "file.adoc"); String currentDirectory = new File( "" ).getAbsolutePath() + File.separator; String[] parameters = command.subList(1, command.size()).toArray(new String[0]); AsciidoctorCliOptions asciidoctorCliOptions = new AsciidoctorCliOptions(); new JCommander(asciidoctorCliOptions, parameters); assertThat(asciidoctorCliOptions.getTemplateDir(), containsInAnyOrder(currentDirectory+"a", currentDirectory+"b")); assertThat(asciidoctorCliOptions.getSafeMode(), is(SafeMode.UNSAFE)); assertThat(asciidoctorCliOptions.getBackend(), is("docbook")); assertThat(asciidoctorCliOptions.getParameters(), containsInAnyOrder("file.adoc")); assertThat(asciidoctorCliOptions.getAttributes(), hasEntry("myAtribute", (Object)"myValue")); assertThat(asciidoctorCliOptions.getAttributes(), hasKey("numbered")); assertThat(asciidoctorCliOptions.getAttributes(), hasKey("copycss!")); }
Example #28
Source File: PrismJsHighlighterTest.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test public void should_invoke_syntax_highlighter() throws Exception { //tag::include[] File sources_adoc = //... //end::include[] classpathResources.getResource("sources.adoc"); //tag::include[] File toDir = // ... //end::include[] tempDir.newFolder(); //tag::include[] //tag::include[] asciidoctor.syntaxHighlighterRegistry() .register(PrismJsHighlighter.class, "prismjs"); // <1> asciidoctor.convertFile(sources_adoc, OptionsBuilder.options() .headerFooter(true) .toDir(toDir) .safe(SafeMode.UNSAFE) .attributes(AttributesBuilder.attributes() .sourceHighlighter("prismjs") // <1> .copyCss(true) .linkCss(true))); File docFile = new File(toDir, "sources.html"); Document document = Jsoup.parse(new File(toDir, "sources.html"), "UTF-8"); Elements keywords = document.select("div.content pre.highlight code span.token.keyword"); // <2> assertThat(keywords, not(empty())); assertThat(keywords.first().text(), is("public")); //end::include[] }
Example #29
Source File: WhenJavaExtensionGroupIsRegistered.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test @Ignore public void extensions_should_be_correctly_added_using_extension_registry() throws IOException { // To avoid registering the same extension over and over for all tests, // service is instantiated manually. this.asciidoctor.createGroup() .postprocessor(ArrowsAndBoxesIncludesPostProcessor.class) .block("arrowsAndBoxes", ArrowsAndBoxesBlock.class) .register(); Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html")) .safe(SafeMode.UNSAFE).get(); asciidoctor.convertFile(classpath.getResource("arrows-and-boxes-example.ad"), options); File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8"); Element arrowsJs = doc.select("script[src=http://www.headjump.de/javascripts/arrowsandboxes.js").first(); assertThat(arrowsJs, is(notNullValue())); Element arrowsCss = doc.select("link[href=http://www.headjump.de/stylesheets/arrowsandboxes.css").first(); assertThat(arrowsCss, is(notNullValue())); Element arrowsAndBoxes = doc.select("pre[class=arrows-and-boxes").first(); assertThat(arrowsAndBoxes, is(notNullValue())); }
Example #30
Source File: HighlightJsHighlighterTest.java From asciidoctorj with Apache License 2.0 | 5 votes |
@Test public void should_invoke_stylesheet_writing_syntax_highlighter() throws Exception { File sources_adoc = classpathResources.getResource("sources.adoc"); //tag::includestylesheetwriter[] File toDir = // ... //end::includestylesheetwriter[] tempDir.newFolder(); //tag::includestylesheetwriter[] asciidoctor.syntaxHighlighterRegistry() .register(HighlightJsWithOfflineStylesHighlighter.class, "myhighlightjs"); asciidoctor.convertFile(sources_adoc, OptionsBuilder.options() .headerFooter(true) .toDir(toDir) // <1> .safe(SafeMode.UNSAFE) .attributes(AttributesBuilder.attributes() .sourceHighlighter("myhighlightjs") .copyCss(true) // <1> .linkCss(true))); File docFile = new File(toDir, "sources.html"); assertTrue(docFile.exists()); File cssFile = new File(toDir, "github.min.css"); assertTrue(cssFile.exists()); File jsFile = new File(toDir, "highlight.min.js"); assertTrue(jsFile.exists()); try (FileReader docReader = new FileReader(new File(toDir, "sources.html"))) { String html = IOUtils.toString(docReader); assertThat(html, containsString("<link rel=\"stylesheet\" href=\"github.min.css\">")); assertThat(html, containsString("<script src=\"highlight.min.js\"></script>")); } //end::includestylesheetwriter[] }