aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt')
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt34
1 files changed, 30 insertions, 4 deletions
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