diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-05-31 13:33:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-31 13:33:48 +0200 |
commit | d4e70e113ac093bdd35edd9c112b4a0addc78ab5 (patch) | |
tree | 7bdfcb8e5ba161dfc41b8dc1958d3de3826d1c71 /plugins/base/src/main/kotlin/translators/documentables | |
parent | 0c48894b5cb0e9dd20706a14f268219b34e18531 (diff) | |
download | dokka-d4e70e113ac093bdd35edd9c112b4a0addc78ab5.tar.gz dokka-d4e70e113ac093bdd35edd9c112b4a0addc78ab5.tar.bz2 dokka-d4e70e113ac093bdd35edd9c112b4a0addc78ab5.zip |
Fix rendering html in briefs (#1931)
Diffstat (limited to 'plugins/base/src/main/kotlin/translators/documentables')
-rw-r--r-- | plugins/base/src/main/kotlin/translators/documentables/briefFromContentNodes.kt | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/plugins/base/src/main/kotlin/translators/documentables/briefFromContentNodes.kt b/plugins/base/src/main/kotlin/translators/documentables/briefFromContentNodes.kt index ca66c1a8..7ac6763d 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/briefFromContentNodes.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/briefFromContentNodes.kt @@ -1,16 +1,20 @@ package org.jetbrains.dokka.base.translators.documentables -import org.jetbrains.dokka.pages.ContentGroup -import org.jetbrains.dokka.pages.ContentNode -import org.jetbrains.dokka.pages.ContentText -import org.jetbrains.dokka.pages.TextStyle +import org.jetbrains.dokka.model.withDescendants +import org.jetbrains.dokka.pages.* +import org.jetbrains.kotlin.utils.addToStdlib.safeAs fun briefFromContentNodes(description: List<ContentNode>): List<ContentNode> { val firstSentenceRegex = """^((?:[^.?!]|[.!?](?!\s))*[.!?])""".toRegex() + //Description that is entirely based on html content. In html it is hard to define a brief so we render all of it + if(description.all { it.withDescendants().all { it is ContentGroup || it.safeAs<ContentText>()?.isHtml == true } }){ + return description + } + var sentenceFound = false fun lookthrough(node: ContentNode): ContentNode = - if (node is ContentText && firstSentenceRegex.containsMatchIn(node.text)) { + if (node is ContentText && !node.isHtml && firstSentenceRegex.containsMatchIn(node.text)) { sentenceFound = true node.copy(text = firstSentenceRegex.find(node.text)?.value.orEmpty()) } else if (node is ContentGroup) { @@ -24,3 +28,6 @@ fun briefFromContentNodes(description: List<ContentNode>): List<ContentNode> { if (!sentenceFound) lookthrough(it) else null } } + +private val ContentText.isHtml + get() = extra[HtmlContent] != null |