@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 iconfont_attributes_should_be_used_for_using_custom_font_css_icons() throws URISyntaxException, IOException { Attributes attributes = attributes().icons(Attributes.FONT_ICONS) .iconFontRemote(true).iconFontCdn(new URI("http://mycdn/css/font-awesome.min.css")).get(); Options options = options().inPlace(true).attributes(attributes).get(); File inputFile = classpath.getResource("documentwithnote.asciidoc"); asciidoctor.convertFile(inputFile, options); File expectedFile = new File(inputFile.getParent(), "documentwithnote.html"); Document doc = Jsoup.parse(expectedFile, "UTF-8"); Elements stylesheetLinks = doc .select("link[href=http://mycdn/css/font-awesome.min.css]"); assertThat(stylesheetLinks.size(), is(1)); expectedFile.delete(); }
@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); }
@Test public void should_be_able_to_get_icon_uri() { Map<String, Object> options = OptionsBuilder.options().safe(SafeMode.SAFE) .attributes(AttributesBuilder.attributes().dataUri(true).icons("font")) .compact(true).asMap(); Document document = asciidoctor.load(DOCUMENT, options); assertThat(document.iconUri("note"), either( is("data:image/png:base64,") // <= Asciidoctor 1.5.5 ) .or(is("data:image/png;base64,"))); // >= Asciidoctor 1.5.6 }
@Test public void use_font_awesome_icons() throws Exception { //tag::attributeFontIcons[] String result = asciidoctor.convert( "NOTE: Asciidoctor supports font-based admonition icons!\n" + "\n" + "{foo}", OptionsBuilder.options() .toFile(false) .headerFooter(false) .attributes( AttributesBuilder.attributes() // <1> .icons(Attributes.FONT_ICONS) // <2> .attribute("foo", "bar") // <3> .get()) .get()); assertThat(result, containsString("<i class=\"fa icon-note\" title=\"Note\"></i>")); assertThat(result, containsString("<p>bar</p>")); //end::attributeFontIcons[] }