From c09bde34ff729ef9b1f3bea602fb53cd4e6dca42 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Fri, 13 Mar 2020 10:46:33 +0100 Subject: Gradle Task supporting multimodular projects --- plugins/jekyll/build.gradle.kts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 plugins/jekyll/build.gradle.kts (limited to 'plugins/jekyll/build.gradle.kts') diff --git a/plugins/jekyll/build.gradle.kts b/plugins/jekyll/build.gradle.kts new file mode 100644 index 00000000..535a0aef --- /dev/null +++ b/plugins/jekyll/build.gradle.kts @@ -0,0 +1,8 @@ +publishing { + publications { + register("jekyll-plugin") { + artifactId = "jekyll-plugin" + from(components["java"]) + } + } +} \ No newline at end of file -- cgit From 10e8dc85946aabf797d73552e0bc98330764ba3f Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Tue, 31 Mar 2020 13:33:31 +0200 Subject: Fixes problems with Markdown and Jekyll --- .../resolvers/local/DefaultLocationProvider.kt | 2 +- plugins/gfm/build.gradle.kts | 8 +- plugins/gfm/src/main/kotlin/GfmPlugin.kt | 42 ++++-- plugins/jekyll/build.gradle.kts | 7 +- plugins/jekyll/src/main/kotlin/JekyllPlugin.kt | 158 +-------------------- settings.gradle.kts | 2 + 6 files changed, 46 insertions(+), 173 deletions(-) (limited to 'plugins/jekyll/build.gradle.kts') diff --git a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt index 736367a9..29c4a425 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt @@ -21,7 +21,7 @@ open class DefaultLocationProvider( protected val pageGraphRoot: RootPageNode, protected val dokkaContext: DokkaContext ) : LocationProvider { - protected val extension = ".html" + protected open val extension = ".html" protected val externalLocationProviderFactories = dokkaContext.plugin().query { externalLocationProviderFactory } diff --git a/plugins/gfm/build.gradle.kts b/plugins/gfm/build.gradle.kts index c327b96c..c0226345 100644 --- a/plugins/gfm/build.gradle.kts +++ b/plugins/gfm/build.gradle.kts @@ -1,8 +1,12 @@ publishing { publications { - register("gfm-plugin") { + register("gfmPlugin") { artifactId = "gfm-plugin" from(components["java"]) } } -} \ No newline at end of file +} + +dependencies { + implementation(project(":plugins:base")) +} diff --git a/plugins/gfm/src/main/kotlin/GfmPlugin.kt b/plugins/gfm/src/main/kotlin/GfmPlugin.kt index 64a2cdfc..7c0ce509 100644 --- a/plugins/gfm/src/main/kotlin/GfmPlugin.kt +++ b/plugins/gfm/src/main/kotlin/GfmPlugin.kt @@ -1,32 +1,31 @@ -package org.jetbrains.dokka.commonmarkrenderer +package org.jetbrains.dokka.gfm import org.jetbrains.dokka.CoreExtensions +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.renderers.DefaultRenderer +import org.jetbrains.dokka.base.renderers.OutputWriter +import org.jetbrains.dokka.base.resolvers.local.DefaultLocationProvider +import org.jetbrains.dokka.base.resolvers.local.LocationProviderFactory import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.DokkaPlugin import java.lang.StringBuilder -class CommonmarkRendererPlugin : DokkaPlugin() { - - val locationProviderFactory by extensionPoint() - val outputWriter by extensionPoint() +class GfmPlugin : DokkaPlugin() { val renderer by extending { - CoreExtensions.renderer providing { CommonmarkRenderer(it.single(outputWriter), it) } + CoreExtensions.renderer providing { CommonmarkRenderer(it) } applyIf { format == "gfm" } } val locationProvider by extending { - locationProviderFactory providing { MarkdownLocationProviderFactory(it) } order { - before(renderer) - } + plugin().locationProviderFactory providing { MarkdownLocationProviderFactory(it) } applyIf { format == "gfm" } } } -class CommonmarkRenderer( - outputWriter: OutputWriter, +open class CommonmarkRenderer( context: DokkaContext -) : DefaultRenderer(outputWriter, context) { +) : DefaultRenderer(context) { override fun StringBuilder.buildHeader(level: Int, content: StringBuilder.() -> Unit) { buildParagraph() append("#".repeat(level) + " ") @@ -84,14 +83,27 @@ class CommonmarkRenderer( append("\n\n") } + override fun StringBuilder.buildPlatformDependent(content: PlatformHintedContent, pageContext: ContentPage) { + val distinct = content.platforms.map { + it to "${StringBuilder().apply {buildContentNode(content.inner, pageContext, it) }.toString()}" + }.groupBy(Pair::second, Pair::first) + + if (distinct.size == 1) + append(distinct.keys.single()) + else + distinct.forEach { text, platforms -> + append(platforms.joinToString(prefix = " [", postfix = "] $text") { it.name }) + } + } + override fun StringBuilder.buildResource(node: ContentEmbeddedResource, pageContext: ContentPage) { append("Resource") } override fun StringBuilder.buildTable(node: ContentTable, pageContext: ContentPage, platformRestriction: PlatformData?) { - val size = node.children.firstOrNull()?.children?.size ?: 0 buildParagraph() + val size = node.children.firstOrNull()?.children?.size ?: 0 if (node.header.size > 0) { node.header.forEach { @@ -116,12 +128,14 @@ class CommonmarkRenderer( } append("|\n") } + + buildParagraph() } override fun StringBuilder.buildText(textNode: ContentText) { val decorators = decorators(textNode.style) append(decorators) - append(textNode.text.escapeIllegalCharacters()) + append(textNode.text.replace(Regex("[<>]"), "")) append(decorators.reversed()) } diff --git a/plugins/jekyll/build.gradle.kts b/plugins/jekyll/build.gradle.kts index 535a0aef..03fcfc58 100644 --- a/plugins/jekyll/build.gradle.kts +++ b/plugins/jekyll/build.gradle.kts @@ -1,8 +1,13 @@ publishing { publications { - register("jekyll-plugin") { + register("jekyllPlugin") { artifactId = "jekyll-plugin" from(components["java"]) } } +} + +dependencies { + implementation(project(":plugins:base")) + implementation(project(":plugins:gfm")) } \ No newline at end of file diff --git a/plugins/jekyll/src/main/kotlin/JekyllPlugin.kt b/plugins/jekyll/src/main/kotlin/JekyllPlugin.kt index 0a0a2cc4..c4f7f2c7 100644 --- a/plugins/jekyll/src/main/kotlin/JekyllPlugin.kt +++ b/plugins/jekyll/src/main/kotlin/JekyllPlugin.kt @@ -1,133 +1,23 @@ package org.jetbrains.dokka.jekyll import org.jetbrains.dokka.CoreExtensions +import org.jetbrains.dokka.gfm.CommonmarkRenderer import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.DokkaPlugin -import org.jetbrains.dokka.plugability.single -import org.jetbrains.dokka.renderers.DefaultRenderer -import org.jetbrains.dokka.renderers.OutputWriter -import org.jetbrains.dokka.resolvers.DefaultLocationProvider -import org.jetbrains.dokka.resolvers.LocationProvider -import org.jetbrains.dokka.resolvers.LocationProviderFactory import java.lang.StringBuilder class JekyllPlugin : DokkaPlugin() { val renderer by extending { - CoreExtensions.renderer providing { JekyllRenderer(it.single(CoreExtensions.outputWriter), it) } + CoreExtensions.renderer providing { JekyllRenderer(it) } applyIf { format == "jekyll" } } } class JekyllRenderer( - outputWriter: OutputWriter, context: DokkaContext -) : DefaultRenderer(outputWriter, context) { - override fun StringBuilder.buildHeader(level: Int, content: StringBuilder.() -> Unit) { - buildParagraph() - append("${"#".repeat(level)} ") - content() - buildNewLine() - } - - override fun StringBuilder.buildLink(address: String, content: StringBuilder.() -> Unit) { - append("[") - content() - append("]($address)") - } - - override fun StringBuilder.buildList(node: ContentList, pageContext: ContentPage) { - buildListLevel(node, pageContext) - buildParagraph() - } - - private val indent = " ".repeat(4) - - private fun StringBuilder.buildListItem(items: List, pageContext: ContentPage, bullet: String = "*") { - items.forEach { - if(it is ContentList) { - val builder = StringBuilder() - builder.append(indent) - builder.buildListLevel(it, pageContext) - append(builder.toString().replace(Regex(" \n(?!$)"), " \n$indent")) - } else { - append("$bullet ") - it.build(this, pageContext) - buildNewLine() - } - } - } - - private fun StringBuilder.buildListLevel(node: ContentList, pageContext: ContentPage) { - if(node.ordered) { - buildListItem(node.children, pageContext, "${node.start}.") - } else { - buildListItem(node.children, pageContext, "*") - } - } - - override fun StringBuilder.buildNewLine() { - this.append(" \n") - } - - fun StringBuilder.buildParagraph() { - this.append("\n\n") - } - - override fun StringBuilder.buildResource(node: ContentEmbeddedResource, pageContext: ContentPage) { - this.append("Resource") - } - - override fun StringBuilder.buildTable(node: ContentTable, pageContext: ContentPage) { - - buildParagraph() - - val size = node.children.firstOrNull()?.children?.size ?: 0 - - if(node.header.size > 0) { - node.header.forEach { - it.children.forEach { - append("| ") - it.build(this, pageContext) - } - append("|\n") - } - } else { - append("| ".repeat(size)) - if(size > 0) append("|\n") - } - - append("|---".repeat(size)) - if(size > 0) append("|\n") - - - node.children.forEach { - it.children.forEach { - append("| ") - it.build(this, pageContext) - } - append("|\n") - } - - buildParagraph() - } - - override fun StringBuilder.buildText(textNode: ContentText) { - val decorators = decorators(textNode.style) - this.append(decorators) - this.append(textNode.text.replace(Regex("[<>]"), "")) - this.append(decorators.reversed()) - } - - override fun StringBuilder.buildNavigation(page: PageNode) { - locationProvider.ancestors(page).asReversed().forEach { node -> - append("/") - if (node.isNavigable) buildLink(node, page) - else append(node.name) - } - buildParagraph() - } +) : CommonmarkRenderer(context) { override fun buildPage(page: ContentPage, content: (StringBuilder, ContentPage) -> Unit): String { val builder = StringBuilder() @@ -137,46 +27,4 @@ class JekyllRenderer( content(builder, page) return builder.toString() } - - override fun buildError(node: ContentNode) { - println("Error") - } - - private fun decorators(styles: Set