Search in sources :

Example 1 with DocxRenderer

use of com.vladsch.flexmark.docx.converter.internal.DocxRenderer in project flexmark-java by vsch.

the class DocxConverterCommonMark method main.

public static void main(String[] args) {
    final String markdown = "### header\n" + "1. List item started from 1\n" + "### header \n" + "1. List item started from 1\n" + "1. List item continued 2\n" + "### test\n" + "1. List item started from 1\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-issue-176.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 2 with DocxRenderer

use of com.vladsch.flexmark.docx.converter.internal.DocxRenderer 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)

Aggregations

Node (com.vladsch.flexmark.ast.Node)2 DocxRenderer (com.vladsch.flexmark.docx.converter.internal.DocxRenderer)2 Parser (com.vladsch.flexmark.parser.Parser)2 File (java.io.File)2 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)2 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)2