Search in sources :

Example 26 with Parser

use of com.vladsch.flexmark.parser.Parser 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 27 with Parser

use of com.vladsch.flexmark.parser.Parser 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 28 with Parser

use of com.vladsch.flexmark.parser.Parser in project flexmark-java by vsch.

the class CustomContextDataSample method main.

public static void main(String[] args) {
    final DataHolder options = PegdownOptionsAdapter.flexmarkOptions(Extensions.ALL, CustomExtension.create());
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    String markdown = "";
    XhtmlContent xhtmlContent = null;
    // You can re-use parser and renderer instances
    Document document = (Document) parser.parse(markdown);
    document.set(XHTML_CONTENT, xhtmlContent);
    // "<p>This is <em>Sparta</em></p>\n"
    String html = renderer.render(document);
    System.out.println(html);
}
Also used : DataHolder(com.vladsch.flexmark.util.options.DataHolder) MutableDataHolder(com.vladsch.flexmark.util.options.MutableDataHolder) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Document(com.vladsch.flexmark.ast.Document) Parser(com.vladsch.flexmark.parser.Parser)

Example 29 with Parser

use of com.vladsch.flexmark.parser.Parser in project flexmark-java by vsch.

the class DocxConverterPegdown method main.

public static void main(String[] args) {
    final String markdown = "#Heading\n" + "-----\n" + "paragraph text \n" + "lazy continuation\n" + "\n" + "* list item\n" + "    > block quote\n" + "    lazy continuation\n" + "\n" + "~~~info\n" + "   with uneven indent\n" + "      with uneven indent\n" + "indented code\n" + "~~~ \n" + "\n" + "       with uneven indent\n" + "          with uneven indent\n" + "    indented code\n" + "1. numbered item 1   \n" + "1. numbered item 2   \n" + "1. numbered item 3   \n" + "    - bullet item 1   \n" + "    - bullet item 2   \n" + "    - bullet item 3   \n" + "        1. numbered sub-item 1   \n" + "        1. numbered sub-item 2   \n" + "        1. numbered sub-item 3   \n" + "    \n" + "    ~~~info\n" + "       with uneven indent\n" + "          with uneven indent\n" + "    indented code\n" + "    ~~~ \n" + "    \n" + "           with uneven indent\n" + "              with uneven indent\n" + "        indented code\n" + "";
    System.out.println("markdown\n");
    System.out.println(markdown);
    final Parser PARSER = Parser.builder(OPTIONS).build();
    final DocxRenderer RENDERER = DocxRenderer.builder(OPTIONS).build();
    Node document = PARSER.parse(markdown);
    // to get XML
    String xml = RENDERER.render(document);
    // or to control the package
    final WordprocessingMLPackage template = DocxRenderer.getDefaultTemplate();
    RENDERER.render(document, template);
    File file = new File("/Users/vlad/src/pdf/flexmark-java.docx");
    try {
        template.save(file, Docx4J.FLAG_SAVE_ZIP_FILE);
    } catch (Docx4JException e) {
        e.printStackTrace();
    }
}
Also used : Node(com.vladsch.flexmark.ast.Node) DocxRenderer(com.vladsch.flexmark.docx.converter.internal.DocxRenderer) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) File(java.io.File) Docx4JException(org.docx4j.openpackaging.exceptions.Docx4JException) Parser(com.vladsch.flexmark.parser.Parser)

Example 30 with Parser

use of com.vladsch.flexmark.parser.Parser in project flexmark-java by vsch.

the class ProfileEmulationFamilySamples method commonMark.

void commonMark() {
    Parser parser = Parser.builder().build();
    Node document = parser.parse("This is *Sparta*");
    HtmlRenderer renderer = HtmlRenderer.builder().build();
    // "<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) Parser(com.vladsch.flexmark.parser.Parser)

Aggregations

Parser (com.vladsch.flexmark.parser.Parser)44 Node (com.vladsch.flexmark.ast.Node)29 HtmlRenderer (com.vladsch.flexmark.html.HtmlRenderer)27 Test (org.junit.Test)18 MutableDataSet (com.vladsch.flexmark.util.options.MutableDataSet)17 MutableDataHolder (com.vladsch.flexmark.util.options.MutableDataHolder)8 Extension (com.vladsch.flexmark.Extension)2 Document (com.vladsch.flexmark.ast.Document)2 DocxRenderer (com.vladsch.flexmark.docx.converter.internal.DocxRenderer)2 AstCollectingVisitor (com.vladsch.flexmark.test.AstCollectingVisitor)2 DataHolder (com.vladsch.flexmark.util.options.DataHolder)2 File (java.io.File)2 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)2 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)2 TextCollectingVisitor (com.vladsch.flexmark.ast.util.TextCollectingVisitor)1 AutolinkExtension (com.vladsch.flexmark.ext.autolink.AutolinkExtension)1 JekyllTag (com.vladsch.flexmark.ext.jekyll.tag.JekyllTag)1 CustomNodeFormatter (com.vladsch.flexmark.formatter.CustomNodeFormatter)1 Formatter (com.vladsch.flexmark.formatter.internal.Formatter)1 InlineParser (com.vladsch.flexmark.parser.InlineParser)1