Search in sources :

Example 36 with Parser

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

the class ComboAutolinkSpecTest method testSpecTxt.

@Test
public void testSpecTxt() throws Exception {
    if (!example.isFullSpecExample())
        return;
    final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
    final Parser PARSER = Parser.builder(OPTIONS).build();
    String source = readResource("/spec.txt");
    Node node = PARSER.parse(source);
// String html = readResource("/table.html");
// assertRendering(source, html);
}
Also used : Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 37 with Parser

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

Example 38 with Parser

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

the class ParserTest method emptyReaderTest.

@Test
public void emptyReaderTest() throws IOException {
    Parser parser = Parser.builder().build();
    Node document1 = parser.parseReader(new StringReader(""));
    assertEquals(false, document1.hasChildren());
}
Also used : StringReader(java.io.StringReader) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 39 with Parser

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

the class ParserTest method ioReaderTest.

@Test
public void ioReaderTest() throws IOException {
    Parser parser = Parser.builder().build();
    InputStream input1 = SpecReader.getSpecInputStream();
    Node document1;
    InputStreamReader reader = new InputStreamReader(input1, "utf-8");
    document1 = parser.parseReader(reader);
    String spec = SpecReader.readSpec();
    Node document2 = parser.parse(spec);
    HtmlRenderer renderer = HtmlRenderer.builder().escapeHtml(true).build();
    assertEquals(renderer.render(document2), renderer.render(document1));
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 40 with Parser

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

the class ParserTest method customBlockParserFactory.

@Test
public void customBlockParserFactory() {
    Parser parser = Parser.builder().customBlockParserFactory(new DashBlockParserFactory()).build();
    // The dashes would normally be a ThematicBreak
    Node document = parser.parse("hey\n\n---\n");
    assertThat(document.getFirstChild(), instanceOf(Paragraph.class));
    assertEquals("hey", ((Text) document.getFirstChild().getFirstChild()).getChars().toString());
    assertThat(document.getLastChild(), instanceOf(DashBlock.class));
}
Also used : 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