render markdown inside link texts

#KT-11791 Fixed
This commit is contained in:
Dmitry Jemerov
2016-04-28 12:27:44 +02:00
parent c967cc8a23
commit 6cbf1de170
2 changed files with 15 additions and 6 deletions
@@ -161,7 +161,7 @@ object KDocRenderer {
MarkdownElementTypes.FULL_REFERENCE_LINK -> { MarkdownElementTypes.FULL_REFERENCE_LINK -> {
val label = node.child(MarkdownElementTypes.LINK_LABEL)?.child(MarkdownTokenTypes.TEXT)?.text val label = node.child(MarkdownElementTypes.LINK_LABEL)?.child(MarkdownTokenTypes.TEXT)?.text
if (label != null) { if (label != null) {
val linkText = node.child(MarkdownElementTypes.LINK_TEXT)?.child(MarkdownTokenTypes.TEXT)?.text ?: label val linkText = node.child(MarkdownElementTypes.LINK_TEXT)?.toHtml() ?: label
DocumentationManagerUtil.createHyperlink(sb, label, linkText, true) DocumentationManagerUtil.createHyperlink(sb, label, linkText, true)
} }
else { else {
@@ -169,10 +169,10 @@ object KDocRenderer {
} }
} }
MarkdownElementTypes.INLINE_LINK -> { MarkdownElementTypes.INLINE_LINK -> {
val label = node.child(MarkdownElementTypes.LINK_TEXT)?.child(MarkdownTokenTypes.TEXT)?.text val label = node.child(MarkdownElementTypes.LINK_TEXT)?.toHtml()
val destination = node.child(MarkdownElementTypes.LINK_DESTINATION)?.text val destination = node.child(MarkdownElementTypes.LINK_DESTINATION)?.text
if (label != null && destination != null) { if (label != null && destination != null) {
sb.append("<a href=\"$destination\">${label.htmlEscape()}</a>") sb.append("<a href=\"$destination\">$label</a>")
} }
else { else {
sb.append(node.text) sb.append(node.text)
@@ -202,6 +202,14 @@ object KDocRenderer {
} }
MarkdownTokenTypes.GT -> sb.append("&gt;") MarkdownTokenTypes.GT -> sb.append("&gt;")
MarkdownTokenTypes.LT -> sb.append("&lt;") MarkdownTokenTypes.LT -> sb.append("&lt;")
MarkdownElementTypes.LINK_TEXT -> {
val childrenWithoutBrackets = node.children.drop(1).dropLast(1)
for (child in childrenWithoutBrackets) {
sb.append(child.toHtml())
}
}
else -> { else -> {
processChildren() processChildren()
} }
+4 -3
View File
@@ -2,10 +2,11 @@
* Some documentation. **Bold** *underline* `code` foo: bar (baz) [quux] <xyzzy> 'apos' * Some documentation. **Bold** *underline* `code` foo: bar (baz) [quux] <xyzzy> 'apos'
* *
* [Kotlin](http://www.kotlinlang.org) * [Kotlin](http://www.kotlinlang.org)
* [a**b**__d__ kas ](http://www.ibm.com)
* *
* [C] * [C]
* *
* [See this class][C] * [See **this** class][C]
*/ */
fun testMethod() { fun testMethod() {
@@ -19,6 +20,6 @@ fun test() {
} }
//INFO: <b>public</b> <b>fun</b> testMethod(): Unit <i>defined in</i> root package<p>Some documentation. <strong>Bold</strong> <em>underline</em> <code>code</code> foo: bar (baz) <a href="psi_element://quux">quux</a> 'apos'</p> //INFO: <b>public</b> <b>fun</b> testMethod(): Unit <i>defined in</i> root package<p>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><a href="http://www.kotlinlang.org">Kotlin</a></p> //INFO: <p><a href="http://www.kotlinlang.org">Kotlin</a> <a href="http://www.ibm.com">a<strong>b</strong><strong>d</strong>kas</a></p>
//INFO: <p><a href="psi_element://C">C</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: <p><a href="psi_element://C">See<strong>this</strong>class</a></p>