Search in sources :

Example 1 with MutableDataHolder

use of com.vladsch.flexmark.util.options.MutableDataHolder in project flexmark-java by vsch.

the class JekyllIncludeFileSample method commonMark.

static String commonMark(String markdown, Map<String, String> included) {
    MutableDataHolder options = new MutableDataSet();
    options.set(Parser.EXTENSIONS, Arrays.asList(AutolinkExtension.create(), JekyllTagExtension.create()));
    // change soft break to hard break
    options.set(HtmlRenderer.SOFT_BREAK, "<br/>");
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    Node document = parser.parse(markdown);
    // see if document has includes
    if (document instanceof Document) {
        Document doc = (Document) document;
        if (doc.contains(JekyllTagExtension.TAG_LIST)) {
            List<JekyllTag> tagList = JekyllTagExtension.TAG_LIST.getFrom(doc);
            Map<String, String> includeHtmlMap = new HashMap<String, String>();
            for (JekyllTag tag : tagList) {
                String includeFile = tag.getParameters().toString();
                if (tag.getTag().equals("include") && !includeFile.isEmpty() && !includeHtmlMap.containsKey(includeFile)) {
                    // see if it exists
                    if (included.containsKey(includeFile)) {
                        // have the file
                        String text = included.get(includeFile);
                        if (includeFile.endsWith(".md")) {
                            Node includeDoc = parser.parse(text);
                            String includeHtml = renderer.render(includeDoc);
                            includeHtmlMap.put(includeFile, includeHtml);
                            if (includeDoc instanceof Document) {
                                // copy any definition of reference elements from included file to our document
                                parser.transferReferences(doc, (Document) includeDoc);
                            }
                        } else {
                            includeHtmlMap.put(includeFile, text);
                        }
                    }
                }
                if (!includeHtmlMap.isEmpty()) {
                    doc.set(JekyllTagExtension.INCLUDED_HTML, includeHtmlMap);
                }
            }
        }
    }
    final String html = renderer.render(document);
    return html;
}
Also used : MutableDataHolder(com.vladsch.flexmark.util.options.MutableDataHolder) HashMap(java.util.HashMap) Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) JekyllTag(com.vladsch.flexmark.ext.jekyll.tag.JekyllTag) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet) Document(com.vladsch.flexmark.ast.Document) Parser(com.vladsch.flexmark.parser.Parser)

Example 2 with MutableDataHolder

use of com.vladsch.flexmark.util.options.MutableDataHolder in project flexmark-java by vsch.

the class NodeRendererSample method commonMark.

static String commonMark(String markdown) {
    MutableDataHolder options = new MutableDataSet();
    options.set(Parser.EXTENSIONS, Arrays.asList(AutolinkExtension.create(), SampleExtension.create()));
    // change soft break to hard break
    options.set(HtmlRenderer.SOFT_BREAK, "<br/>");
    options.set(HtmlRenderer.ESCAPE_HTML, true);
    Parser parser = Parser.builder(options).build();
    Node document = parser.parse(markdown);
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    final String html = renderer.render(document);
    return html;
}
Also used : MutableDataHolder(com.vladsch.flexmark.util.options.MutableDataHolder) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet) Parser(com.vladsch.flexmark.parser.Parser)

Example 3 with MutableDataHolder

use of com.vladsch.flexmark.util.options.MutableDataHolder in project flexmark-java by vsch.

the class PegdownOptions2 method main.

public static void main(String[] args) {
    final MutableDataHolder OPTIONS = PegdownOptionsAdapter.flexmarkOptions(Extensions.ALL - (headerLinks ? 0 : Extensions.ANCHORLINKS) - (hardwrap ? 0 : Extensions.HARDWRAPS) + (allowHtml ? 0 : Extensions.SUPPRESS_ALL_HTML)).toMutable();
    final Parser PARSER = Parser.builder(OPTIONS).build();
    final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
    String input = "[[test page]]" + "";
    Node node = PARSER.parse(input);
    System.out.println(RENDERER.render(node));
}
Also used : MutableDataHolder(com.vladsch.flexmark.util.options.MutableDataHolder) Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Parser(com.vladsch.flexmark.parser.Parser)

Example 4 with MutableDataHolder

use of com.vladsch.flexmark.util.options.MutableDataHolder in project flexmark-java by vsch.

the class AttributeProviderSample method commonMark.

static String commonMark(String markdown) {
    MutableDataHolder options = new MutableDataSet();
    options.set(Parser.EXTENSIONS, Arrays.asList(new Extension[] { AutolinkExtension.create(), SampleExtension.create() }));
    // change soft break to hard break
    options.set(HtmlRenderer.SOFT_BREAK, "<br/>");
    Parser parser = Parser.builder(options).build();
    Node document = parser.parse(markdown);
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    final String html = renderer.render(document);
    return html;
}
Also used : Extension(com.vladsch.flexmark.Extension) AutolinkExtension(com.vladsch.flexmark.ext.autolink.AutolinkExtension) MutableDataHolder(com.vladsch.flexmark.util.options.MutableDataHolder) Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet) Parser(com.vladsch.flexmark.parser.Parser)

Example 5 with MutableDataHolder

use of com.vladsch.flexmark.util.options.MutableDataHolder in project flexmark-java by vsch.

the class AttributeProviderSample2 method commonMark.

static String commonMark(String markdown) {
    MutableDataHolder options = new MutableDataSet();
    options.set(Parser.EXTENSIONS, Arrays.asList(new Extension[] { SampleExtension.create() }));
    // change soft break to hard break
    options.set(HtmlRenderer.SOFT_BREAK, "<br/>");
    Parser parser = Parser.builder(options).build();
    Node document = parser.parse(markdown);
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    final String html = renderer.render(document);
    return html;
}
Also used : Extension(com.vladsch.flexmark.Extension) MutableDataHolder(com.vladsch.flexmark.util.options.MutableDataHolder) Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet) Parser(com.vladsch.flexmark.parser.Parser)

Aggregations

Parser (com.vladsch.flexmark.parser.Parser)7 MutableDataHolder (com.vladsch.flexmark.util.options.MutableDataHolder)7 HtmlRenderer (com.vladsch.flexmark.html.HtmlRenderer)6 MutableDataSet (com.vladsch.flexmark.util.options.MutableDataSet)6 Node (com.vladsch.flexmark.ast.Node)5 Extension (com.vladsch.flexmark.Extension)2 Document (com.vladsch.flexmark.ast.Document)1 AutolinkExtension (com.vladsch.flexmark.ext.autolink.AutolinkExtension)1 JekyllTag (com.vladsch.flexmark.ext.jekyll.tag.JekyllTag)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1