aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authoringo <ingo.kegel@ej-technologies.com>2016-01-06 13:39:54 +0100
committeringo <ingo.kegel@ej-technologies.com>2016-01-06 13:58:30 +0100
commitddd22fc7652f468f57c5a9dca380743eea53be5d (patch)
tree93bcf9670ff317e5450cbb501a5f4b091baf8463 /core/src
parent97b5672ae2ef645c53e9c783dc494860a1eed800 (diff)
downloaddokka-ddd22fc7652f468f57c5a9dca380743eea53be5d.tar.gz
dokka-ddd22fc7652f468f57c5a9dca380743eea53be5d.tar.bz2
dokka-ddd22fc7652f468f57c5a9dca380743eea53be5d.zip
Linking to a target with underscores did not work
For example, in a link like [MY_VALUE], the link would only try to resolve the text "MY" until the first underscore. Since the markdown parser parses the link label as [TEXT:MY, EMPH:_, TEXT:VALUE], using the first TEXT child node is not sufficient.
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/Kotlin/ContentBuilder.kt22
-rw-r--r--core/src/test/kotlin/model/LinkTest.kt10
2 files changed, 22 insertions, 10 deletions
diff --git a/core/src/main/kotlin/Kotlin/ContentBuilder.kt b/core/src/main/kotlin/Kotlin/ContentBuilder.kt
index 1a6ffb98..39e8d8ce 100644
--- a/core/src/main/kotlin/Kotlin/ContentBuilder.kt
+++ b/core/src/main/kotlin/Kotlin/ContentBuilder.kt
@@ -48,27 +48,27 @@ public fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver
MarkdownElementTypes.PARAGRAPH -> appendNodeWithChildren(ContentParagraph())
MarkdownElementTypes.INLINE_LINK -> {
- val label = node.child(MarkdownElementTypes.LINK_TEXT)?.child(MarkdownTokenTypes.TEXT)
+ val labelText = node.child(MarkdownElementTypes.LINK_TEXT)?.getLabelText()
val destination = node.child(MarkdownElementTypes.LINK_DESTINATION)
- if (label != null) {
+ if (labelText != null) {
if (destination != null) {
val link = ContentExternalLink(destination.text)
- link.append(ContentText(label.text))
+ link.append(ContentText(labelText))
parent.append(link)
} else {
- val link = ContentExternalLink(label.text)
- link.append(ContentText(label.text))
+ val link = ContentExternalLink(labelText)
+ link.append(ContentText(labelText))
parent.append(link)
}
}
}
MarkdownElementTypes.SHORT_REFERENCE_LINK,
MarkdownElementTypes.FULL_REFERENCE_LINK -> {
- val label = node.child(MarkdownElementTypes.LINK_LABEL)?.child(MarkdownTokenTypes.TEXT)
- if (label != null) {
- val link = linkResolver(label.text)
- val linkText = node.child(MarkdownElementTypes.LINK_TEXT)?.child(MarkdownTokenTypes.TEXT)
- link.append(ContentText(linkText?.text ?: label.text))
+ 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))
parent.append(link)
}
}
@@ -127,6 +127,8 @@ public fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver
}
}
+private fun MarkdownNode.getLabelText() = children.filter { it.type == MarkdownTokenTypes.TEXT || it.type == MarkdownTokenTypes.EMPH }.joinToString("") { it.text }
+
private fun keepWhitespace(node: ContentNode) = node is ContentParagraph || node is ContentSection
public fun buildInlineContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (String) -> ContentBlock) {
diff --git a/core/src/test/kotlin/model/LinkTest.kt b/core/src/test/kotlin/model/LinkTest.kt
index c30e1c10..ac49cae6 100644
--- a/core/src/test/kotlin/model/LinkTest.kt
+++ b/core/src/test/kotlin/model/LinkTest.kt
@@ -25,6 +25,16 @@ public class LinkTest {
}
}
+ @Test fun linkToConstantWithUnderscores() {
+ verifyModel("testdata/links/linkToConstantWithUnderscores.kt") { model ->
+ with(model.members.single().members.single()) {
+ assertEquals("Foo", name)
+ assertEquals(DocumentationNode.Kind.Class, kind)
+ assertEquals("This is link to [MY_CONSTANT_VALUE -> CompanionObjectProperty:MY_CONSTANT_VALUE]", content.summary.toTestString())
+ }
+ }
+ }
+
@Test fun linkToQualifiedMember() {
verifyModel("testdata/links/linkToQualifiedMember.kt") { model ->
with(model.members.single().members.single()) {