aboutsummaryrefslogtreecommitdiff
path: root/plugins/gfm/src/main/kotlin
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2020-11-20 17:23:10 +0100
committerBłażej Kardyś <bkardys@virtuslab.com>2020-11-27 03:15:02 +0100
commit3cb4702a68139788de6e1f7b087ced345f2b71ba (patch)
treea383471c9915ae4aaff078b4f3b81bb99a4fde35 /plugins/gfm/src/main/kotlin
parent076a5f421c5e4621539efd814be612f43fef33f5 (diff)
downloaddokka-3cb4702a68139788de6e1f7b087ced345f2b71ba.tar.gz
dokka-3cb4702a68139788de6e1f7b087ced345f2b71ba.tar.bz2
dokka-3cb4702a68139788de6e1f7b087ced345f2b71ba.zip
Changing how multimodule location provider works and improving gfm link substitution
Diffstat (limited to 'plugins/gfm/src/main/kotlin')
-rw-r--r--plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/GfmPlugin.kt4
-rw-r--r--plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/gfmTemplating.kt15
-rw-r--r--plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/location/MarkdownLocationProvider.kt12
-rw-r--r--plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/CommonmarkRenderer.kt15
4 files changed, 32 insertions, 14 deletions
diff --git a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/GfmPlugin.kt b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/GfmPlugin.kt
index 3f2eae4d..4ca639b2 100644
--- a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/GfmPlugin.kt
+++ b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/GfmPlugin.kt
@@ -5,7 +5,7 @@ import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.renderers.PackageListCreator
import org.jetbrains.dokka.base.renderers.RootCreator
import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat
-import org.jetbrains.dokka.gfm.location.MarkdownLocationProviderFactory
+import org.jetbrains.dokka.gfm.location.MarkdownLocationProvider
import org.jetbrains.dokka.gfm.renderer.CommonmarkRenderer
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.transformers.pages.PageTransformer
@@ -21,7 +21,7 @@ class GfmPlugin : DokkaPlugin() {
}
val locationProvider by extending {
- dokkaBase.locationProviderFactory providing ::MarkdownLocationProviderFactory override dokkaBase.locationProvider
+ dokkaBase.locationProviderFactory providing MarkdownLocationProvider::Factory override dokkaBase.locationProvider
}
val rootCreator by extending {
diff --git a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/gfmTemplating.kt b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/gfmTemplating.kt
index 1473ceee..4fa6a36e 100644
--- a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/gfmTemplating.kt
+++ b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/gfmTemplating.kt
@@ -9,11 +9,20 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo.Id.CLASS
sealed class GfmCommand {
companion object {
private const val delimiter = "\u1680"
- fun templateCommand(command: GfmCommand): String = "$delimiter GfmCommand ${toJsonString(command)}$delimiter"
- val templateCommandRegex: Regex = Regex("$delimiter GfmCommand ([^$delimiter ]*)$delimiter")
+ val templateCommandRegex: Regex =
+ Regex("<!---$delimiter GfmCommand ([^$delimiter ]*)$delimiter--->(.+?)(?=<!---$delimiter)<!---$delimiter--->")
+ val MatchResult.command
+ get() = groupValues[1]
+ val MatchResult.label
+ get() = groupValues[2]
+ fun Appendable.templateCommand(command: GfmCommand, content: Appendable.() -> Unit): Unit {
+ append("<!---$delimiter GfmCommand ${toJsonString(command)}$delimiter--->")
+ content()
+ append("<!---$delimiter--->")
+ }
}
}
-class ResolveLinkGfmCommand(val dri: DRI): GfmCommand()
+class ResolveLinkGfmCommand(val dri: DRI) : GfmCommand()
diff --git a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/location/MarkdownLocationProvider.kt b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/location/MarkdownLocationProvider.kt
index 6f96dbd5..bd789464 100644
--- a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/location/MarkdownLocationProvider.kt
+++ b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/location/MarkdownLocationProvider.kt
@@ -5,12 +5,14 @@ import org.jetbrains.dokka.base.resolvers.local.LocationProviderFactory
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
-class MarkdownLocationProviderFactory(val context: DokkaContext) : LocationProviderFactory {
- override fun getLocationProvider(pageNode: RootPageNode) = MarkdownLocationProvider(pageNode, context)
-}
-
class MarkdownLocationProvider(
pageGraphRoot: RootPageNode,
dokkaContext: DokkaContext
-) : DokkaLocationProvider(pageGraphRoot, dokkaContext, ".md")
+) : DokkaLocationProvider(pageGraphRoot, dokkaContext, ".md") {
+
+ class Factory(private val context: DokkaContext) : LocationProviderFactory {
+ override fun getLocationProvider(pageNode: RootPageNode) =
+ MarkdownLocationProvider(pageNode, context)
+ }
+}
diff --git a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/CommonmarkRenderer.kt b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/CommonmarkRenderer.kt
index 25b24f0c..9fb92272 100644
--- a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/CommonmarkRenderer.kt
+++ b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/CommonmarkRenderer.kt
@@ -18,6 +18,8 @@ open class CommonmarkRenderer(
override val preprocessors = context.plugin<GfmPlugin>().query { gfmPreprocessors }
+ private val isPartial = context.configuration.delayTemplateSubstitution
+
override fun StringBuilder.wrapGroup(
node: ContentGroup,
pageContext: ContentPage,
@@ -87,10 +89,15 @@ open class CommonmarkRenderer(
pageContext: ContentPage,
sourceSetRestriction: Set<DisplaySourceSet>?
) {
- val address = locationProvider.resolve(node.address, node.sourceSets, pageContext)
- buildLink(address ?: templateCommand(ResolveLinkGfmCommand(node.address))) {
- buildText(node.children, pageContext, sourceSetRestriction)
- }
+ locationProvider.resolve(node.address, node.sourceSets, pageContext)?.let {
+ buildLink(it) {
+ buildText(node.children, pageContext, sourceSetRestriction)
+ }
+ } ?: if (isPartial) {
+ templateCommand(ResolveLinkGfmCommand(node.address)) {
+ buildText(node.children, pageContext, sourceSetRestriction)
+ }
+ } else Unit
}
override fun StringBuilder.buildNewLine() {