Search in sources :

Example 41 with Parser

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

the class TextCollectingVisitorTest method test_inline_code.

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

Example 42 with Parser

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

the class UsageExampleTest method parseAndRender.

@Test
public void parseAndRender() {
    Parser parser = Parser.builder().build();
    Node document = parser.parse("This is *Sparta*");
    HtmlRenderer renderer = HtmlRenderer.builder().escapeHtml(true).build();
    assertEquals("<p>This is <em>Sparta</em></p>\n", renderer.render(document));
}
Also used : HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 43 with Parser

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

the class UsageExampleTest method visitor.

@Test
public void visitor() {
    Parser parser = Parser.builder().build();
    Node node = parser.parse("Example\n=======\n\nSome more text");
    WordCountVisitor visitor = new WordCountVisitor();
    visitor.countWords(node);
    assertEquals(4, visitor.wordCount);
}
Also used : Parser(com.vladsch.flexmark.parser.Parser) Test(org.junit.Test)

Example 44 with Parser

use of com.vladsch.flexmark.parser.Parser in project nzbhydra2 by theotherp.

the class Markdown method renderMarkdownAsHtml.

public static String renderMarkdownAsHtml(String markdown) {
    MutableDataSet options = new MutableDataSet();
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    Node document = parser.parse(markdown);
    return renderer.render(document);
}
Also used : 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)

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