aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Kotlin
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2016-04-28 12:58:06 +0200
committerDmitry Jemerov <yole@jetbrains.com>2016-04-28 12:58:06 +0200
commit2e5b40d69e15c30474cf8564b08587f15ed8e383 (patch)
tree2682025e1a2688bedbd1ad4a3796ad16011ab345 /core/src/main/kotlin/Kotlin
parent586748b30a21012774266dac3c8f2fa6fe3ab2b8 (diff)
downloaddokka-2e5b40d69e15c30474cf8564b08587f15ed8e383.tar.gz
dokka-2e5b40d69e15c30474cf8564b08587f15ed8e383.tar.bz2
dokka-2e5b40d69e15c30474cf8564b08587f15ed8e383.zip
correctly render Markdown in link text (KT-11791)
Diffstat (limited to 'core/src/main/kotlin/Kotlin')
-rw-r--r--core/src/main/kotlin/Kotlin/ContentBuilder.kt28
1 files changed, 20 insertions, 8 deletions
diff --git a/core/src/main/kotlin/Kotlin/ContentBuilder.kt b/core/src/main/kotlin/Kotlin/ContentBuilder.kt
index 496c886b..9e89a20a 100644
--- a/core/src/main/kotlin/Kotlin/ContentBuilder.kt
+++ b/core/src/main/kotlin/Kotlin/ContentBuilder.kt
@@ -48,16 +48,16 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri
MarkdownElementTypes.PARAGRAPH -> appendNodeWithChildren(ContentParagraph())
MarkdownElementTypes.INLINE_LINK -> {
- val labelText = node.child(MarkdownElementTypes.LINK_TEXT)?.getLabelText()
+ val linkTextNode = node.child(MarkdownElementTypes.LINK_TEXT)
val destination = node.child(MarkdownElementTypes.LINK_DESTINATION)
- if (labelText != null) {
+ if (linkTextNode != null) {
if (destination != null) {
val link = ContentExternalLink(destination.text)
- link.append(ContentText(labelText))
+ renderLinkTextTo(linkTextNode, link, linkResolver)
parent.append(link)
} else {
- val link = ContentExternalLink(labelText)
- link.append(ContentText(labelText))
+ val link = ContentExternalLink(linkTextNode.getLabelText())
+ renderLinkTextTo(linkTextNode, link, linkResolver)
parent.append(link)
}
}
@@ -67,8 +67,13 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri
val labelText = node.child(MarkdownElementTypes.LINK_LABEL)?.getLabelText()
if (labelText != null) {
val link = linkResolver(labelText)
- val linkText = node.child(MarkdownElementTypes.LINK_TEXT)?.getLabelText()
- link.append(ContentText(linkText ?: labelText))
+ val linkText = node.child(MarkdownElementTypes.LINK_TEXT)
+ if (linkText != null) {
+ renderLinkTextTo(linkText, link, linkResolver)
+ }
+ else {
+ link.append(ContentText(labelText))
+ }
parent.append(link)
}
}
@@ -104,7 +109,8 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri
}
MarkdownTokenTypes.EMPH -> {
- if (node.parent?.type != MarkdownElementTypes.EMPH) {
+ val parentNodeType = node.parent?.type
+ if (parentNodeType != MarkdownElementTypes.EMPH && parentNodeType != MarkdownElementTypes.STRONG) {
parent.append(ContentText(node.text))
}
}
@@ -138,3 +144,9 @@ fun buildInlineContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver:
}
}
+fun renderLinkTextTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (String) -> ContentBlock) {
+ val linkTextNodes = tree.children.drop(1).dropLast(1)
+ linkTextNodes.forEach {
+ buildContentTo(it, target, linkResolver)
+ }
+}