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); } }
@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())); }
@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"))); }
@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[] }