diff options
Diffstat (limited to 'plugins/gfm')
14 files changed, 126 insertions, 116 deletions
diff --git a/plugins/gfm/.DS_Store b/plugins/gfm/.DS_Store Binary files differnew file mode 100644 index 00000000..343f9af6 --- /dev/null +++ b/plugins/gfm/.DS_Store diff --git a/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmAllModulesPagaPlugin.kt b/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmAllModulesPagaPlugin.kt deleted file mode 100644 index eb5e7e45..00000000 --- a/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmAllModulesPagaPlugin.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.jetbrains.dokka.gfm.allModulesPage - -import org.jetbrains.dokka.allModulesPage.AllModulesPagePlugin -import org.jetbrains.dokka.allModulesPage.templates.DefaultTemplateProcessor -import org.jetbrains.dokka.base.DokkaBase -import org.jetbrains.dokka.gfm.GfmPlugin -import org.jetbrains.dokka.plugability.DokkaPlugin - -class GfmAllModulesPagePlugin : DokkaPlugin() { - - private val gfmPlugin by lazy { plugin<GfmPlugin>() } - - private val dokkaBase by lazy { plugin<DokkaBase>() } - - private val allModulesPagePlugin by lazy { plugin<AllModulesPagePlugin>() } - - val locationProvider by extending { - (dokkaBase.locationProviderFactory providing GfmMultimoduleLocationProvider::Factory - override listOf(allModulesPagePlugin.multimoduleLocationProvider, gfmPlugin.locationProvider)) - } - - val defaultTemplateProcessor by extending { - (allModulesPagePlugin.templateProcessingStrategy - providing ::GfmTemplateProcessingStrategy - override allModulesPagePlugin.directiveBasedHtmlTemplateProcessingStrategy - order { before(allModulesPagePlugin.fallbackProcessingStrategy) }) - } -}
\ No newline at end of file diff --git a/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmMultimoduleLocationProvider.kt b/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmMultimoduleLocationProvider.kt deleted file mode 100644 index 9f2ee140..00000000 --- a/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmMultimoduleLocationProvider.kt +++ /dev/null @@ -1,17 +0,0 @@ -package org.jetbrains.dokka.gfm.allModulesPage - -import org.jetbrains.dokka.allModulesPage.MultimoduleLocationProvider -import org.jetbrains.dokka.base.resolvers.local.LocationProviderFactory -import org.jetbrains.dokka.gfm.location.MarkdownLocationProvider -import org.jetbrains.dokka.pages.RootPageNode -import org.jetbrains.dokka.plugability.DokkaContext - -class GfmMultimoduleLocationProvider(root: RootPageNode, context: DokkaContext) : MultimoduleLocationProvider(root, context, ".md") { - - override val defaultLocationProvider = MarkdownLocationProvider(root, context) - - class Factory(private val context: DokkaContext): LocationProviderFactory { - override fun getLocationProvider(pageNode: RootPageNode) = - GfmMultimoduleLocationProvider(pageNode, context) - } -}
\ No newline at end of file diff --git a/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmTemplateProcessingStrategy.kt b/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmTemplateProcessingStrategy.kt deleted file mode 100644 index 37226d1e..00000000 --- a/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmTemplateProcessingStrategy.kt +++ /dev/null @@ -1,45 +0,0 @@ -package org.jetbrains.dokka.gfm.allModulesPage - -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.launch -import org.jetbrains.dokka.allModulesPage.templates.ExternalModuleLinkResolver -import org.jetbrains.dokka.allModulesPage.templates.TemplateProcessingStrategy -import org.jetbrains.dokka.base.templating.parseJson -import org.jetbrains.dokka.gfm.GfmCommand -import org.jetbrains.dokka.gfm.GfmCommand.Companion.templateCommandRegex -import org.jetbrains.dokka.gfm.ResolveLinkGfmCommand -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.plugability.DokkaContext -import java.io.File - -class GfmTemplateProcessingStrategy(val context: DokkaContext) : TemplateProcessingStrategy { - - private val externalModuleLinkResolver = ExternalModuleLinkResolver(context) - - override suspend fun process(input: File, output: File): Boolean = coroutineScope { - if (input.extension == "md") { - launch(IO) { - val reader = input.bufferedReader() - val writer = output.bufferedWriter() - do { - val line = reader.readLine() - if (line != null) { - writer.write(line.replace(templateCommandRegex) { - when (val command = parseJson<GfmCommand>(it.groupValues.last())) { - is ResolveLinkGfmCommand -> resolveLink(output, command.dri) - } - }) - writer.newLine() - } - } while (line != null) - reader.close() - writer.close() - } - true - } else false - } - - private fun resolveLink(fileContext: File, dri: DRI): String = - externalModuleLinkResolver.resolve(dri, fileContext) ?: "" -}
\ No newline at end of file diff --git a/plugins/gfm/gfm-all-module-page/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin b/plugins/gfm/gfm-all-module-page/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin deleted file mode 100644 index 1a8acd51..00000000 --- a/plugins/gfm/gfm-all-module-page/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.dokka.gfm.allModulesPage.GfmAllModulesPagePlugin
\ No newline at end of file diff --git a/plugins/gfm/gfm-all-module-page/build.gradle.kts b/plugins/gfm/gfm-template-processing/build.gradle.kts index 85f83587..f95ef0e4 100644 --- a/plugins/gfm/gfm-all-module-page/build.gradle.kts +++ b/plugins/gfm/gfm-template-processing/build.gradle.kts @@ -3,12 +3,12 @@ import org.jetbrains.registerDokkaArtifactPublication dependencies { implementation(project(":plugins:base")) implementation(project(":plugins:gfm")) - implementation(project(":plugins:all-module-page")) + implementation(project(":plugins:all-modules-page")) val coroutines_version: String by project implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version") } -registerDokkaArtifactPublication("dokkaGfmAllModulePage") { - artifactId = "gfm-all-module-page-plugin" +registerDokkaArtifactPublication("dokkaGfmTemplateProcessing") { + artifactId = "gfm-template-processing-plugin" }
\ No newline at end of file diff --git a/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingPlugin.kt b/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingPlugin.kt new file mode 100644 index 00000000..7df740a5 --- /dev/null +++ b/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingPlugin.kt @@ -0,0 +1,31 @@ +package org.jetbrains.dokka.gfm.templateProcessing + +import org.jetbrains.dokka.allModulesPage.AllModulesPagePlugin +import org.jetbrains.dokka.allModulesPage.MultimoduleLocationProvider +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.gfm.GfmPlugin +import org.jetbrains.dokka.gfm.location.MarkdownLocationProvider +import org.jetbrains.dokka.plugability.DokkaPlugin + +class GfmTemplateProcessingPlugin : DokkaPlugin() { + + private val allModulesPagePlugin by lazy { plugin<AllModulesPagePlugin>() } + + private val gfmPlugin by lazy { plugin<GfmPlugin>() } + + private val dokkaBase by lazy { plugin<DokkaBase>()} + + val gfmTemplateProcessingStrategy by extending { + (allModulesPagePlugin.templateProcessingStrategy + providing ::GfmTemplateProcessingStrategy + order { before(allModulesPagePlugin.fallbackProcessingStrategy) }) + } + + val gfmLocationProvider by extending { + dokkaBase.locationProviderFactory providing MultimoduleLocationProvider::Factory override listOf(gfmPlugin.locationProvider, allModulesPagePlugin.multimoduleLocationProvider) + } + + val gfmPartialLocationProvider by extending { + allModulesPagePlugin.partialLocationProviderFactory providing MarkdownLocationProvider::Factory override allModulesPagePlugin.baseLocationProviderFactory + } +}
\ No newline at end of file diff --git a/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingStrategy.kt b/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingStrategy.kt new file mode 100644 index 00000000..b2ef4d06 --- /dev/null +++ b/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingStrategy.kt @@ -0,0 +1,51 @@ +package org.jetbrains.dokka.gfm.templateProcessing + +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.launch +import org.jetbrains.dokka.allModulesPage.AllModulesPagePlugin +import org.jetbrains.dokka.allModulesPage.templates.TemplateProcessingStrategy +import org.jetbrains.dokka.base.templating.parseJson +import org.jetbrains.dokka.gfm.GfmCommand +import org.jetbrains.dokka.gfm.GfmCommand.Companion.command +import org.jetbrains.dokka.gfm.GfmCommand.Companion.label +import org.jetbrains.dokka.gfm.GfmCommand.Companion.templateCommandRegex +import org.jetbrains.dokka.gfm.ResolveLinkGfmCommand +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.querySingle +import java.io.File + +class GfmTemplateProcessingStrategy(context: DokkaContext) : TemplateProcessingStrategy { + + private val externalModuleLinkResolver = context.plugin<AllModulesPagePlugin>().querySingle { externalModuleLinkResolver } + + override suspend fun process(input: File, output: File): Boolean = coroutineScope { + if (input.extension == "md") { + launch(IO) { + input.bufferedReader().use { reader -> + output.bufferedWriter().use { writer -> + do { + val line = reader.readLine() + if (line != null) { + writer.write(line.replace(templateCommandRegex) { + when (val command = parseJson<GfmCommand>(it.command)) { + is ResolveLinkGfmCommand -> resolveLink(output, command.dri, it.label) + } + }) + writer.newLine() + } + } while (line != null) + } + } + } + true + } else false + } + + private fun resolveLink(fileContext: File, dri: DRI, label: String): String = + externalModuleLinkResolver.resolve(dri, fileContext)?.let { address -> + "[$label]($address)" + } ?: label +}
\ No newline at end of file diff --git a/plugins/gfm/gfm-template-processing/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin b/plugins/gfm/gfm-template-processing/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin new file mode 100644 index 00000000..197823e7 --- /dev/null +++ b/plugins/gfm/gfm-template-processing/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin @@ -0,0 +1 @@ +org.jetbrains.dokka.gfm.templateProcessing.GfmTemplateProcessingPlugin
\ No newline at end of file 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() { diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt index 165aef98..1fa78423 100644 --- a/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt +++ b/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt @@ -1,13 +1,13 @@ package renderers.gfm import org.jetbrains.dokka.DokkaConfigurationImpl -import org.jetbrains.dokka.gfm.GfmPlugin -import org.jetbrains.dokka.gfm.location.MarkdownLocationProviderFactory -import org.jetbrains.dokka.testApi.context.MockContext import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.renderers.RootCreator import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProviderFactory import org.jetbrains.dokka.base.resolvers.external.javadoc.JavadocExternalLocationProviderFactory +import org.jetbrains.dokka.gfm.GfmPlugin +import org.jetbrains.dokka.gfm.location.MarkdownLocationProvider +import org.jetbrains.dokka.testApi.context.MockContext import renderers.RenderingOnlyTestBase import utils.TestOutputWriter @@ -15,11 +15,11 @@ abstract class GfmRenderingOnlyTestBase : RenderingOnlyTestBase<String>() { val files = TestOutputWriter() override val context = MockContext( - DokkaBase().outputWriter to { _ -> files }, - DokkaBase().locationProviderFactory to ::MarkdownLocationProviderFactory, - DokkaBase().externalLocationProviderFactory to { ::JavadocExternalLocationProviderFactory }, - DokkaBase().externalLocationProviderFactory to { ::DefaultExternalLocationProviderFactory }, - GfmPlugin().gfmPreprocessors to { _ -> RootCreator }, + DokkaBase().outputWriter to { files }, + DokkaBase().locationProviderFactory to MarkdownLocationProvider::Factory, + DokkaBase().externalLocationProviderFactory to ::JavadocExternalLocationProviderFactory, + DokkaBase().externalLocationProviderFactory to ::DefaultExternalLocationProviderFactory, + GfmPlugin().gfmPreprocessors to { RootCreator }, testConfiguration = DokkaConfigurationImpl(moduleName = "root") ) |