Skip to content

Commit

Permalink
1.5.0-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
msink committed Jun 30, 2021
1 parent bdd5e92 commit 1c930e3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 22 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ plugins {
allprojects {
repositories {
mavenCentral()
mavenLocal()
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object Libui {
}

object Dokka {
const val version = "1.4.32"
const val version = "1.5.0-SNAPSHOT"
}

object Download {
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
pluginManagement {
repositories {
mavenCentral()
mavenLocal()
gradlePluginPortal()
}
}
Expand Down
5 changes: 3 additions & 2 deletions tools/dokka-mygfm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ plugins {

repositories {
mavenCentral()
mavenLocal()
}

dependencies {
compileOnly("org.jetbrains.dokka:dokka-core:1.4.32")
implementation("org.jetbrains.dokka:dokka-base:1.4.32")
compileOnly("org.jetbrains.dokka:dokka-core:1.5.0-SNAPSHOT")
implementation("org.jetbrains.dokka:dokka-base:1.5.0-SNAPSHOT")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.1")
}

Expand Down
67 changes: 48 additions & 19 deletions tools/dokka-mygfm/src/main/kotlin/renderer/CommonmarkRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class CommonmarkRenderer(
return when {
node.hasStyle(TextStyle.Block) -> {
childrenCallback()
buildNewLine()
buildParagraph()
}
node.hasStyle(TextStyle.Paragraph) -> {
buildParagraph()
Expand All @@ -43,7 +43,7 @@ open class CommonmarkRenderer(
buildParagraph()
append("#".repeat(level) + " ")
content()
buildNewLine()
appendNewLine()
}

override fun StringBuilder.buildLink(address: String, content: StringBuilder.() -> Unit) {
Expand Down Expand Up @@ -101,11 +101,17 @@ open class CommonmarkRenderer(
}

override fun StringBuilder.buildNewLine() {
append(" \n")
append("\\")
appendNewLine()
}

private fun StringBuilder.appendNewLine() {
append("\n")
}

private fun StringBuilder.buildParagraph() {
append("\n\n")
appendNewLine()
appendNewLine()
}

override fun StringBuilder.buildPlatformDependent(
Expand All @@ -131,8 +137,8 @@ open class CommonmarkRenderer(
distinct.filter { it.key.isNotBlank() }.forEach { (text, platforms) ->
append(" ")
buildSourceSetTags(platforms.toSet())
append(" $text ")
buildNewLine()
append(" $text")
appendNewLine()
}
}
}
Expand All @@ -149,18 +155,18 @@ open class CommonmarkRenderer(
pageContext: ContentPage,
sourceSetRestriction: Set<DisplaySourceSet>?
) {
buildNewLine()
appendNewLine()
if (node.dci.kind == ContentKind.Sample || node.dci.kind == ContentKind.Parameters) {
node.sourceSets.forEach { sourcesetData ->
append(sourcesetData.name)
buildNewLine()
appendNewLine()
buildTable(
node.copy(
children = node.children.filter { it.sourceSets.contains(sourcesetData) },
dci = node.dci.copy(kind = ContentKind.Main)
), pageContext, sourceSetRestriction
)
buildNewLine()
appendNewLine()
}
} else {
val size = node.header.firstOrNull()?.children?.size ?: node.children.firstOrNull()?.children?.size ?: 0
Expand All @@ -177,11 +183,17 @@ open class CommonmarkRenderer(
}
} else {
append("| ".repeat(size))
if (size > 0) append("|\n")
if (size > 0) {
append("|")
appendNewLine()
}
}

append("|---".repeat(size))
if (size > 0) append("|\n")
if (size > 0) {
append("|")
appendNewLine()
}

node.children.forEach {
val builder = StringBuilder()
Expand Down Expand Up @@ -225,7 +237,7 @@ open class CommonmarkRenderer(
override fun buildPage(page: ContentPage, content: (StringBuilder, ContentPage) -> Unit): String =
buildString {
content(this, page)
}
}.trim().replace("\n[\n]+".toRegex(), "\n\n")

override fun buildError(node: ContentNode) {
context.logger.warn("Markdown renderer has encountered problem. The unmatched node is $node")
Expand All @@ -248,23 +260,24 @@ open class CommonmarkRenderer(
val (instance, sourceSets) = entry.getInstanceAndSourceSets()

buildSourceSetTags(sourceSets)
buildNewLine()

instance.before?.let {
buildNewLine()
append("Brief description")
buildNewLine()
buildContentNode(
it,
pageContext,
sourceSets.first()
) // It's workaround to render content only once
buildNewLine()
}

append("Content")
buildNewLine()
append("Content")
entry.groupBy { buildString { buildContentNode(it.first.divergent, pageContext, setOf(it.second)) } }
.values.forEach { innerEntry ->
val (innerInstance, innerSourceSets) = innerEntry.getInstanceAndSourceSets()
buildNewLine()
if (sourceSets.size > 1) {
buildSourceSetTags(innerSourceSets)
buildNewLine()
Expand All @@ -274,18 +287,17 @@ open class CommonmarkRenderer(
pageContext,
setOf(innerSourceSets.first())
) // It's workaround to render content only once
buildNewLine()
}

instance.after?.let {
buildNewLine()
append("More info")
buildNewLine()
buildContentNode(
it,
pageContext,
sourceSets.first()
) // It's workaround to render content only once
buildNewLine()
}

buildParagraph()
Expand Down Expand Up @@ -318,12 +330,26 @@ open class CommonmarkRenderer(
?: throw DokkaException("Cannot resolve path for ${page.name}")
}

when (page) {
return when (page) {
is ContentPage -> outputWriter.write(path, buildPage(page) { c, p -> buildPageContent(c, p) }, ".md")
is RendererSpecificPage -> when (val strategy = page.strategy) {
is RenderingStrategy.Copy -> outputWriter.writeResources(strategy.from, path)
is RenderingStrategy.Write -> outputWriter.write(path, strategy.text, "")
is RenderingStrategy.Callback -> outputWriter.write(path, strategy.instructions(this, page), ".md")
is RenderingStrategy.DriLocationResolvableWrite -> outputWriter.write(
path,
strategy.contentToResolve { dri, sourcesets ->
locationProvider.resolve(dri, sourcesets)
},
""
)
is RenderingStrategy.PageLocationResolvableWrite -> outputWriter.write(
path,
strategy.contentToResolve { pageToLocate, context ->
locationProvider.resolve(pageToLocate, context)
},
""
)
RenderingStrategy.DoNothing -> Unit
}
else -> throw AssertionError(
Expand All @@ -332,7 +358,10 @@ open class CommonmarkRenderer(
}
}

private fun String.withEntersAsHtml(): String = replace("\n", "<br>")
private fun String.withEntersAsHtml(): String = this
.replace("\\\n", "\n\n")
.replace("\n[\n]+".toRegex(), "<br>")
.replace("\n", " ")

private fun List<Pair<ContentDivergentInstance, DisplaySourceSet>>.getInstanceAndSourceSets() =
this.let { Pair(it.first().first, it.map { it.second }.toSet()) }
Expand Down

0 comments on commit 1c930e3

Please sign in to comment.