aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt4
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt10
-rw-r--r--plugins/base/src/test/kotlin/renderers/html/FormattingUtilsTest.kt38
3 files changed, 43 insertions, 9 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index 362447d1..3086b82d 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -734,8 +734,6 @@ open class HtmlRenderer(
super.render(root)
}
- private fun PageNode.root(path: String) = locationProvider.pathToRoot(this) + path
-
override fun buildPage(page: ContentPage, content: (FlowContent, ContentPage) -> Unit): String =
buildHtml(page, page.embeddedResources) {
div("main-content") {
@@ -755,7 +753,7 @@ open class HtmlRenderer(
meta(name = "viewport", content = "width=device-width, initial-scale=1", charset = "UTF-8")
title(page.name)
templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) {
- link(href = page.root("###images/logo-icon.svg"), rel = "icon", type = "image/svg")
+ link(href = "###images/logo-icon.svg", rel = "icon", type = "image/svg")
}
templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) {
script { unsafe { +"""var pathToRoot = "###";""" } }
diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt b/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt
index d77426da..c77a6e94 100644
--- a/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt
@@ -12,7 +12,7 @@ fun FlowContent.buildTextBreakableAfterCapitalLetters(name: String, hasLastEleme
}
buildBreakableText(withOutSpaces.last())
} else {
- val content = name.replace(Regex("(?!^)([A-Z])"), " $1").split(" ")
+ val content = name.replace(Regex("(?<=[a-z])([A-Z])"), " $1").split(" ")
joinToHtml(content, hasLastElement) {
it
}
@@ -35,13 +35,13 @@ private fun FlowContent.joinToHtml(elements: List<String>, hasLastElement: Boole
elements.dropLast(1).forEach {
buildBreakableHtmlElement(onEach(it))
}
- elements.last().takeIf { it.isNotBlank() }?.let {
+ elements.takeIf { it.isNotEmpty() && it.last().isNotEmpty() }?.let {
if (hasLastElement) {
span {
- buildBreakableHtmlElement(it, last = true)
+ buildBreakableHtmlElement(it.last(), last = true)
}
} else {
- buildBreakableHtmlElement(it, last = false)
+ buildBreakableHtmlElement(it.last(), last = false)
}
}
}
@@ -59,4 +59,4 @@ private fun FlowContent.buildBreakableHtmlElement(element: String, last: Boolean
fun FlowContent.buildBreakableText(name: String) =
if (name.contains(".")) buildBreakableDotSeparatedHtml(name)
- else buildTextBreakableAfterCapitalLetters(name) \ No newline at end of file
+ else buildTextBreakableAfterCapitalLetters(name, hasLastElement = true) \ No newline at end of file
diff --git a/plugins/base/src/test/kotlin/renderers/html/FormattingUtilsTest.kt b/plugins/base/src/test/kotlin/renderers/html/FormattingUtilsTest.kt
index fa1e30f6..c77a78fb 100644
--- a/plugins/base/src/test/kotlin/renderers/html/FormattingUtilsTest.kt
+++ b/plugins/base/src/test/kotlin/renderers/html/FormattingUtilsTest.kt
@@ -31,7 +31,43 @@ class FormattingUtilsTest {
val testedText = "Package org.jetbrains.dokka.it.moduleC"
val expectedHtml = """
<html>
- <body><span>Package</span><wbr></wbr> <span>org.</span><wbr></wbr><span>jetbrains.</span><wbr></wbr><span>dokka.</span><wbr></wbr><span>it.</span><wbr></wbr><span>moduleC</span></body>
+ <body><span><span>Package</span></span> <span>org.</span><wbr></wbr><span>jetbrains.</span><wbr></wbr><span>dokka.</span><wbr></wbr><span>it.</span><wbr></wbr><span>moduleC</span></body>
+ </html>
+ """.trimIndent()
+
+ val html = createHTML(prettyPrint = true).html {
+ body {
+ buildBreakableText(testedText)
+ }
+ }
+
+ assertEquals(expectedHtml.trim(), html.trim())
+ }
+
+ @Test
+ fun `should build breakable text for text with braces`(){
+ val testedText = "[Common]kotlinx.collections.immutable"
+ val expectedHtml = """
+ <html>
+ <body><span>[Common]kotlinx.</span><wbr></wbr><span>collections.</span><wbr></wbr><span>immutable</span></body>
+ </html>
+ """.trimIndent()
+
+ val html = createHTML(prettyPrint = true).html {
+ body {
+ buildBreakableText(testedText)
+ }
+ }
+
+ assertEquals(expectedHtml.trim(), html.trim())
+ }
+
+ @Test
+ fun `should build breakable text for camel case notation`(){
+ val testedText = "DokkkkkkkaIsTheBest"
+ val expectedHtml = """
+ <html>
+ <body><span>Dokkkkkkka</span><wbr></wbr><span>Is</span><wbr></wbr><span>The</span><wbr></wbr><span><span>Best</span></span></body>
</html>
""".trimIndent()