aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/Kotlin/ContentBuilder.kt18
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt8
2 files changed, 21 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()
}
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index e3f4bae7..48b06d6e 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -364,6 +364,14 @@ class MarkdownFormatTest {
verifyMarkdownNode("nestedLists")
}
+ @Test fun referenceLink() {
+ verifyMarkdownNode("referenceLink")
+ }
+
+ @Test fun externalReferenceLink() {
+ verifyMarkdownNode("externalReferenceLink")
+ }
+
@Test fun newlineInTableCell() {
verifyMarkdownPackage("newlineInTableCell")
}