From d4e70e113ac093bdd35edd9c112b4a0addc78ab5 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Mon, 31 May 2021 13:33:48 +0200 Subject: Fix rendering html in briefs (#1931) --- .../translators/documentables/briefFromContentNodes.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'plugins/base/src/main/kotlin/translators/documentables') 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): List { 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()?.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): List { if (!sentenceFound) lookthrough(it) else null } } + +private val ContentText.isHtml + get() = extra[HtmlContent] != null -- cgit