aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Kryachko <vkryachko@google.com>2020-07-16 11:28:30 -0400
committerVladimir Kryachko <vkryachko@google.com>2020-07-20 16:00:52 -0400
commit9b8280a227848c53045cabc5a86cd013d720c63c (patch)
tree5877b4faa12c2640c1c0ba4a9f22cd433f761bb8
parenta4965376f967f80f6fc948f925bb0466a49527f4 (diff)
downloaddokka-9b8280a227848c53045cabc5a86cd013d720c63c.tar.gz
Fix external link rendering.
The issue manifested by rendering "empty" links to not-imported fully-qualified symbols, for example `{@link com.example.Foo#bar()}` as opposed to `{@link Foo#bar()}` where the file also contains `import com.example.Foo;`. The resulting rendering would be `<a href="correct url"> </a>`( note the space instead of the symbol name. Bug: 161729379 Change-Id: Idc90a7c94c1babff1656a0d2e71194dc7016ec70
-rw-r--r--core/src/main/kotlin/Java/JavadocParser.kt8
1 files changed, 7 insertions, 1 deletions
diff --git a/core/src/main/kotlin/Java/JavadocParser.kt b/core/src/main/kotlin/Java/JavadocParser.kt
index 27cca9177..f446a998d 100644
--- a/core/src/main/kotlin/Java/JavadocParser.kt
+++ b/core/src/main/kotlin/Java/JavadocParser.kt
@@ -439,7 +439,13 @@ class JavadocParser(
val externalLink = resolveExternalLink(valueElement)
val linkSignature by lazy { resolveInternalLink(valueElement) }
if (externalLink != null || linkSignature != null) {
- val labelText = tag.dataElements.firstOrNull { it is PsiDocToken }?.text ?: valueElement!!.text
+
+ // sometimes `dataElements` contains multiple `PsiDocToken` elements and some have whitespace in them
+ // this is best effort to find the first non-empty one before falling back to using the symbol name.
+ val labelText = tag.dataElements.firstOrNull {
+ it is PsiDocToken && it.text?.trim()?.isNotEmpty() ?: false
+ }?.text ?: valueElement!!.text
+
val linkTarget = if (externalLink != null) "href=\"$externalLink\"" else "docref=\"$linkSignature\""
val link = "<a $linkTarget>$labelText</a>"
if (tag.name == "link") "<code>$link</code>" else link