Search in sources :

Example 6 with MutableDataHolder

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

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

the class ParserTest method indentationWithLines.

@Test
public void indentationWithLines() {
    String given = " - 1 space\n   - 3 spaces\n     - 5 spaces\n\t - tab + space";
    MutableDataHolder options = new MutableDataSet().set(Parser.TRACK_DOCUMENT_LINES, true);
    Parser parser = Parser.builder(options).build();
    Document document = parser.parse(given);
    assertThat(document.getFirstChild(), instanceOf(BulletList.class));
    assertEquals("Document line count", 4, document.getLineCount());
    // first level list
    Node list = document.getFirstChild();
    assertEquals("expect one child", list.getFirstChild(), list.getLastChild());
    assertEquals("1 space", firstText(list.getFirstChild()));
    assertEquals("node start line number", 0, list.getStartLineNumber());
    assertEquals("node end line number", 3, list.getEndLineNumber());
    // second level list
    list = list.getFirstChild().getLastChild();
    assertEquals("expect one child", list.getFirstChild(), list.getLastChild());
    assertEquals("3 spaces", firstText(list.getFirstChild()));
    assertEquals("node start line number", 1, list.getStartLineNumber());
    assertEquals("node end line number", 3, list.getEndLineNumber());
    // third level list
    list = list.getFirstChild().getLastChild();
    assertEquals("5 spaces", firstText(list.getFirstChild()));
    assertEquals("tab + space", firstText(list.getFirstChild().getNext()));
    assertEquals("node start line number", 2, list.getStartLineNumber());
    assertEquals("node end line number", 3, list.getEndLineNumber());
}
Also used : MutableDataHolder(com.vladsch.flexmark.util.options.MutableDataHolder) MutableDataSet(com.vladsch.flexmark.util.options.MutableDataSet) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

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