Search in sources :

Example 16 with Parser

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

the class DelimiterProcessorTest method delimiterProcessorWithInvalidDelimiterUse.

@Test
public void delimiterProcessorWithInvalidDelimiterUse() {
    Parser parser = Parser.builder().customDelimiterProcessor(new CustomDelimiterProcessor(':', 0)).customDelimiterProcessor(new CustomDelimiterProcessor(';', -1)).build();
    assertEquals("<p>:test:</p>\n", RENDERER.render(parser.parse(":test:")));
    assertEquals("<p>;test;</p>\n", RENDERER.render(parser.parse(";test;")));
}
Also used : Parser(com.vladsch.flexmark.parser.Parser) InlineParser(com.vladsch.flexmark.parser.InlineParser) Test(org.junit.Test)

Example 17 with Parser

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

the class ParserTest method indentation.

@Test
public void indentation() {
    String given = " - 1 space\n   - 3 spaces\n     - 5 spaces\n\t - tab + space";
    Parser parser = Parser.builder().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 : Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 18 with Parser

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

the class TextCollectingVisitorTest method test_basic.

@Test
public void test_basic() {
    Parser parser = Parser.builder().build();
    Node document = parser.parse("Test text");
    TextCollectingVisitor collectingVisitor = new TextCollectingVisitor();
    final String text = collectingVisitor.collectAndGetText(document);
    assertEquals("Test text", text);
}
Also used : Node(com.vladsch.flexmark.ast.Node) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 19 with Parser

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

the class TextCollectingVisitorTest method test_fenced_code.

@Test
public void test_fenced_code() {
    Parser parser = Parser.builder().build();
    Node document = parser.parse("```info\nfenced code\nlines\n```");
    TextCollectingVisitor collectingVisitor = new TextCollectingVisitor();
    final String text = collectingVisitor.collectAndGetText(document);
    assertEquals("fenced code\nlines\n", text);
}
Also used : Node(com.vladsch.flexmark.ast.Node) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 20 with Parser

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

the class TextCollectingVisitorTest method test_emphasis.

@Test
public void test_emphasis() {
    Parser parser = Parser.builder().build();
    Node document = parser.parse("Test text *emphasis*");
    TextCollectingVisitor collectingVisitor = new TextCollectingVisitor();
    final String text = collectingVisitor.collectAndGetText(document);
    assertEquals("Test text emphasis", text);
}
Also used : Node(com.vladsch.flexmark.ast.Node) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

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