use of org.pegdown.ast.RootNode 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);
}
use of org.pegdown.ast.RootNode in project activityinfo by bedatadriven.
the class DocGenerator method renderTopics.
private static String renderTopics() throws IOException {
File contentDir = new File("clients/docs/src/main/content");
if (!contentDir.exists()) {
throw new RuntimeException("Content directory does not exist: " + contentDir.getAbsolutePath());
}
List<File> files = Arrays.asList(contentDir.listFiles());
Collections.sort(files, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return o1.getName().compareTo(o2.getName());
}
});
StringBuilder html = new StringBuilder();
for (File file : files) {
PegDownProcessor processor = new PegDownProcessor(Extensions.TABLES);
RootNode rootNode = processor.parseMarkdown(Files.asCharSource(file, Charsets.UTF_8).read().toCharArray());
MyHtmlSerializer serializer = new MyHtmlSerializer();
html.append(serializer.toHtml(rootNode));
}
return html.toString();
}
use of org.pegdown.ast.RootNode in project flexmark-java by vsch.
the class PegdownParser method parse.
@Override
public Node parse(BasedSequence input) {
// here we make the lexer parse the input sequence from start to finish and accumulate everything in custom nodes
final int pegdownExtensions = getPegdownExtensions(getOptions());
RootNode rootNode = new PegDownProcessor(pegdownExtensions).parseMarkdown(input.toString().toCharArray());
return new PegdownRootNode(rootNode);
}
use of org.pegdown.ast.RootNode in project gitblit by gitblit.
the class MarkdownUtils method transformMarkdown.
/**
* Returns the html version of the markdown source text.
*
* @param markdown
* @return html version of markdown text
* @throws java.text.ParseException
*/
public static String transformMarkdown(String markdown, LinkRenderer linkRenderer) {
try {
PegDownProcessor pd = new PegDownProcessor(ALL & ~SMARTYPANTS & ~ANCHORLINKS);
RootNode astRoot = pd.parseMarkdown(markdown.toCharArray());
return new WorkaroundHtmlSerializer(linkRenderer == null ? new LinkRenderer() : linkRenderer).toHtml(astRoot);
} catch (ParsingTimeoutException e) {
return null;
}
}
use of org.pegdown.ast.RootNode in project flexmark-java by vsch.
the class PegdownRenderer method render.
@Override
public void render(Node node, Appendable output) {
assert node instanceof PegdownParser.PegdownRootNode;
RootNode rootNode = ((PegdownParser.PegdownRootNode) node).myRootNode;
String html = mySerializer.toHtml(rootNode);
try {
output.append(html);
output.append('\n');
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations