FlexmarkParser implements MarkdownParser { public static String wrapWithMarkdownClassDiv(String html) { return new StringBuilder() .append("<div class=\"markdown-body\">\n") .append(html) .append("\n</div>") .toString(); } FlexmarkParser(); @Override String render(String markdownText); static String wrapWithMarkdownClassDiv(String html);  }
@Test public void testStrikethrough() { InterpreterResult result = md.interpret("This is ~~deleted~~ text", null); assertEquals(wrapWithMarkdownClassDiv("<p>This is <del>deleted</del> text</p>\n"), result.message().get(0).getData()); }
@Test public void testHeader() { InterpreterResult r1 = md.interpret("# H1", null); assertEquals(wrapWithMarkdownClassDiv("<h1>H1</h1>\n"), r1.message().get(0).getData()); InterpreterResult r2 = md.interpret("## H2", null); assertEquals(wrapWithMarkdownClassDiv("<h2>H2</h2>\n"), r2.message().get(0).getData()); InterpreterResult r3 = md.interpret("### H3", null); assertEquals(wrapWithMarkdownClassDiv("<h3>H3</h3>\n"), r3.message().get(0).getData()); InterpreterResult r4 = md.interpret("#### H4", null); assertEquals(wrapWithMarkdownClassDiv("<h4>H4</h4>\n"), r4.message().get(0).getData()); InterpreterResult r5 = md.interpret("##### H5", null); assertEquals(wrapWithMarkdownClassDiv("<h5>H5</h5>\n"), r5.message().get(0).getData()); InterpreterResult r6 = md.interpret("###### H6", null); assertEquals(wrapWithMarkdownClassDiv("<h6>H6</h6>\n"), r6.message().get(0).getData()); InterpreterResult r7 = md.interpret("Alt-H1\n" + "======", null); assertEquals(wrapWithMarkdownClassDiv("<h1>Alt-H1</h1>\n"), r7.message().get(0).getData()); InterpreterResult r8 = md.interpret("Alt-H2\n" + "------", null); assertEquals(wrapWithMarkdownClassDiv("<h2>Alt-H2</h2>\n"), r8.message().get(0).getData()); }
@Test public void testItalics() { InterpreterResult result = md.interpret("This is *italics* text", null); assertEquals( wrapWithMarkdownClassDiv("<p>This is <em>italics</em> text</p>\n"), result.message().get(0).getData()); }
@Test public void testStrongEmphasis() { InterpreterResult result = md.interpret("This is **strong emphasis** text", null); assertEquals( wrapWithMarkdownClassDiv("<p>This is <strong>strong emphasis</strong> text</p>\n"), result.message().get(0).getData()); }
@Test public void testOrderedList() { String input = new StringBuilder() .append("1. First ordered list item\n") .append("2. Another item") .toString(); String expected = new StringBuilder() .append("<ol>\n") .append("<li>First ordered list item</li>\n") .append("<li>Another item</li>\n") .append("</ol>\n") .toString(); InterpreterResult result = md.interpret(input, null); assertEquals(wrapWithMarkdownClassDiv(expected), result.message().get(0).getData()); }
@Test public void testUnorderedList() { String input = new StringBuilder() .append("* Unordered list can use asterisks\n") .append("- Or minuses\n") .append("+ Or pluses") .toString(); String expected = new StringBuilder() .append("<ul>\n") .append("<li>Unordered list can use asterisks</li>\n") .append("</ul>\n") .append("<ul>\n") .append("<li>Or minuses</li>\n") .append("</ul>\n") .append("<ul>\n") .append("<li>Or pluses</li>\n") .append("</ul>\n") .toString(); InterpreterResult result = md.interpret(input, null); assertEquals(wrapWithMarkdownClassDiv(expected), result.message().get(0).getData()); }