diff options
author | Mike Sinkovsky <msink@users.noreply.github.com> | 2021-06-26 01:29:17 +0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-25 22:29:17 +0200 |
commit | 46b33710df5418fd3b668ea0753a8bd72f63c406 (patch) | |
tree | 4100d599be82488d78f6f27720bccec37e4ac397 /core/src | |
parent | c2182b766a65619c859c0fc871a8a6334d66f199 (diff) | |
download | dokka-46b33710df5418fd3b668ea0753a8bd72f63c406.tar.gz dokka-46b33710df5418fd3b668ea0753a8bd72f63c406.tar.bz2 dokka-46b33710df5418fd3b668ea0753a8bd72f63c406.zip |
Cleanup paragraphs and tables in GFM renderer (#1946)
* GFM renderer: cleanup paragraphs
* GFM renderer: cleanup tables
* GFM renderer: add tests for wrong header in table
Table with extra cell in row is really generated by `all-modules-page` plugin
* Remove commented-out lines
* Add BriefCommentPreprocessor which inserts a line break between a signature and a brief comment
Fixed a bug with `mapTransform` function which replaces table headers with their contents
Co-authored-by: Kamil Doległo <kamil.doleglo@interia.pl>
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/pages/utils.kt | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/core/src/main/kotlin/pages/utils.kt b/core/src/main/kotlin/pages/utils.kt index c9039416..4afc0a26 100644 --- a/core/src/main/kotlin/pages/utils.kt +++ b/core/src/main/kotlin/pages/utils.kt @@ -5,6 +5,9 @@ import kotlin.reflect.KClass inline fun <reified T : ContentNode, R : ContentNode> R.mapTransform(noinline operation: (T) -> T): R = mapTransform(T::class, operation) +inline fun <reified T : ContentNode, R : ContentNode> R.recursiveMapTransform(noinline operation: (T) -> T): R = + recursiveMapTransform(T::class, operation) + @PublishedApi @Suppress("UNCHECKED_CAST") internal fun <T : ContentNode, R : ContentNode> R.mapTransform(type: KClass<T>, operation: (T) -> T): R { @@ -12,20 +15,45 @@ internal fun <T : ContentNode, R : ContentNode> R.mapTransform(type: KClass<T>, return operation(this as T) as R } val new = when (this) { - is ContentGroup -> this.copy(children.map { it.mapTransform(type, operation) }) - is ContentHeader -> this.copy(children.map { it.mapTransform(type, operation) }) - is ContentCodeBlock -> this.copy(children.map { it.mapTransform(type, operation) }) - is ContentCodeInline -> this.copy(children.map { it.mapTransform(type, operation) }) - is ContentTable -> this.copy(children.map { it.mapTransform(type, operation) }) - is ContentList -> this.copy(children.map { it.mapTransform(type, operation) }) - is ContentDivergentGroup -> this.copy(children.map { it.mapTransform(type, operation) }) - is ContentDivergentInstance -> this.copy( + is ContentGroup -> copy(children = children.map { it.mapTransform(type, operation) }) + is ContentHeader -> copy(children = children.map { it.mapTransform(type, operation) }) + is ContentCodeBlock -> copy(children = children.map { it.mapTransform(type, operation) }) + is ContentCodeInline -> copy(children = children.map { it.mapTransform(type, operation) }) + is ContentTable -> copy(header = header.map { it.recursiveMapTransform(type, operation) }, children = children.map { it.recursiveMapTransform(type, operation) }) + is ContentList -> copy(children = children.map { it.mapTransform(type, operation) }) + is ContentDivergentGroup -> copy(children = children.map { it.mapTransform(type, operation) }) + is ContentDivergentInstance -> copy( before = before?.mapTransform(type, operation), divergent = divergent.mapTransform(type, operation), after = after?.mapTransform(type, operation) ) - is PlatformHintedContent -> this.copy(inner.mapTransform(type, operation)) + is PlatformHintedContent -> copy(inner = inner.mapTransform(type, operation)) else -> this } return new as R } + +@PublishedApi +@Suppress("UNCHECKED_CAST") +internal fun <T : ContentNode, R : ContentNode> R.recursiveMapTransform(type: KClass<T>, operation: (T) -> T): R { + val new = when (this) { + is ContentGroup -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) + is ContentHeader -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) + is ContentCodeBlock -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) + is ContentCodeInline -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) + is ContentTable -> copy(header = header.map { it.recursiveMapTransform(type, operation) }, children = children.map { it.recursiveMapTransform(type, operation) }) + is ContentList -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) + is ContentDivergentGroup -> copy(children = children.map { it.recursiveMapTransform(type, operation) }) + is ContentDivergentInstance -> copy( + before = before?.recursiveMapTransform(type, operation), + divergent = divergent.recursiveMapTransform(type, operation), + after = after?.recursiveMapTransform(type, operation) + ) + is PlatformHintedContent -> copy(inner = inner.recursiveMapTransform(type, operation)) + else -> this + } + if (new::class == type) { + return operation(new as T) as R + } + return new as R +} |