Search in sources :

Example 6 with MutableDataSet

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

the class SyntheticLinkSample method main.

public static void main(String[] args) {
    MutableDataSet options = new MutableDataSet();
    // set optional extensions
    options.set(Parser.EXTENSIONS, Arrays.asList(SyntheticLinkExtension.create()));
    // uncomment to convert soft-breaks to hard breaks
    // options.set(HtmlRenderer.SOFT_BREAK, "<br />\n");
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    // You can re-use parser and renderer instances
    Node document = parser.parse("Some markdown content");
    String html = renderer.render(document);
    System.out.println(html);
}
Also used : HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet) Parser(com.vladsch.flexmark.parser.Parser)

Example 7 with MutableDataSet

use of com.vladsch.flexmark.util.options.MutableDataSet in project jspwiki by apache.

the class MarkdownDocument method options.

/**
 * configuration options for MarkdownRenderers.
 *
 * @param context current wikicontext
 * @return configuration options for MarkdownRenderers.
 */
public static MutableDataSet options(final WikiContext context) {
    MutableDataSet options = new MutableDataSet();
    options.setFrom(ParserEmulationProfile.COMMONMARK);
    // align style of Markdown's footnotes extension with jspwiki footnotes refs
    options.set(FootnoteExtension.FOOTNOTE_LINK_REF_CLASS, JSPWikiMarkupParser.CLASS_FOOTNOTE_REF);
    options.set(Parser.EXTENSIONS, Arrays.asList(new Extension[] { new MarkdownForJSPWikiExtension(context), FootnoteExtension.create(), TocExtension.create() }));
    return options;
}
Also used : TocExtension(com.vladsch.flexmark.ext.toc.TocExtension) FootnoteExtension(com.vladsch.flexmark.ext.footnotes.FootnoteExtension) MarkdownForJSPWikiExtension(org.apache.wiki.markdown.MarkdownForJSPWikiExtension) Extension(com.vladsch.flexmark.Extension) MarkdownForJSPWikiExtension(org.apache.wiki.markdown.MarkdownForJSPWikiExtension) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet)

Example 8 with MutableDataSet

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

the class PegdownOptionsAdapter method getFlexmarkOptions.

