/** * Sets attributes used for rendering input. * * @param attributes * builder. * @return this instance. */ public OptionsBuilder attributes(AttributesBuilder attributes) { this.options.setAttributes(attributes.asMap()); return this; }
/** * Sets attributes used for rendering input. * * @param attributes * builder. * @return this instance. */ public OptionsBuilder attributes(AttributesBuilder attributes) { this.options.setAttributes(attributes.asMap()); return this; }
@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 string_content_with_custom_time_should_be_rendered() throws IOException, SAXException, ParserConfigurationException { InputStream content = new FileInputStream(classpath.getResource("documentwithtime.asciidoc")); Calendar customTime = Calendar.getInstance(); customTime.set(Calendar.HOUR_OF_DAY, 23); customTime.set(Calendar.MINUTE, 15); customTime.set(Calendar.SECOND, 0); Map<String, Object> attributes = attributes().localTime(customTime.getTime()).asMap(); Map<String, Object> options = options().attributes(attributes).asMap(); String render_file = asciidoctor.convert(toString(content), options); Format TIME_FORMAT = new SimpleDateFormat("HH:mm:ss z"); assertRenderedLocalDateContent(render_file, TIME_FORMAT.format(customTime.getTime()) + "."); }
@Test public void docbook_document_should_be_rendered_into_current_directory() throws FileNotFoundException, IOException, SAXException, ParserConfigurationException { Map<String, Object> attributes = attributes().backend("docbook").asMap(); Map<String, Object> options = options().inPlace(true).attributes(attributes).asMap(); File inputFile = classpath.getResource("rendersample.asciidoc"); String renderContent = asciidoctor.convertFile(inputFile, options); File expectedFile = new File(inputFile.getParent(), "rendersample.xml"); assertThat(expectedFile.exists(), is(true)); assertThat(renderContent, is(nullValue())); expectedFile.delete(); }
@Test public void string_content_with_custom_date_should_be_rendered() throws IOException, SAXException, ParserConfigurationException { InputStream content = new FileInputStream(classpath.getResource("documentwithdate.asciidoc")); Calendar customDate = Calendar.getInstance(); customDate.set(Calendar.YEAR, 2012); customDate.set(Calendar.MONTH, 11); customDate.set(Calendar.DATE, 5); Map<String, Object> attributes = attributes().localDate(customDate.getTime()).asMap(); Map<String, Object> options = options().attributes(attributes).asMap(); String render_file = asciidoctor.convert(toString(content), options); assertRenderedLocalDateContent(render_file, "2012-12-05."); }
@Test public void string_content_with_icons_enabled_and_iconsdir_set_should_be_rendered_with_iconsdir() throws IOException, SAXException, ParserConfigurationException { InputStream content = new FileInputStream( classpath.getResource("documentwithnote.asciidoc")); Map<String, Object> attributes = attributes() .icons(Attributes.IMAGE_ICONS).iconsDir("icons").asMap(); Map<String, Object> options = options().attributes(attributes).asMap(); String renderContent = asciidoctor.convert(toString(content), options); Document doc = Jsoup.parse(renderContent, "UTF-8"); Elements image = doc.select("img[src]"); String srcValue = image.attr("src"); assertThat(srcValue, is("icons/note.png")); }
@Test public void string_content_with_icons_enabled_should_be_rendered() throws IOException, SAXException, ParserConfigurationException { InputStream content = new FileInputStream( classpath.getResource("documentwithnote.asciidoc")); Map<String, Object> attributes = attributes().icons( Attributes.IMAGE_ICONS).asMap(); Map<String, Object> options = options().attributes(attributes).asMap(); String result = asciidoctor.convert(toString(content), options); result = result.replaceAll("<img(.*?)>", "<img$1/>"); assertRenderedAdmonitionIcon(result); }
@Test public void string_content_with_fontawesome_icons_enabled_should_be_rendered() throws IOException, SAXException, ParserConfigurationException { InputStream content = new FileInputStream( classpath.getResource("documentwithnote.asciidoc")); Map<String, Object> attributes = attributes().icons( Attributes.FONT_ICONS).asMap(); Map<String, Object> options = options().attributes(attributes).asMap(); String result = asciidoctor.convert(toString(content), options); assertRenderedFontAwesomeAdmonitionIcon(result); }