diff options
Diffstat (limited to 'plugins/base/src/main/kotlin')
3 files changed, 32 insertions, 6 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 93a20157..01f4ed6d 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -633,7 +633,7 @@ open class HtmlRenderer( consumer.onTagContentEntity(Entities.nbsp) text(textNode.text) } - textNode.hasStyle(TextStyle.Cover) -> buildBreakableDotSeparatedHtml(textNode.text) + textNode.hasStyle(TextStyle.Cover) -> buildBreakableText(textNode.text) else -> text(textNode.text) } diff --git a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt index 24065e57..bc414e23 100644 --- a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt +++ b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt @@ -26,7 +26,7 @@ class NavigationPage(val root: NavigationNode) : RendererSpecificPage { id = navId attributes["pageId"] = node.dri.toString() div("overview") { - buildLink(node.dri, node.sourceSets.toList()) { buildBreakableDotSeparatedHtml(node.name) } + buildLink(node.dri, node.sourceSets.toList()) { buildBreakableText(node.name) } if (node.children.isNotEmpty()) { span("navButton pull-right") { onClick = """document.getElementById("$navId").classList.toggle("hidden");""" diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt b/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt index 1102b86d..65bf59fa 100644 --- a/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt +++ b/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt @@ -3,15 +3,41 @@ package org.jetbrains.dokka.base.renderers.html import kotlinx.html.FlowContent import kotlinx.html.span +fun FlowContent.buildTextBreakableAfterCapitalLetters(name: String) { + if (name.contains(" ")) { + val withOutSpaces = name.split(" ") + withOutSpaces.dropLast(1).forEach { + buildBreakableText(it) + +" " + } + buildBreakableText(withOutSpaces.last()) + } else { + val content = name.replace(Regex("(?!^)([A-Z])"), " $1").split(" ") + joinToHtml(content){ + it + } + } +} + fun FlowContent.buildBreakableDotSeparatedHtml(name: String) { val phrases = name.split(".") - phrases.dropLast(1).forEach { + joinToHtml(phrases){ + "$it." + } +} + +private fun FlowContent.joinToHtml(elements: List<String>, onEach: (String) -> String) { + elements.dropLast(1).forEach { span { - +"$it." + +onEach(it) } wbr { } } span { - +phrases.last() + +elements.last() } -}
\ No newline at end of file +} + +fun FlowContent.buildBreakableText(name: String) = + if (name.contains(".")) buildBreakableDotSeparatedHtml(name) + else buildTextBreakableAfterCapitalLetters(name)
\ No newline at end of file |