diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-08-25 09:41:01 +0200 |
---|---|---|
committer | Marcin Aman <marcin.aman@gmail.com> | 2021-08-25 09:41:01 +0200 |
commit | 3d416fec95e741289b02bf4a4b2e0fdf06de0aea (patch) | |
tree | e65f0a0a84c3a380d8d20f7ee5bd7f1ec05100bb | |
parent | 9044761979d08b3b116c9f8416dfb42ae216898c (diff) | |
download | dokka-3d416fec95e741289b02bf4a4b2e0fdf06de0aea.tar.gz dokka-3d416fec95e741289b02bf4a4b2e0fdf06de0aea.tar.bz2 dokka-3d416fec95e741289b02bf4a4b2e0fdf06de0aea.zip |
Fix breakable labels and icon on single module project
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() |