public DataHolder getFlexmarkOptions(boolean strictHtml, Extension... additionalExtensions) {
    if (myIsUpdateNeeded) {
        myIsUpdateNeeded = false;
        MutableDataSet options = myOptions;
        ArrayList<Extension> extensions = new ArrayList<Extension>();
        options.clear();
        // add this for extension use if needed
        options.set(PEGDOWN_EXTENSIONS, myPegdownExtensions);
        extensions.addAll(Arrays.asList(additionalExtensions));
        // Setup List Options for Fixed List Indent profile
        options.setFrom(strictHtml ? ParserEmulationProfile.PEGDOWN_STRICT : ParserEmulationProfile.PEGDOWN);
        options.set(HtmlRenderer.SUPPRESS_HTML_BLOCKS, haveExtensions(SUPPRESS_HTML_BLOCKS));
        options.set(HtmlRenderer.SUPPRESS_INLINE_HTML, haveExtensions(SUPPRESS_INLINE_HTML));
        // add default extensions in pegdown
        extensions.add(EscapedCharacterExtension.create());
        if (haveExtensions(ABBREVIATIONS)) {
            extensions.add(AbbreviationExtension.create());
            options.set(AbbreviationExtension.ABBREVIATIONS_KEEP, KeepType.LAST);
        }
        if (haveExtensions(ANCHORLINKS | EXTANCHORLINKS)) {
            options.set(HtmlRenderer.RENDER_HEADER_ID, false);
            extensions.add(AnchorLinkExtension.create());
            if (haveExtensions(EXTANCHORLINKS)) {
                options.set(AnchorLinkExtension.ANCHORLINKS_WRAP_TEXT, false);
            } else if (haveExtensions(ANCHORLINKS)) {
                options.set(AnchorLinkExtension.ANCHORLINKS_WRAP_TEXT, true);
            }
        }
        if (haveExtensions(AUTOLINKS)) {
            extensions.add(AutolinkExtension.create());
        }
        if (haveExtensions(DEFINITIONS)) {
            // not implemented yet, but have placeholder
            extensions.add(DefinitionExtension.create());
        }
        if (!haveExtensions(FENCED_CODE_BLOCKS)) {
            // disable fenced code blocks
            options.set(Parser.FENCED_CODE_BLOCK_PARSER, false);
        } else {
            options.set(Parser.MATCH_CLOSING_FENCE_CHARACTERS, false);
        }
        if (haveExtensions(FORCELISTITEMPARA)) {
            // first item is loose if second item is loose
            options.set(Parser.LISTS_LOOSE_WHEN_HAS_NON_LIST_CHILDREN, true);
        } else {
        // should already be set
        }
        if (haveExtensions(HARDWRAPS)) {
            options.set(HtmlRenderer.SOFT_BREAK, "<br />\n");
            options.set(HtmlRenderer.HARD_BREAK, "<br />\n");
        }
        if (!haveExtensions(ATXHEADERSPACE)) {
            options.set(Parser.HEADING_NO_ATX_SPACE, true);
        }
        if (haveExtensions(QUOTES | SMARTS)) {
            // not implemented yet, have placeholder
            extensions.add(TypographicExtension.create());
            options.set(TypographicExtension.ENABLE_SMARTS, haveExtensions(SMARTS));
            options.set(TypographicExtension.ENABLE_QUOTES, haveExtensions(QUOTES));
        }
        if (!haveExtensions(RELAXEDHRULES)) {
            options.set(Parser.THEMATIC_BREAK_RELAXED_START, false);
        }
        if (haveExtensions(TABLES)) {
            extensions.add(TablesExtension.create());
            options.set(TablesExtension.TRIM_CELL_WHITESPACE, false);
            options.set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, false);
        }
        if (haveExtensions(TASKLISTITEMS)) {
            extensions.add(TaskListExtension.create());
        }
        if (haveExtensions(WIKILINKS)) {
            extensions.add(WikiLinkExtension.create());
            // pegdown does not have an option for selecting Creole or GitHub wiki link syntax: Creole puts page ref first, link text second, GitHub the other way around
            options.set(WikiLinkExtension.LINK_FIRST_SYNTAX, false);
        }
        if (haveExtensions(SUBSCRIPT) && haveExtensions(STRIKETHROUGH)) {
            // first item is loose if second item is loose
            extensions.add(StrikethroughSubscriptExtension.create());
        } else if (haveExtensions(STRIKETHROUGH)) {
            extensions.add(StrikethroughExtension.create());
        } else if (haveExtensions(SUBSCRIPT)) {
            extensions.add(SubscriptExtension.create());
        }
        if (haveExtensions(SUPERSCRIPT)) {
            extensions.add(SuperscriptExtension.create());
        }
        if (haveExtensions(INSERTED)) {
            extensions.add(InsExtension.create());
        }
        if (haveExtensions(TOC)) {
            extensions.add(SimTocExtension.create());
            options.set(TocExtension.BLANK_LINE_SPACER, true);
            extensions.add(TocExtension.create());
            options.set(TocExtension.LEVELS, TocOptions.getLevels(2, 3));
        }
        if (haveExtensions(MULTI_LINE_IMAGE_URLS)) {
            options.set(Parser.PARSE_MULTI_LINE_IMAGE_URLS, true);
        }
        if (haveExtensions(FOOTNOTES)) {
            extensions.add(FootnoteExtension.create());
            options.set(FootnoteExtension.FOOTNOTES_KEEP, KeepType.LAST);
        }
        myOptions.set(Parser.EXTENSIONS, extensions);
    }
    return myOptions.toImmutable();
}
Also used : AbbreviationExtension(com.vladsch.flexmark.ext.abbreviation.AbbreviationExtension) AnchorLinkExtension(com.vladsch.flexmark.ext.anchorlink.AnchorLinkExtension) SubscriptExtension(com.vladsch.flexmark.ext.gfm.strikethrough.SubscriptExtension) SimTocExtension(com.vladsch.flexmark.ext.toc.SimTocExtension) InsExtension(com.vladsch.flexmark.ext.ins.InsExtension) WikiLinkExtension(com.vladsch.flexmark.ext.wikilink.WikiLinkExtension) StrikethroughSubscriptExtension(com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughSubscriptExtension) StrikethroughExtension(com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension) Extension(com.vladsch.flexmark.Extension) AutolinkExtension(com.vladsch.flexmark.ext.autolink.AutolinkExtension) TypographicExtension(com.vladsch.flexmark.ext.typographic.TypographicExtension) TocExtension(com.vladsch.flexmark.ext.toc.TocExtension) DefinitionExtension(com.vladsch.flexmark.ext.definition.DefinitionExtension) FootnoteExtension(com.vladsch.flexmark.ext.footnotes.FootnoteExtension) TaskListExtension(com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension) EscapedCharacterExtension(com.vladsch.flexmark.ext.escaped.character.EscapedCharacterExtension) SuperscriptExtension(com.vladsch.flexmark.superscript.SuperscriptExtension) TablesExtension(com.vladsch.flexmark.ext.tables.TablesExtension) ArrayList(java.util.ArrayList) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet)

Example 9 with MutableDataSet

use of com.vladsch.flexmark.util.options.MutableDataSet 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 10 with MutableDataSet

use of com.vladsch.flexmark.util.options.MutableDataSet 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

MutableDataSet (com.vladsch.flexmark.util.options.MutableDataSet)20 Parser (com.vladsch.flexmark.parser.Parser)17 HtmlRenderer (com.vladsch.flexmark.html.HtmlRenderer)15 Node (com.vladsch.flexmark.ast.Node)14 MutableDataHolder (com.vladsch.flexmark.util.options.MutableDataHolder)6 Extension (com.vladsch.flexmark.Extension)4 AutolinkExtension (com.vladsch.flexmark.ext.autolink.AutolinkExtension)2 FootnoteExtension (com.vladsch.flexmark.ext.footnotes.FootnoteExtension)2 TocExtension (com.vladsch.flexmark.ext.toc.TocExtension)2 DataHolder (com.vladsch.flexmark.util.options.DataHolder)2 Test (org.junit.Test)2 Document (com.vladsch.flexmark.ast.Document)1 TextCollectingVisitor (com.vladsch.flexmark.ast.util.TextCollectingVisitor)1 AbbreviationExtension (com.vladsch.flexmark.ext.abbreviation.AbbreviationExtension)1 AnchorLinkExtension (com.vladsch.flexmark.ext.anchorlink.AnchorLinkExtension)1 DefinitionExtension (com.vladsch.flexmark.ext.definition.DefinitionExtension)1 EscapedCharacterExtension (com.vladsch.flexmark.ext.escaped.character.EscapedCharacterExtension)1 StrikethroughExtension (com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension)1 StrikethroughSubscriptExtension (com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughSubscriptExtension)1 SubscriptExtension (com.vladsch.flexmark.ext.gfm.strikethrough.SubscriptExtension)1