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);
}
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());
}
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());
}
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));
}
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));
}
Aggregations