JavadocUtil { public static String convertFromJavadoc(String javadoc, TemplateFormatting templateFormatting) { String converted = javadoc .replace("\n", "") .replace("<br/>", FORCED_LB) .replace("<br>", FORCED_LB) .replace("<p>", LB + LB) .replace("</p>", LB + LB) .replace("<ul>", LB) .replace("</ul>", LB + LB) .replace("<li>", LB + "- ") .replace("</li>", "") .replace("<b>", templateFormatting.getBold()) .replace("</b>", templateFormatting.getBold()) .replace("<strong>", templateFormatting.getBold()) .replace("</strong>", templateFormatting.getBold()) .replace("<i>", templateFormatting.getItalics()) .replace("</i>", templateFormatting.getItalics()) .replace("<em>", templateFormatting.getItalics()) .replace("</em>", templateFormatting.getItalics()) .replace("<code>", templateFormatting.getCode()) .replace("</code>", templateFormatting.getCode()) .replaceAll("<a\\s+href\\s*=\\s*[\"\'](.*?)[\"\']\\s*>(.*?)</a>", templateFormatting.link()); if (converted.isEmpty()) { return ""; } String res = trimAndFixLineBreak(converted, FORCED_LB, templateFormatting.getLineBreak()); res = trimAndFixLineBreak(res, LB, "\n"); return res; } private  JavadocUtil(); static String convertFromJavadoc(String javadoc, TemplateFormatting templateFormatting);  }
@Test public void convertLineBreaksAsciidoc() { String actual = "" + "First line is ok" + "<br> second line should be trimmed " + "<br/>\n\nthis is just \none\n\n line " + "<p> first paragraph</p>" + "<p> second paragraph \n \n "; String expected = "" + "First line is ok" + " +\nsecond line should be trimmed" + " +\nthis is just one line" + "\n\nfirst paragraph\n\n" + "\n\nsecond paragraph"; assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.ASCIIDOC), is(expected)); }
@Test public void convertLineBreaksMarkdown() { String actual = "" + "First line is ok" + "<br> second line should be trimmed " + "<br/>\n\nthis is just \none\n\n line " + "<p> first paragraph</p>" + "<p> second paragraph \n \n "; String expected = "" + "First line is ok" + "<br>second line should be trimmed" + "<br>this is just one line" + "\n\nfirst paragraph\n\n" + "\n\nsecond paragraph"; assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.MARKDOWN), is(expected)); }
@Test public void convertBulletedListAsciidoc() { String actual = "" + "<ul>" + "<li>first bullet</li>" + "<li>second bullet</li>" + "</ul>some text" + "<li>standalone li" + "<ul>" + "<li>without end works as well"; String expected = "" + "\n" + "\n- first bullet" + "\n- second bullet" + "\n\nsome text" + "\n- standalone li" + "\n" + "\n- without end works as well"; assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.ASCIIDOC), is(expected)); }
@Test public void convertBulletedListMarkdown() { String actual = "" + "<ul>" + "<li>first bullet</li>" + "<li>second bullet</li>" + "</ul>some text" + "<li>standalone li" + "<ul>" + "<li>without end works as well"; String expected = "" + "\n" + "\n- first bullet" + "\n- second bullet" + "\n\nsome text" + "\n- standalone li" + "\n" + "\n- without end works as well"; assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.MARKDOWN), is(expected)); }
@Test public void convertBoldStylingAsciidoc() { String actual = "before<b>bold</b>normal<strong>bold2</strong>after"; String expected = "before**bold**normal**bold2**after"; assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.ASCIIDOC), is(expected)); }
@Test public void convertItalicsStylingAsciidoc() { String actual = "before<i>italics</i>normal<em>italics2</em>after"; String expected = "before__italics__normal__italics2__after"; assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.ASCIIDOC), is(expected)); }
@Test public void convertCodeStylingAsciidoc() { String actual = "before <code>code()</code> after"; String expected = "before `code()` after"; assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.ASCIIDOC), is(expected)); }
@Test public void convertBoldStylingMarkdown() { String actual = "before<b>bold</b>normal<strong>bold2</strong>after"; String expected = "before**bold**normal**bold2**after"; assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.MARKDOWN), is(expected)); }
@Test public void convertItalicsStylingMarkdown() { String actual = "before<i>italics</i>normal<em>italics2</em>after"; String expected = "before*italics*normal*italics2*after"; assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.MARKDOWN), is(expected)); }
@Test public void convertCodeStylingMarkdown() { String actual = "before <code>code()</code> after"; String expected = "before `code()` after"; assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.MARKDOWN), is(expected)); }
@Test public void convertLinkAsciidoc() { String actual = "<a href=\"https: String expected = "link:https: assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.ASCIIDOC), is(expected)); }
@Test public void convertLinkMarkdown() { String actual = "<a href=\"https: String expected = "[GitHub](https: assertThat(JavadocUtil.convertFromJavadoc(actual, TemplateFormatting.MARKDOWN), is(expected)); }