Search in sources :

Example 1 with RootNode

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);
}
Also used : RootNode(org.pegdown.ast.RootNode) LinkRenderer(org.pegdown.LinkRenderer) ToHtmlSerializer(org.pegdown.ToHtmlSerializer)

Example 2 with RootNode

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();
}
Also used : RootNode(org.pegdown.ast.RootNode) PegDownProcessor(org.pegdown.PegDownProcessor) File(java.io.File)

Example 3 with RootNode

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);
}
Also used : RootNode(org.pegdown.ast.RootNode) PegDownProcessor(org.pegdown.PegDownProcessor)

Example 4 with 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;
    }
}
Also used : RootNode(org.pegdown.ast.RootNode) LinkRenderer(org.pegdown.LinkRenderer) WorkaroundHtmlSerializer(com.gitblit.wicket.MarkupProcessor.WorkaroundHtmlSerializer) ParsingTimeoutException(org.pegdown.ParsingTimeoutException) PegDownProcessor(org.pegdown.PegDownProcessor)

Example 5 with RootNode

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();
    }
}
Also used : RootNode(org.pegdown.ast.RootNode) IOException(java.io.IOException)

Aggregations

RootNode (org.pegdown.ast.RootNode)5 PegDownProcessor (org.pegdown.PegDownProcessor)3 LinkRenderer (org.pegdown.LinkRenderer)2 WorkaroundHtmlSerializer (com.gitblit.wicket.MarkupProcessor.WorkaroundHtmlSerializer)1 File (java.io.File)1 IOException (java.io.IOException)1 ParsingTimeoutException (org.pegdown.ParsingTimeoutException)1 ToHtmlSerializer (org.pegdown.ToHtmlSerializer)1