diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-05-18 16:01:52 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-05-18 16:14:02 +0300 |
commit | e80b64b122950f2a623ce86ea68abdb0061bed27 (patch) | |
tree | 389c43de9470bba6b09e6332096f17c0ad9850c6 /core/src/main/kotlin/Kotlin/ContentBuilder.kt | |
parent | 4f4b86b873b7676979d3258030fdfc382e22a06b (diff) | |
download | dokka-e80b64b122950f2a623ce86ea68abdb0061bed27.tar.gz dokka-e80b64b122950f2a623ce86ea68abdb0061bed27.tar.bz2 dokka-e80b64b122950f2a623ce86ea68abdb0061bed27.zip |
Support reference-style markdown links in KDoc
#KT-17924 fixed
Diffstat (limited to 'core/src/main/kotlin/Kotlin/ContentBuilder.kt')
-rw-r--r-- | core/src/main/kotlin/Kotlin/ContentBuilder.kt | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/core/src/main/kotlin/Kotlin/ContentBuilder.kt b/core/src/main/kotlin/Kotlin/ContentBuilder.kt index a244a48e..b7b7a044 100644 --- a/core/src/main/kotlin/Kotlin/ContentBuilder.kt +++ b/core/src/main/kotlin/Kotlin/ContentBuilder.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.MarkdownTokenTypes import org.intellij.markdown.html.entities.EntityConverter +import org.intellij.markdown.parser.LinkMap import java.util.* fun buildContent(tree: MarkdownNode, linkResolver: (String) -> ContentBlock, inline: Boolean = false): MutableContent { @@ -21,6 +22,8 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri val nodeStack = ArrayDeque<ContentBlock>() nodeStack.push(target) + val linkMap = LinkMap.buildLinkMap(tree.node, tree.text) + tree.visit {node, processChildren -> val parent = nodeStack.peek() @@ -74,14 +77,15 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri } MarkdownElementTypes.SHORT_REFERENCE_LINK, MarkdownElementTypes.FULL_REFERENCE_LINK -> { - val labelText = node.child(MarkdownElementTypes.LINK_LABEL)?.getLabelText() - if (labelText != null) { - val link = linkResolver(labelText) + val labelElement = node.child(MarkdownElementTypes.LINK_LABEL) + if (labelElement != null) { + val linkInfo = linkMap.getLinkInfo(labelElement.text) + val labelText = labelElement.getLabelText() + val link = linkInfo?.let { linkResolver(it.destination.toString()) } ?: linkResolver(labelText) val linkText = node.child(MarkdownElementTypes.LINK_TEXT) if (linkText != null) { renderLinkTextTo(linkText, link, linkResolver) - } - else { + } else { link.append(ContentText(labelText)) } parent.append(link) @@ -148,6 +152,10 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri MarkdownTokenTypes.CODE_FENCE_CONTENT -> { parent.append(ContentText(node.text)) } + + MarkdownElementTypes.LINK_DEFINITION -> { + } + else -> { processChildren() } |