Search in sources :

Example 1 with ToHtmlSerializer

use of org.pegdown.ToHtmlSerializer in project gerrit by GerritCodeReview.

the class MarkdownFormatter method markdownToDocHtml.

public byte[] markdownToDocHtml(String md, String charEnc) throws UnsupportedEncodingException {
    RootNode root = parseMarkdown(md);
    String title = findTitle(root);
    StringBuilder html = new StringBuilder();
    html.append("<html>");
    html.append("<head>");
    if (!Strings.isNullOrEmpty(title)) {
        html.append("<title>").append(title).append("</title>");
    }
    html.append("<style type=\"text/css\">\n");
    if (css != null) {
        html.append(css);
    } else {
        html.append(readCSS());
    }
    html.append("\n</style>");
    html.append("</head>");
    html.append("<body>\n");
    html.append(new ToHtmlSerializer(new LinkRenderer()).toHtml(root));
    html.append("\n</body></html>");
    return html.toString().getBytes(charEnc);
}
Also used : RootNode(org.pegdown.ast.RootNode) LinkRenderer(org.pegdown.LinkRenderer) ToHtmlSerializer(org.pegdown.ToHtmlSerializer)

Aggregations

LinkRenderer (org.pegdown.LinkRenderer)1 ToHtmlSerializer (org.pegdown.ToHtmlSerializer)1 RootNode (org.pegdown.ast.RootNode)1