Merge "Allow to suppress HTML when converting Markdown to HTML"

This commit is contained in:
Edwin Kempin 2014-09-08 14:21:29 +00:00 committed by Gerrit Code Review
commit 7d76f7d348

View File

@ -16,6 +16,7 @@ package com.google.gerrit.server.documentation;
import static org.pegdown.Extensions.ALL;
import static org.pegdown.Extensions.HARDWRAPS;
import static org.pegdown.Extensions.SUPPRESS_ALL_HTML;
import com.google.common.base.Strings;
@ -69,6 +70,13 @@ public class MarkdownFormatter {
}
}
private boolean suppressHtml;
public MarkdownFormatter suppressHtml() {
suppressHtml = true;
return this;
}
public byte[] markdownToDocHtml(String md, String charEnc)
throws UnsupportedEncodingException {
RootNode root = parseMarkdown(md);
@ -121,7 +129,11 @@ public class MarkdownFormatter {
}
private RootNode parseMarkdown(String md) {
return new PegDownProcessor(ALL & ~(HARDWRAPS))
int options = ALL & ~(HARDWRAPS);
if (suppressHtml) {
options |= SUPPRESS_ALL_HTML;
}
return new PegDownProcessor(options)
.parseMarkdown(md.toCharArray());
}