diff options
Diffstat (limited to 'plugins/gfm/src/main')
5 files changed, 42 insertions, 31 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 5ffa883a..3fd7b514 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 @@ -8,39 +8,39 @@ import org.jetbrains.dokka.CoreExtensions 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.local.LocationProviderFactory import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat import org.jetbrains.dokka.gfm.location.MarkdownLocationProvider import org.jetbrains.dokka.gfm.renderer.BriefCommentPreprocessor import org.jetbrains.dokka.gfm.renderer.CommonmarkRenderer -import org.jetbrains.dokka.plugability.DokkaPlugin -import org.jetbrains.dokka.plugability.DokkaPluginApiPreview -import org.jetbrains.dokka.plugability.PluginApiPreviewAcknowledgement +import org.jetbrains.dokka.plugability.* import org.jetbrains.dokka.renderers.PostAction +import org.jetbrains.dokka.renderers.Renderer import org.jetbrains.dokka.transformers.pages.PageTransformer -class GfmPlugin : DokkaPlugin() { +public class GfmPlugin : DokkaPlugin() { - val gfmPreprocessors by extensionPoint<PageTransformer>() + public val gfmPreprocessors: ExtensionPoint<PageTransformer> by extensionPoint<PageTransformer>() private val dokkaBase by lazy { plugin<DokkaBase>() } - val renderer by extending { + public val renderer: Extension<Renderer, *, *> by extending { CoreExtensions.renderer providing ::CommonmarkRenderer override dokkaBase.htmlRenderer } - val locationProvider by extending { + public val locationProvider: Extension<LocationProviderFactory, *, *> by extending { dokkaBase.locationProviderFactory providing MarkdownLocationProvider::Factory override dokkaBase.locationProvider } - val rootCreator by extending { + public val rootCreator: Extension<PageTransformer, *, *> by extending { gfmPreprocessors with RootCreator } - val briefCommentPreprocessor by extending { + public val briefCommentPreprocessor: Extension<PageTransformer, *, *> by extending { gfmPreprocessors with BriefCommentPreprocessor() } - val packageListCreator by extending { + public val packageListCreator: Extension<PageTransformer, *, *> by extending { (gfmPreprocessors providing { PackageListCreator(it, RecognizedLinkFormat.DokkaGFM) } order { after(rootCreator) }) 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 f30c5929..194127df 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 @@ -10,16 +10,21 @@ import org.jetbrains.dokka.base.templating.toJsonString import org.jetbrains.dokka.links.DRI @JsonTypeInfo(use = CLASS) -sealed class GfmCommand { - companion object { +public sealed class GfmCommand { + + public companion object { private const val delimiter = "\u1680" - val templateCommandRegex: Regex = + + public val templateCommandRegex: Regex = Regex("<!---$delimiter GfmCommand ([^$delimiter ]*)$delimiter--->(.+?)(?=<!---$delimiter)<!---$delimiter--->") - val MatchResult.command + + public val MatchResult.command: String get() = groupValues[1] - val MatchResult.label + + public val MatchResult.label: String get() = groupValues[2] - fun Appendable.templateCommand(command: GfmCommand, content: Appendable.() -> Unit) { + + public fun Appendable.templateCommand(command: GfmCommand, content: Appendable.() -> Unit) { append("<!---$delimiter GfmCommand ${toJsonString(command)}$delimiter--->") content() append("<!---$delimiter--->") @@ -27,6 +32,8 @@ sealed class GfmCommand { } } -class ResolveLinkGfmCommand(val dri: DRI) : GfmCommand() +public class ResolveLinkGfmCommand( + public 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 03025863..f331a6d9 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,17 +5,18 @@ package org.jetbrains.dokka.gfm.location import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider +import org.jetbrains.dokka.base.resolvers.local.LocationProvider import org.jetbrains.dokka.base.resolvers.local.LocationProviderFactory import org.jetbrains.dokka.pages.RootPageNode import org.jetbrains.dokka.plugability.DokkaContext -class MarkdownLocationProvider( +public class MarkdownLocationProvider( pageGraphRoot: RootPageNode, dokkaContext: DokkaContext ) : DokkaLocationProvider(pageGraphRoot, dokkaContext, ".md") { - class Factory(private val context: DokkaContext) : LocationProviderFactory { - override fun getLocationProvider(pageNode: RootPageNode) = + public class Factory(private val context: DokkaContext) : LocationProviderFactory { + override fun getLocationProvider(pageNode: RootPageNode): LocationProvider = MarkdownLocationProvider(pageNode, context) } } diff --git a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/BriefCommentPreprocessor.kt b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/BriefCommentPreprocessor.kt index 56d75fd2..6023cca1 100644 --- a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/BriefCommentPreprocessor.kt +++ b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/BriefCommentPreprocessor.kt @@ -7,14 +7,16 @@ package org.jetbrains.dokka.gfm.renderer import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.transformers.pages.PageTransformer -class BriefCommentPreprocessor : PageTransformer { - override fun invoke(input: RootPageNode) = input.transformContentPagesTree { contentPage -> - contentPage.modified(content = contentPage.content.recursiveMapTransform<ContentGroup, ContentNode> { - if (it.dci.kind == ContentKind.BriefComment) { - it.copy(style = it.style + setOf(TextStyle.Block)) - } else { - it - } - }) +public class BriefCommentPreprocessor : PageTransformer { + override fun invoke(input: RootPageNode): RootPageNode { + return input.transformContentPagesTree { contentPage -> + contentPage.modified(content = contentPage.content.recursiveMapTransform<ContentGroup, ContentNode> { + if (it.dci.kind == ContentKind.BriefComment) { + it.copy(style = it.style + setOf(TextStyle.Block)) + } else { + it + } + }) + } } } 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 3cfd17ef..3bc420ac 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 @@ -15,13 +15,14 @@ import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.query +import org.jetbrains.dokka.transformers.pages.PageTransformer import org.jetbrains.dokka.utilities.htmlEscape -open class CommonmarkRenderer( +public open class CommonmarkRenderer( context: DokkaContext ) : DefaultRenderer<StringBuilder>(context) { - override val preprocessors = context.plugin<GfmPlugin>().query { gfmPreprocessors } + override val preprocessors: List<PageTransformer> = context.plugin<GfmPlugin>().query { gfmPreprocessors } private val isPartial = context.configuration.delayTemplateSubstitution |