Package org.jbake.parser

Source Code of org.jbake.parser.MarkdownEngine

package org.jbake.parser;

import org.pegdown.Extensions;
import org.pegdown.PegDownProcessor;

/**
* Renders documents in the Markdown format.
*
* @author Cédric Champeau
*/
public class MarkdownEngine extends MarkupEngine {

    public MarkdownEngine() {
        Class engineClass = PegDownProcessor.class;
        assert engineClass!=null;
    }

    @Override
    public void processBody(final ParserContext context) {
        String[] mdExts = context.getConfig().getStringArray("markdown.extensions");

        int extensions = Extensions.NONE;
        if (mdExts.length > 0) {
            for (int index = 0; index < mdExts.length; index++) {
                if (mdExts[index].equals("HARDWRAPS")) {
                    extensions |= Extensions.HARDWRAPS;
                } else if (mdExts[index].equals("AUTOLINKS")) {
                    extensions |= Extensions.AUTOLINKS;
                } else if (mdExts[index].equals("FENCED_CODE_BLOCKS")) {
                    extensions |= Extensions.FENCED_CODE_BLOCKS;
                } else if (mdExts[index].equals("DEFINITIONS")) {
                    extensions |= Extensions.DEFINITIONS;
                } else if (mdExts[index].equals("ABBREVIATIONS")) {
                    extensions |= Extensions.ABBREVIATIONS;
                } else if (mdExts[index].equals("QUOTES")) {
                    extensions |= Extensions.QUOTES;
                } else if (mdExts[index].equals("SMARTS")) {
                    extensions |= Extensions.SMARTS;
                } else if (mdExts[index].equals("SMARTYPANTS")) {
                    extensions |= Extensions.SMARTYPANTS;
                } else if (mdExts[index].equals("SUPPRESS_ALL_HTML")) {
                    extensions |= Extensions.SUPPRESS_ALL_HTML;
                } else if (mdExts[index].equals("SUPPRESS_HTML_BLOCKS")) {
                    extensions |= Extensions.SUPPRESS_HTML_BLOCKS;
                } else if (mdExts[index].equals("SUPPRESS_INLINE_HTML")) {
                    extensions |= Extensions.SUPPRESS_INLINE_HTML;
                } else if (mdExts[index].equals("TABLES")) {
                    extensions |= Extensions.TABLES;
                } else if (mdExts[index].equals("WIKILINKS")) {
                    extensions |= Extensions.WIKILINKS;
                } else if (mdExts[index].equals("ALL")) {
                    extensions = Extensions.ALL;
                }
            }

        }
       
        long maxParsingTime = context.getConfig().getLong("markdown.maxParsingTimeInMillis", PegDownProcessor.DEFAULT_MAX_PARSING_TIME);
       
        PegDownProcessor pegdownProcessor = new PegDownProcessor(extensions, maxParsingTime);
        context.setBody(pegdownProcessor.markdownToHtml(context.getBody()));
    }
}
TOP

Related Classes of org.jbake.parser.MarkdownEngine

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.