static void runAsciiDoctor(Asciidoctor asciidoctor, Path srcPath, String courseName, Path destPath, PrintWriter err) throws IOException { Path courseDestDir = destPath.resolve(courseName); Attributes attributes = attributes() .tableOfContents(true) .tableOfContents(Placement.LEFT) .attribute("toc-title", courseName) .attribute("numbered", true) .attribute("verbose", true) .attribute("linkcss", "true") .attribute("stylesheet", "../css/style.css") .get(); Options options = options() .safe(SafeMode.UNSAFE) .attributes(attributes) .docType("book") .destinationDir(new File(courseDestDir.toString())) .baseDir(new File(courseDestDir.toString())) .toFile(courseIndexFile(courseDestDir)) .get(); asciidoctor.convertFile(new File(courseADocFile(courseName, courseDestDir).toString()), options); }
@Override public String convertAsciiDocToXHtml(final String asciiDoc) { LOG.info("Converting AsciiDoc to XHTML5..."); final Asciidoctor asciidoctor = create(); final Map<String, Object> attributes = AttributesBuilder.attributes() .unsetStyleSheet() .tableOfContents(Placement.TOP) .asMap(); final Map<String, Object> options = OptionsBuilder.options() .attributes(attributes) .backend("xhtml5") .asMap(); LOG.info("XHTML5 Conversion Complete!"); return asciidoctor.render(asciiDoc, options); }
@Test public void unsetting_toc_attribute_table_of_contents_should_not_be_generated() { Attributes attributes = attributes().tableOfContents(false).get(); Options options = options().toFile(false).attributes(attributes).get(); String renderContent = asciidoctor.convertFile( classpath.getResource("tocsample.asciidoc"), options); Document doc = Jsoup.parse(renderContent, "UTF-8"); Elements tocElement = doc.select("div.toc"); assertThat(tocElement.hasClass("toc"), is(false)); }
@Test public void setting_toc_attribute_table_of_contents_should_be_generated() throws IOException { Attributes attributes = attributes().tableOfContents(true).get(); Options options = options().inPlace(false).toDir(testFolder.getRoot()).safe(SafeMode.UNSAFE).attributes(attributes).get(); asciidoctor.convertFile(classpath.getResource("tocsample.asciidoc"), options); Document doc = Jsoup.parse(new File(testFolder.getRoot(), "tocsample.html"), "UTF-8"); Elements tocElement = doc.select("div.toc"); assertThat(tocElement.hasClass("toc"), is(true)); }
@Test public void table_of_content_should_be_placeable() throws IOException { Attributes attributes = attributes().tableOfContents(Placement.RIGHT).get(); Options options = options().inPlace(false) .toFile(new File(testFolder.getRoot(), "toc2sample.html")) .safe(SafeMode.UNSAFE).attributes(attributes).get(); asciidoctor.convertFile(classpath.getResource("toc2sample.asciidoc"), options); File renderedFile = new File(testFolder.getRoot(), "toc2sample.html"); Document doc = Jsoup.parse(renderedFile, "UTF-8"); Elements body = doc.select("body"); String classAttribute = body.attr("class"); String[] classAttributes = classAttribute.split(" "); assertThat(classAttributes, hasItemInArray("toc2")); assertThat(classAttributes, hasItemInArray("toc-right")); renderedFile.delete(); }