Search in sources :

Example 11 with Parser

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

the class TitleExtract method main.

public static void main(String[] args) {
    Parser parser = Parser.builder(OPTIONS).build();
    HtmlRenderer renderer = HtmlRenderer.builder(OPTIONS).build();
    // You can re-use parser and renderer instances
    Node document = parser.parse("\n" + "# Plugin commit-message-length-validator\n" + "\n" + "Vendor\n" + ":  Gerrit Code Review\n" + "\n" + "Version\n" + ":  v2.15-rc2\n" + "\n" + "commitmessage.maxSubjectLength\n" + ":       Maximum length of the commit message's subject line.  Defaults\n" + "        to 50 if not specified or less than 0.\n" + "\n" + "## About\n" + "\n" + "This plugin checks the length of a commit's commit message subject and body, and reports warnings and errors to the git client if the lentghts are exceeded.\n" + "\n" + "## Documentation\n" + "\n" + "* [Commit Message Length Configuration](config.md)\n" + "* More Items\n" + "\n" + "");
    String title = findTitle(document);
    System.out.println("Title: " + title + "\n");
    // "<p>This is <em>Sparta</em></p>\n"
    String html = renderer.render(document);
    System.out.println(html);
}
Also used : Node(com.vladsch.flexmark.ast.Node) HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Parser(com.vladsch.flexmark.parser.Parser)

Example 12 with Parser

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

the class VisitorSample method countWords.

void countWords() {
    Parser parser = Parser.builder().build();
    Node document = parser.parse("Example\n=======\n\nSome more text");
    visitor.visit(document);
    // 4
    System.out.println(wordCount);
}
Also used : Parser(com.vladsch.flexmark.parser.Parser)

Example 13 with Parser

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

the class ComboParserTest method testWrap.

// @Test
public void testWrap() throws Exception {
    if (!example.isFullSpecExample())
        return;
    final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
    final Parser PARSER = Parser.builder(OPTIONS).build();
    String source = readResource("/wrap.md");
    String html = readResource("/wrap.html");
    assertRendering(source, html);
}
Also used : HtmlRenderer(com.vladsch.flexmark.html.HtmlRenderer) Parser(com.vladsch.flexmark.parser.Parser)

Example 14 with Parser

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

the class ComboTableSpecTest method testTable.

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

Example 15 with Parser

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

the class DelimitedNodeTest method emphasisDelimiters.

@Test
public void emphasisDelimiters() {
    String input = "* *emphasis* \n" + "* **strong** \n" + "* _important_ \n" + "* __CRITICAL__ \n";
    Parser parser = Parser.builder().build();
    Node document = parser.parse(input);
    final List<DelimitedNode> list = new ArrayList<DelimitedNode>();
    NodeVisitor visitor = new NodeVisitor(new VisitHandler<Emphasis>(Emphasis.class, new Visitor<Emphasis>() {

        @Override
        public void visit(Emphasis e) {
            list.add(e);
        }
    }), new VisitHandler<StrongEmphasis>(StrongEmphasis.class, new Visitor<StrongEmphasis>() {

        @Override
        public void visit(StrongEmphasis e) {
            list.add(e);
        }
    }));
    visitor.visit(document);
    assertEquals(4, list.size());
    DelimitedNode emphasis = list.get(0);
    DelimitedNode strong = list.get(1);
    DelimitedNode important = list.get(2);
    DelimitedNode critical = list.get(3);
    assertEquals("*", String.valueOf(emphasis.getOpeningMarker()));
    assertEquals("*", String.valueOf(emphasis.getClosingMarker()));
    assertEquals("**", String.valueOf(strong.getOpeningMarker()));
    assertEquals("**", String.valueOf(strong.getClosingMarker()));
    assertEquals("_", String.valueOf(important.getOpeningMarker()));
    assertEquals("_", String.valueOf(important.getClosingMarker()));
    assertEquals("__", String.valueOf(critical.getOpeningMarker()));
    assertEquals("__", String.valueOf(critical.getClosingMarker()));
}
Also used : ArrayList(java.util.ArrayList) 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