Java源码示例:org.commonmark.renderer.html.HtmlWriter

示例1
@Override
public void render(Node node) {

    HtmlWriter html = context.getWriter();
    FencedCodeBlock codeBlock = (FencedCodeBlock) node;
    Map<String,String> attrs = new HashMap<>();
    if (!StringUtils.isEmpty(codeBlock.getInfo())) {
        attrs.put("class","language-" + codeBlock.getInfo());
    }
    html.line();
    html.tag("pre");
    html.tag("code",attrs);
    html.tag("ol");
    String data = codeBlock.getLiteral();
    String[] split = data.split("\n");
    for (String s : split) {
        html.tag("li");
        html.text(s + "\n");
        html.tag("/li");
    }
    html.tag("/ol");
    html.tag("/code");
    html.tag("/pre");
    html.line();

}
 
示例2
@Override
public void render(Node node) {

    HtmlWriter html = context.getWriter();

    Image image = (Image) node;
    Map<String,String> attrs = new HashMap<>();
    Map<String,String> attrs2 = new HashMap<>();
    attrs.put("href",image.getDestination());
    attrs2.put("src",image.getDestination());
    html.line();
    html.tag("a",attrs);
    html.tag("image",attrs2);
    html.tag("/a");
    html.line();
}
 
示例3
private void renderBlock(Node node, String tagName) {
  HtmlWriter writer = context.getWriter();
  writer.line();
  writer.tag(tagName);
  renderChildren(node);
  writer.tag("/" + tagName);
  writer.line();
}