Search in sources :

Example 11 with MutableDataSet

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

the class BasicSample method main.

public static void main(String[] args) {
    MutableDataSet options = new MutableDataSet();
    // uncomment to set optional extensions
    // options.set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), StrikethroughExtension.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("This is *Sparta*");
    // "<p>This is <em>Sparta</em></p>\n"
    String html = renderer.render(document);
    System.out.println(html);
}
Also used : 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 12 with MutableDataSet

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

the class XWikiMacrosSample method main.

public static void main(String[] args) {
    MutableDataHolder options = new MutableDataSet();
    options.set(Parser.EXTENSIONS, Arrays.asList(MacroExtension.create()));
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    String markdown = "markdown content here";
    Node document = parser.parse(markdown);
    XWikiMacrosSample macroProcessor = new XWikiMacrosSample();
    macroProcessor.visitor.visitChildren(document);
}
Also used : 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 13 with MutableDataSet

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

the class ProfileEmulationFamilySamples method gitHub.

void gitHub() {
    MutableDataSet options = new MutableDataSet();
    options.setFrom(ParserEmulationProfile.GITHUB_DOC);
    options.set(Parser.EXTENSIONS, Arrays.asList(AutolinkExtension.create(), // EmojiExtension.create(),
    StrikethroughExtension.create(), TablesExtension.create(), TaskListExtension.create()));
    // uncomment and define location of emoji images from https://github.com/arvida/emoji-cheat-sheet.com
    // options.set(EmojiExtension.ROOT_IMAGE_PATH, "");
    // Uncomment if GFM anchor links are desired in headings
    // options.set(AnchorLinkExtension.ANCHORLINKS_SET_ID, false);
    // options.set(AnchorLinkExtension.ANCHORLINKS_ANCHOR_CLASS, "anchor");
    // options.set(AnchorLinkExtension.ANCHORLINKS_SET_NAME, true);
    // options.set(AnchorLinkExtension.ANCHORLINKS_TEXT_PREFIX, "<span class=\"octicon octicon-link\"></span>");
    // References compatibility
    options.set(Parser.REFERENCES_KEEP, KeepType.LAST);
    // Set GFM table parsing options
    options.set(TablesExtension.COLUMN_SPANS, false).set(TablesExtension.MIN_HEADER_ROWS, 1).set(TablesExtension.MAX_HEADER_ROWS, 1).set(TablesExtension.APPEND_MISSING_COLUMNS, true).set(TablesExtension.DISCARD_EXTRA_COLUMNS, true).set(TablesExtension.WITH_CAPTION, false).set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true);
    // Setup List Options for GitHub profile which is kramdown for documents
    options.setFrom(ParserEmulationProfile.GITHUB_DOC);
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    Node document = parser.parse("This is *Sparta*");
    // "<p>This is <em>Sparta</em></p>\n"
    renderer.render(document);
}
Also used : 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 14 with MutableDataSet

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

the class ProfileEmulationFamilySamples method kramdown.

void kramdown() {
    MutableDataSet options = new MutableDataSet();
    options.setFrom(ParserEmulationProfile.KRAMDOWN);
    options.set(Parser.EXTENSIONS, Arrays.asList(AbbreviationExtension.create(), DefinitionExtension.create(), FootnoteExtension.create(), TablesExtension.create(), TypographicExtension.create()));
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    Node document = parser.parse("This is *Sparta*");
    // "<p>This is <em>Sparta</em></p>\n"
    renderer.render(document);
}
Also used : 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 15 with MutableDataSet

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

the class ProfileEmulationFamilySamples method multiMarkdown.

void multiMarkdown() {
    MutableDataSet options = new MutableDataSet();
    options.setFrom(ParserEmulationProfile.MULTI_MARKDOWN);
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    Node document = parser.parse("This is *Sparta*");
    // "<p>This is <em>Sparta</em></p>\n"
    renderer.render(document);
}
Also used : 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