aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt8
-rw-r--r--plugins/gfm/src/main/kotlin/GfmPlugin.kt43
-rw-r--r--plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt22
-rw-r--r--plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt14
4 files changed, 47 insertions, 40 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
index ebfcf864..75fbb187 100644
--- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
@@ -175,7 +175,7 @@ abstract class DefaultRenderer<T>(
pageContext: ContentPage,
beforeTransformer: (ContentDivergentInstance, ContentPage, DokkaSourceSet) -> String,
afterTransformer: (ContentDivergentInstance, ContentPage, DokkaSourceSet) -> String
- ): Map<SerializedInstanceWithSource, List<InstanceWithSource>> =
+ ): Map<SerializedBeforeAndAfter, List<InstanceWithSource>> =
children.flatMap { instance ->
instance.sourceSets.map { sourceSet ->
Pair(instance, sourceSet) to Pair(
@@ -184,12 +184,12 @@ abstract class DefaultRenderer<T>(
)
}
}.groupBy(
- Pair<Pair<ContentDivergentInstance, DokkaSourceSet>, Pair<String, String>>::second,
- Pair<Pair<ContentDivergentInstance, DokkaSourceSet>, Pair<String, String>>::first
+ Pair<InstanceWithSource, SerializedBeforeAndAfter>::second,
+ Pair<InstanceWithSource, SerializedBeforeAndAfter>::first
)
}
-internal typealias SerializedInstanceWithSource = Pair<String, String>
+internal typealias SerializedBeforeAndAfter = Pair<String, String>
internal typealias InstanceWithSource = Pair<ContentDivergentInstance, DokkaSourceSet>
fun ContentPage.sourceSets() = this.content.sourceSets \ No newline at end of file
diff --git a/plugins/gfm/src/main/kotlin/GfmPlugin.kt b/plugins/gfm/src/main/kotlin/GfmPlugin.kt
index df9d032f..6774e31b 100644
--- a/plugins/gfm/src/main/kotlin/GfmPlugin.kt
+++ b/plugins/gfm/src/main/kotlin/GfmPlugin.kt
@@ -98,7 +98,7 @@ open class CommonmarkRenderer(
buildList(it, pageContext)
} else {
append("<li>")
- it.build(this, pageContext)
+ append(buildString { it.build(this, pageContext, it.sourceSets) }.trim())
append("</li>")
}
}
@@ -138,7 +138,7 @@ open class CommonmarkRenderer(
pageContext: ContentPage,
) {
if (content is ContentGroup && content.children.firstOrNull { it is ContentTable } != null) {
- buildContentNode(content, pageContext)
+ buildContentNode(content, pageContext, sourceSets)
} else {
val distinct = sourceSets.map {
it to buildString { buildContentNode(content, pageContext, setOf(it)) }
@@ -149,7 +149,7 @@ open class CommonmarkRenderer(
platforms.joinToString(
prefix = " [",
postfix = "] $text "
- ) { "${it.moduleDisplayName}/${it.displayName}" })
+ ) { it.displayName })
buildNewLine()
}
}
@@ -166,7 +166,7 @@ open class CommonmarkRenderer(
) {
if (node.dci.kind == ContentKind.Sample || node.dci.kind == ContentKind.Parameters) {
node.sourceSets.forEach { sourcesetData ->
- append("${sourcesetData.moduleDisplayName}/${sourcesetData.displayName}")
+ append(sourcesetData.displayName)
buildNewLine()
buildTable(
node.copy(
@@ -184,7 +184,7 @@ open class CommonmarkRenderer(
node.header.forEach {
it.children.forEach {
append(" ")
- it.build(this, pageContext)
+ it.build(this, pageContext, it.sourceSets)
}
append("| ")
}
@@ -201,7 +201,7 @@ open class CommonmarkRenderer(
val builder = StringBuilder()
it.children.forEach {
builder.append("| ")
- it.build(builder, pageContext)
+ builder.append(buildString { it.build(this, pageContext) }.replace(Regex("#+ "), "") ) // Workaround for headers inside tables
}
append(builder.toString().withEntersAsHtml())
append(" | ".repeat(size - it.children.size))
@@ -211,10 +211,14 @@ open class CommonmarkRenderer(
}
override fun StringBuilder.buildText(textNode: ContentText) {
- val decorators = decorators(textNode.style)
- append(decorators)
- append(textNode.text)
- append(decorators.reversed())
+ if(textNode.text.isNotBlank()) {
+ val decorators = decorators(textNode.style)
+ append(textNode.text.takeWhile { it == ' ' } )
+ append(decorators)
+ append(textNode.text.trim())
+ append(decorators.reversed())
+ append(textNode.text.takeLastWhile { it == ' ' })
+ }
}
override fun StringBuilder.buildNavigation(page: PageNode) {
@@ -251,33 +255,36 @@ open class CommonmarkRenderer(
distinct.values.forEach { entry ->
val (instance, sourceSets) = entry.getInstanceAndSourceSets()
- append(sourceSets.joinToString(prefix = "#### [", postfix = "]") { "${it.moduleDisplayName}/${it.displayName}" })
+ append(sourceSets.joinToString(prefix = "[", postfix = "]") { it.displayName })
buildNewLine()
instance.before?.let {
- append("##### Brief description")
+ append("Brief description")
buildNewLine()
- buildContentNode(it, pageContext)
+ buildContentNode(it, pageContext, setOf(sourceSets.first())) // It's workaround to render content only once
buildNewLine()
}
- append("##### Content")
+ append("Content")
buildNewLine()
entry.groupBy { buildString { buildContentNode(it.first.divergent, pageContext, setOf(it.second)) } }
.values.forEach { innerEntry ->
val (innerInstance, innerSourceSets) = innerEntry.getInstanceAndSourceSets()
if(sourceSets.size > 1) {
- append(innerSourceSets.joinToString(prefix = "###### [", postfix = "]") { "${it.moduleDisplayName}/${it.displayName}" })
+ append(innerSourceSets.joinToString(prefix = "[", postfix = "]") { it.displayName })
buildNewLine()
}
- innerInstance.divergent.build(this@buildDivergent, pageContext)
+ innerInstance.divergent.build(this@buildDivergent, pageContext, setOf(innerSourceSets.first())) // It's workaround to render content only once
buildNewLine()
}
+
instance.after?.let {
- append("##### More info")
+ append("More info")
buildNewLine()
- buildContentNode(it, pageContext)
+ buildContentNode(it, pageContext, setOf(sourceSets.first())) // It's workaround to render content only once
buildNewLine()
}
+
+ buildParagraph()
}
}
diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt
index 634f427a..0c8b942e 100644
--- a/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt
+++ b/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt
@@ -44,7 +44,7 @@ class DivergentTest : GfmRenderingOnlyTestBase() {
}
}
}
- val expect = "//[testPage](test-page.md)\n\n#### [root/js] \n##### Content \na \n"
+ val expect = "//[testPage](test-page.md)\n\n[js] \nContent \na \n\n\n"
CommonmarkRenderer(context).render(page)
assert(renderedContent == expect)
}
@@ -60,7 +60,7 @@ class DivergentTest : GfmRenderingOnlyTestBase() {
}
}
}
- val expect = "//[testPage](test-page.md)\n\n#### [root/js] \n##### Content \na \n"
+ val expect = "//[testPage](test-page.md)\n\n[js] \nContent \na \n\n\n"
CommonmarkRenderer(context).render(page)
assert(renderedContent == expect)
}
@@ -86,7 +86,7 @@ class DivergentTest : GfmRenderingOnlyTestBase() {
}
}
}
- val expect = "//[testPage](test-page.md)\n\n#### [root/js, root/jvm, root/native] \n##### Content \n###### [root/js] \na \n###### [root/jvm] \nb \n###### [root/native] \nc \n"
+ val expect = "//[testPage](test-page.md)\n\n[js, jvm, native] \nContent \n[js] \na \n[jvm] \nb \n[native] \nc \n\n\n"
CommonmarkRenderer(context).render(page)
assert(renderedContent == expect)
}
@@ -112,7 +112,7 @@ class DivergentTest : GfmRenderingOnlyTestBase() {
}
}
}
- val expect = "//[testPage](test-page.md)\n\n#### [root/js] \n##### Content \na \nb \nc \n"
+ val expect = "//[testPage](test-page.md)\n\n[js] \nContent \na \nb \nc \n\n\n"
CommonmarkRenderer(context).render(page)
assert(renderedContent == expect)
}
@@ -148,7 +148,7 @@ class DivergentTest : GfmRenderingOnlyTestBase() {
}
}
}
- val expect = "//[testPage](test-page.md)\n\n#### [root/native, root/js, root/jvm] \n##### Content \n###### [root/native] \na \n###### [root/js] \nb \n###### [root/jvm] \nc \n###### [root/js] \nd \n###### [root/native] \ne \n"
+ val expect = "//[testPage](test-page.md)\n\n[native, js, jvm] \nContent \n[native] \na \n[js] \nb \n[jvm] \nc \n[js] \nd \n[native] \ne \n\n\n"
CommonmarkRenderer(context).render(page)
assert(renderedContent == expect)
}
@@ -196,7 +196,7 @@ class DivergentTest : GfmRenderingOnlyTestBase() {
}
}
}
- val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Content \na \n##### More info \na+ \n#### [root/js] \n##### Content \nb \nd \n##### More info \nbd+ \n#### [root/jvm] \n##### Content \nc \n#### [root/native] \n##### Content \ne \n##### More info \ne+ \n"
+ val expect = "//[testPage](test-page.md)\n\n[native] \nContent \na \nMore info \na+ \n\n\n[js] \nContent \nb \nd \nMore info \nbd+ \n\n\n[jvm] \nContent \nc \n\n\n[native] \nContent \ne \nMore info \ne+ \n\n\n"
CommonmarkRenderer(context).render(page)
assert(renderedContent == expect)
}
@@ -223,7 +223,7 @@ class DivergentTest : GfmRenderingOnlyTestBase() {
}
}
}
- val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Brief description \nab- \n##### Content \na \nb \n"
+ val expect = "//[testPage](test-page.md)\n\n[native] \nBrief description \nab- \nContent \na \nb \n\n\n"
CommonmarkRenderer(context).render(page)
assert(renderedContent == expect)
}
@@ -250,7 +250,7 @@ class DivergentTest : GfmRenderingOnlyTestBase() {
}
}
}
- val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Content \na \nb \n##### More info \nab+ \n"
+ val expect = "//[testPage](test-page.md)\n\n[native] \nContent \na \nb \nMore info \nab+ \n\n\n"
CommonmarkRenderer(context).render(page)
assert(renderedContent == expect)
}
@@ -283,7 +283,7 @@ class DivergentTest : GfmRenderingOnlyTestBase() {
}
}
}
- val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Brief description \nab- \n##### Content \na \nb \n##### More info \nab+ \n"
+ val expect = "//[testPage](test-page.md)\n\n[native] \nBrief description \nab- \nContent \na \nb \nMore info \nab+ \n\n\n"
CommonmarkRenderer(context).render(page)
assert(renderedContent == expect)
}
@@ -316,7 +316,7 @@ class DivergentTest : GfmRenderingOnlyTestBase() {
}
}
}
- val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Brief description \na- \n##### Content \na \n##### More info \nab+ \n#### [root/native] \n##### Brief description \nb- \n##### Content \nb \n##### More info \nab+ \n"
+ val expect = "//[testPage](test-page.md)\n\n[native] \nBrief description \na- \nContent \na \nMore info \nab+ \n\n\n[native] \nBrief description \nb- \nContent \nb \nMore info \nab+ \n\n\n"
CommonmarkRenderer(context).render(page)
assert(renderedContent == expect)
}
@@ -367,7 +367,7 @@ class DivergentTest : GfmRenderingOnlyTestBase() {
}
}
}
- val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Content \na \n##### More info \na+ \n#### [root/js, root/jvm] \n##### Content \n###### [root/js] \nb \n###### [root/jvm] \nc \n###### [root/js] \nd \n##### More info \nbd+ \n#### [root/native] \n##### Content \ne \n##### More info \ne+ \n"
+ val expect = "//[testPage](test-page.md)\n\n[native] \nContent \na \nMore info \na+ \n\n\n[js, jvm] \nContent \n[js] \nb \n[jvm] \nc \n[js] \nd \nMore info \nbd+ \n\n\n[native] \nContent \ne \nMore info \ne+ \n\n\n"
CommonmarkRenderer(context).render(page)
assert(renderedContent == expect)
}
diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt
index 5807d025..e181e3a2 100644
--- a/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt
+++ b/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt
@@ -44,7 +44,7 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() {
}
CommonmarkRenderer(context).render(page)
- assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2, root/pl3] abc \n \n")
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1, pl2, pl3] abc \n \n")
}
@Test
@@ -58,7 +58,7 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() {
}
CommonmarkRenderer(context).render(page)
- assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1] a \n \n [root/pl2] b \n \n [root/pl3] c \n \n")
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1] a \n \n [pl2] b \n \n [pl3] c \n \n")
}
@Test
@@ -72,7 +72,7 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() {
}
CommonmarkRenderer(context).render(page)
- assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1] ab \n \n [root/pl2] bc \n \n")
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1] ab \n \n [pl2] bc \n \n")
}
@Test
@@ -86,7 +86,7 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() {
}
CommonmarkRenderer(context).render(page)
- assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2] ab \n \n")
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1, pl2] ab \n \n")
}
@Test
@@ -102,7 +102,7 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() {
}
CommonmarkRenderer(context).render(page)
- assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1] ab \n \n \n [root/pl2] a \nb \n \n")
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1] ab \n \n \n [pl2] a \nb \n \n")
}
@Test
@@ -118,7 +118,7 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() {
}
CommonmarkRenderer(context).render(page)
- assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2] ab \n")
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1, pl2] ab \n")
}
@Test
@@ -132,6 +132,6 @@ class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() {
}
CommonmarkRenderer(context).render(page)
- assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2] a \n \n [root/pl3] b \n \n")
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [pl1, pl2] a \n \n [pl3] b \n \n")
}
} \ No newline at end of file