aboutsummaryrefslogtreecommitdiff
path: root/plugins/gfm/src/main/kotlin
diff options
context:
space:
mode:
authorAndrzej Ratajczak <andrzej.ratajczak98@gmail.com>2020-03-31 13:33:31 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-04-01 11:02:45 +0200
commit10e8dc85946aabf797d73552e0bc98330764ba3f (patch)
tree7175ae51e36f5816f5de4df2842255b77d91e34f /plugins/gfm/src/main/kotlin
parentd9af94f2b26d54c88fb0696560de166af9df3d65 (diff)
downloaddokka-10e8dc85946aabf797d73552e0bc98330764ba3f.tar.gz
dokka-10e8dc85946aabf797d73552e0bc98330764ba3f.tar.bz2
dokka-10e8dc85946aabf797d73552e0bc98330764ba3f.zip
Fixes problems with Markdown and Jekyll
Diffstat (limited to 'plugins/gfm/src/main/kotlin')
-rw-r--r--plugins/gfm/src/main/kotlin/GfmPlugin.kt42
1 files changed, 28 insertions, 14 deletions
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<LocationProviderFactory>()
- val outputWriter by extensionPoint<OutputWriter>()
+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<DokkaBase>().locationProviderFactory providing { MarkdownLocationProviderFactory(it) } applyIf { format == "gfm" }
}
}
-class CommonmarkRenderer(
- outputWriter: OutputWriter,
+open class CommonmarkRenderer(
context: DokkaContext
-) : DefaultRenderer<StringBuilder>(outputWriter, context) {
+) : DefaultRenderer<StringBuilder>(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<PlatformData, String>::second, Pair<PlatformData, String>::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())
}