HtmlSerializer extends ToHtmlSerializer { @Override protected void printImageTag(SuperNode imageNode, String url) { String params = StringUtils.EMPTY; if (url.contains("|")) { params = StringUtils.substringAfter(url, "|").trim(); url = StringUtils.substringBefore(url, "|").trim(); } boolean thumbnail = params.contains(IMAGE_PARAM_THUMB); String altText = printChildrenToString(imageNode); String title = null; if (imageNode instanceof ExpImageNode) { title = StringUtils.defaultIfBlank(((ExpImageNode) imageNode).title, altText); } if (thumbnail) { printer.print("<ul class=\"thumbnails\"><li class=\"span3\"><a class=\"thumbnail\" href=\"") .print(context.getAttachmentUri(url)).print("\">"); } printer.print("<img src=\"").print(context.getAttachmentUri(url)).print("\""); if (StringUtils.isNotBlank(altText)) { printer.print(" alt=\"").printEncoded(altText).print("\""); } if (thumbnail) { printer.print(" data-lightbox=\"lightbox\" width=\"260\""); } if (StringUtils.isNotBlank(title)) { printer.print(" rel=\"tooltip\" data-title=\"").printEncoded(title).print("\""); } printer.print("/>"); if (thumbnail) { printer.print("</a></li></ul>"); } } HtmlSerializer(HtmlSerializerContext context); @Override void visit(ParaNode node); @Override void visit(VerbatimNode node); @Override void visit(HeaderNode node); @Override void visit(BulletListNode node); @Override void visit(OrderedListNode node); @Override void visit(DefinitionListNode node); @Override void visit(SuperNode node);  }
@Test public void printImageTag() { when(context.getAttachmentUri("url")).thenReturn("/foo.png"); RefImageNode node = new RefImageNode( new SuperNode(new TextNode("foo.png")), null, new TextNode(StringUtils.EMPTY)); RootNode rootNode = root(node); ReferenceNode refNode = new ReferenceNode(new TextNode("foo.png")); refNode.setUrl("url"); rootNode.setReferences(Lists.newArrayList(refNode)); String html = htmlSerializer.toHtml(rootNode); assertEquals("<img src=\"/foo.png\"/>", html); }