From bb712835958c823e06db8c39c0a1d32493f095b8 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Thu, 22 Jul 2021 14:29:25 +0200 Subject: Fix overflow in throws tables (#2028) --- .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 3 +- .../kotlin/renderers/html/htmlFormatingUtils.kt | 32 ++++++++++++++++------ .../documentables/DefaultPageCreator.kt | 4 +-- 3 files changed, 28 insertions(+), 11 deletions(-) (limited to 'plugins/base/src/main') diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index a6eec0b9..d63e8da6 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -714,13 +714,14 @@ open class HtmlRenderer( consumer.onTagContentEntity(Entities.nbsp) buildText(textNode, unappliedStyles - TextStyle.Indented) } - unappliedStyles.size == 1 && unappliedStyles.contains(TextStyle.Cover) -> buildBreakableText(textNode.text) unappliedStyles.isNotEmpty() -> { val styleToApply = unappliedStyles.first() applyStyle(styleToApply){ buildText(textNode, unappliedStyles - styleToApply) } } + textNode.hasStyle(ContentStyle.RowTitle) || textNode.hasStyle(TextStyle.Cover) -> + buildBreakableText(textNode.text) else -> text(textNode.text) } } diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt b/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt index 65bf59fa..b9eab293 100644 --- a/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt +++ b/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt @@ -13,7 +13,7 @@ fun FlowContent.buildTextBreakableAfterCapitalLetters(name: String) { buildBreakableText(withOutSpaces.last()) } else { val content = name.replace(Regex("(?!^)([A-Z])"), " $1").split(" ") - joinToHtml(content){ + joinToHtml(content) { it } } @@ -21,20 +21,36 @@ fun FlowContent.buildTextBreakableAfterCapitalLetters(name: String) { fun FlowContent.buildBreakableDotSeparatedHtml(name: String) { val phrases = name.split(".") - joinToHtml(phrases){ - "$it." + phrases.forEachIndexed { i, e -> + if (e.length > 10) { + buildBreakableText(e) + } else { + val elementWithOptionalDot = + if (i != phrases.lastIndex) { + "$e." + } else { + e + } + buildBreakableHtmlElement(elementWithOptionalDot) + } } } private fun FlowContent.joinToHtml(elements: List, onEach: (String) -> String) { elements.dropLast(1).forEach { - span { - +onEach(it) - } - wbr { } + buildBreakableHtmlElement(onEach(it)) } span { - +elements.last() + buildBreakableHtmlElement(elements.last(), last = true) + } +} + +private fun FlowContent.buildBreakableHtmlElement(element: String, last: Boolean = false) { + span { + +element + } + if (!last) { + wbr { } } } diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index c611927c..61fbd7d2 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -452,7 +452,7 @@ open class DefaultPageCreator( fun DocumentableContentBuilder.contentForThrows() { val throws = tags.withTypeNamed() if (throws.isNotEmpty()) { - header(4, "Throws") + header(2, "Throws") sourceSetDependentHint(sourceSets = platforms.toSet(), kind = ContentKind.SourceSetDependentHint) { platforms.forEach { sourceset -> table(kind = ContentKind.Main, sourceSets = setOf(sourceset)) { @@ -615,7 +615,7 @@ open class DefaultPageCreator( styles = emptySet(), extra = elementName?.let { name -> extra + SymbolAnchorHint(name, kind) } ?: extra ) { - link(elementName.orEmpty(), elements.first().dri, kind = kind) + link(elementName.orEmpty(), elements.first().dri, kind = kind, styles = setOf(ContentStyle.RowTitle)) divergentGroup( ContentDivergentGroup.GroupID(name), elements.map { it.dri }.toSet(), -- cgit