Fixed rendering of line breaks and apostrophes in KDoc

#KT-8531 Fixed
 #KT-8392 Fixed
This commit is contained in:
Dmitry Jemerov
2015-07-28 18:47:42 +02:00
parent ff0a064908
commit 909d094896
4 changed files with 58 additions and 73 deletions
@@ -118,79 +118,36 @@ object KDocRenderer {
public fun MarkdownNode.toHtml(): String {
val sb = StringBuilder()
visit { node, processChildren ->
fun wrapChildren(tag: String, newline: Boolean = false) {
sb.append("<$tag>")
if (newline) sb.appendln()
processChildren()
sb.append("</$tag>")
if (newline) sb.appendln()
}
val nodeType = node.type
val nodeText = node.text
when (nodeType) {
MarkdownElementTypes.UNORDERED_LIST -> {
sb.appendln("<ul>")
processChildren()
sb.appendln("</ul>")
}
MarkdownElementTypes.ORDERED_LIST -> {
sb.appendln("<ol>")
processChildren()
sb.appendln("</ol>")
}
MarkdownElementTypes.LIST_ITEM -> {
sb.append("<li>")
processChildren()
sb.appendln("</li>")
}
MarkdownElementTypes.EMPH -> {
sb.append("<em>")
processChildren()
sb.append("</em>")
}
MarkdownElementTypes.STRONG -> {
sb.append("<strong>")
processChildren()
sb.append("</strong>")
}
MarkdownElementTypes.ATX_1 -> {
sb.append("<h1>")
processChildren()
sb.append("</h1>")
}
MarkdownElementTypes.ATX_2 -> {
sb.append("<h2>")
processChildren()
sb.append("</h2>")
}
MarkdownElementTypes.ATX_3 -> {
sb.append("<h3>")
processChildren()
sb.append("</h3>")
}
MarkdownElementTypes.ATX_4 -> {
sb.append("<h4>")
processChildren()
sb.append("</h4>")
}
MarkdownElementTypes.ATX_5 -> {
sb.append("<h5>")
processChildren()
sb.append("</h5>")
}
MarkdownElementTypes.ATX_6 -> {
sb.append("<h6>")
processChildren()
sb.append("</h6>")
}
MarkdownElementTypes.BLOCK_QUOTE -> {
sb.append("<blockquote>")
processChildren()
sb.append("</blockquote>")
}
MarkdownElementTypes.UNORDERED_LIST -> wrapChildren("ul", newline = true)
MarkdownElementTypes.ORDERED_LIST -> wrapChildren("ol", newline = true)
MarkdownElementTypes.LIST_ITEM -> wrapChildren("li")
MarkdownElementTypes.EMPH -> wrapChildren("em")
MarkdownElementTypes.STRONG -> wrapChildren("strong")
MarkdownElementTypes.ATX_1 -> wrapChildren("h1")
MarkdownElementTypes.ATX_2 -> wrapChildren("h2")
MarkdownElementTypes.ATX_3 -> wrapChildren("h3")
MarkdownElementTypes.ATX_4 -> wrapChildren("h4")
MarkdownElementTypes.ATX_5 -> wrapChildren("h5")
MarkdownElementTypes.ATX_6 -> wrapChildren("h6")
MarkdownElementTypes.BLOCK_QUOTE -> wrapChildren("blockquote")
MarkdownElementTypes.PARAGRAPH -> {
sb.append("<p>")
processChildren()
sb.appendln("</p>")
}
MarkdownElementTypes.CODE_SPAN -> {
sb.append("<code>")
processChildren()
sb.append("</code>")
while (sb.length() > 0 && sb[sb.length() - 1] == ' ') {
sb.deleteCharAt(sb.length() - 1)
}
wrapChildren("p", newline = true)
}
MarkdownElementTypes.CODE_SPAN -> wrapChildren("code")
MarkdownElementTypes.CODE_BLOCK -> {
sb.append("<pre><code>")
processChildren()
@@ -218,6 +175,7 @@ object KDocRenderer {
MarkdownTokenTypes.TEXT,
MarkdownTokenTypes.WHITE_SPACE,
MarkdownTokenTypes.COLON,
MarkdownTokenTypes.SINGLE_QUOTE,
MarkdownTokenTypes.DOUBLE_QUOTE,
MarkdownTokenTypes.LPAREN,
MarkdownTokenTypes.RPAREN,
@@ -225,6 +183,9 @@ object KDocRenderer {
MarkdownTokenTypes.RBRACKET -> {
sb.append(nodeText)
}
MarkdownTokenTypes.EOL -> {
sb.append(" ")
}
MarkdownTokenTypes.GT -> sb.append("&gt;")
MarkdownTokenTypes.LT -> sb.append("&lt;")
else -> {
+14
View File
@@ -0,0 +1,14 @@
/**
* Some documentation
* on two lines.
*/
fun testMethod() {
}
fun test() {
<caret>testMethod()
}
//INFO: <b>internal</b> <b>fun</b> testMethod(): Unit <i>defined in</i> root package<br/><p>Some documentation on two lines.
//INFO: </p>
+9 -5
View File
@@ -1,5 +1,5 @@
/**
* Some documentation. **Bold** *underline* `code` foo: bar (baz) [quux] <xyzzy>
* Some documentation. **Bold** *underline* `code` foo: bar (baz) [quux] <xyzzy> 'apos'
*
* [Kotlin](http://www.kotlinlang.org)
*
@@ -18,9 +18,13 @@ fun test() {
<caret>testMethod(1, "value")
}
//INFO: <b>internal</b> <b>fun</b> testMethod(): Unit <i>defined in</i> root package<br/><p><p>Some documentation. <strong>Bold</strong> <em>underline</em> <code>code</code> foo: bar (baz) <a href="psi_element://quux">quux</a> </p>
//INFO: <p>a href="http://www.kotlinlang.org">Kotlin</a></p>
//INFO: <p><a href="psi_element://C">C</a></p>
//INFO: <p><a href="psi_element://C">See this class</a></p>
//INFO: <b>internal</b> <b>fun</b> testMethod(): Unit <i>defined in</i> root package<br/><p><p>
//INFO: Some documentation. <strong>Bold</strong> <em>underline</em> <code>code</code> foo: bar (baz) <a href="psi_element://quux">quux</a> 'apos'</p>
//INFO: <p>
//INFO: a href="http://www.kotlinlang.org">Kotlin</a></p>
//INFO: <p>
//INFO: <a href="psi_element://C">C</a></p>
//INFO: <p>
//INFO: <a href="psi_element://C">See this class</a></p>
//INFO:
//INFO: </p>
@@ -113,6 +113,12 @@ public class JetQuickDocProviderTestGenerated extends AbstractJetQuickDocProvide
doTest(fileName);
}
@TestMetadata("OnMethodUsageMultiline.kt")
public void testOnMethodUsageMultiline() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/editor/quickDoc/OnMethodUsageMultiline.kt");
doTest(fileName);
}
@TestMetadata("OnMethodUsageWithBracketsInParam.kt")
public void testOnMethodUsageWithBracketsInParam() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/editor/quickDoc/OnMethodUsageWithBracketsInParam.kt");