aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-02-17 11:27:37 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-02-18 13:28:23 +0100
commitba769f0695aaa9719b62ca32028fd3d24442f5ec (patch)
tree5f7ed51c2eaae6988648d5132ff8d5aa258c5bc5 /plugins/base/src
parent2bfb7733dfef8da0271a01a7275ea42ecb69d93a (diff)
downloaddokka-ba769f0695aaa9719b62ca32028fd3d24442f5ec.tar.gz
dokka-ba769f0695aaa9719b62ca32028fd3d24442f5ec.tar.bz2
dokka-ba769f0695aaa9719b62ca32028fd3d24442f5ec.zip
Moves comments to content conversion to base plugin
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/DokkaBase.kt13
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentablesToPageTranslator.kt13
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/PageContentBuilder.kt1
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt14
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt132
5 files changed, 167 insertions, 6 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt
index ed23d77e..9b6e9b1a 100644
--- a/plugins/base/src/main/kotlin/DokkaBase.kt
+++ b/plugins/base/src/main/kotlin/DokkaBase.kt
@@ -4,6 +4,8 @@ import org.jetbrains.dokka.CoreExtensions
import org.jetbrains.dokka.base.transformers.descriptors.DefaultDescriptorToDocumentationTranslator
import org.jetbrains.dokka.base.transformers.documentables.DefaultDocumentableMerger
import org.jetbrains.dokka.base.transformers.documentables.DefaultDocumentablesToPageTranslator
+import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
+import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter
import org.jetbrains.dokka.base.transformers.pages.merger.FallbackPageMergerStrategy
import org.jetbrains.dokka.base.transformers.pages.merger.PageMergerStrategy
import org.jetbrains.dokka.base.transformers.pages.merger.PageNodeMerger
@@ -12,8 +14,9 @@ import org.jetbrains.dokka.base.transformers.psi.DefaultPsiToDocumentationTransl
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.renderers.html.HtmlRenderer
-class DokkaBase: DokkaPlugin() {
+class DokkaBase : DokkaPlugin() {
val pageMergerStrategy by extensionPoint<PageMergerStrategy>()
+ val commentsToContentConverter by extensionPoint<CommentsToContentConverter>()
val descriptorToDocumentationTranslator by extending(isFallback = true) {
CoreExtensions.descriptorToDocumentationTranslator providing ::DefaultDescriptorToDocumentationTranslator
@@ -28,7 +31,13 @@ class DokkaBase: DokkaPlugin() {
}
val documentablesToPageTranslator by extending(isFallback = true) {
- CoreExtensions.documentablesToPageTranslator with DefaultDocumentablesToPageTranslator
+ CoreExtensions.documentablesToPageTranslator providing { ctx ->
+ DefaultDocumentablesToPageTranslator(ctx.single(commentsToContentConverter), ctx.logger)
+ }
+ }
+
+ val docTagToContentConverter by extending(isFallback = true) {
+ commentsToContentConverter with DocTagToContentConverter
}
val pageMerger by extending {
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentablesToPageTranslator.kt b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentablesToPageTranslator.kt
index 90f8e2d7..d28791ab 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentablesToPageTranslator.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/DefaultDocumentablesToPageTranslator.kt
@@ -1,21 +1,26 @@
package org.jetbrains.dokka.base.transformers.documentables
import org.jetbrains.dokka.CoreExtensions
+import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.model.Module
import org.jetbrains.dokka.pages.ModulePageNode
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.documentation.DocumentablesToPageTranslator
+import org.jetbrains.dokka.utilities.DokkaLogger
-object DefaultDocumentablesToPageTranslator : DocumentablesToPageTranslator {
- override fun invoke(module: Module, context: DokkaContext): ModulePageNode =
+class DefaultDocumentablesToPageTranslator(
+ private val commentsToContentConverter: CommentsToContentConverter,
+ private val logger: DokkaLogger
+) : DocumentablesToPageTranslator {
+ override fun invoke(module: Module): ModulePageNode =
DefaultPageBuilder { node, kind, operation ->
DefaultPageContentBuilder.group(
setOf(node.dri),
node.platformData,
kind,
- context.single(CoreExtensions.commentsToContentConverter),
- context.logger,
+ commentsToContentConverter,
+ logger,
operation
)
}.pageForModule(module)
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/transformers/documentables/PageContentBuilder.kt
index 809b97a0..6ce883b1 100644
--- a/plugins/base/src/main/kotlin/transformers/documentables/PageContentBuilder.kt
+++ b/plugins/base/src/main/kotlin/transformers/documentables/PageContentBuilder.kt
@@ -1,5 +1,6 @@
package org.jetbrains.dokka.base.transformers.documentables
+import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.Documentable
import org.jetbrains.dokka.model.Function
diff --git a/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt
new file mode 100644
index 00000000..4d2f14a5
--- /dev/null
+++ b/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt
@@ -0,0 +1,14 @@
+package org.jetbrains.dokka.base.transformers.pages.comments
+
+import org.jetbrains.dokka.model.doc.DocTag
+import org.jetbrains.dokka.pages.*
+
+interface CommentsToContentConverter {
+ fun buildContent(
+ docTag: DocTag,
+ dci: DCI,
+ platforms: Set<PlatformData>,
+ styles: Set<Style> = emptySet(),
+ extras: Set<Extra> = emptySet()
+ ): List<ContentNode>
+}
diff --git a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
new file mode 100644
index 00000000..70792534
--- /dev/null
+++ b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
@@ -0,0 +1,132 @@
+package org.jetbrains.dokka.base.transformers.pages.comments
+
+import org.jetbrains.dokka.model.doc.*
+import org.jetbrains.dokka.pages.*
+import org.jetbrains.dokka.plugability.DokkaContext
+
+object DocTagToContentConverter : CommentsToContentConverter {
+ override fun buildContent(
+ docTag: DocTag,
+ dci: DCI,
+ platforms: Set<PlatformData>,
+ styles: Set<Style>,
+ extras: Set<Extra>
+
+ ): List<ContentNode> {
+
+ fun buildChildren(docTag: DocTag, newStyles: Set<Style> = emptySet(), newExtras: Set<Extra> = emptySet()) =
+ docTag.children.flatMap {
+ buildContent(it, dci, platforms, styles + newStyles, extras + newExtras)
+ }
+
+ fun buildHeader(level: Int) =
+ listOf(
+ ContentHeader(
+ buildChildren(docTag),
+ level,
+ dci,
+ platforms,
+ styles,
+ extras
+ )
+ )
+
+ fun buildList(ordered: Boolean) =
+ listOf(
+ ContentList(
+ buildChildren(docTag),
+ ordered,
+ dci,
+ platforms,
+ styles,
+ extras
+ )
+ )
+
+ return when (docTag) {
+ is H1 -> buildHeader(1)
+ is H2 -> buildHeader(2)
+ is H3 -> buildHeader(3)
+ is H4 -> buildHeader(4)
+ is H5 -> buildHeader(5)
+ is H6 -> buildHeader(6)
+ is Ul -> buildList(false)
+ is Ol -> buildList(true)
+ is Li -> buildChildren(docTag)
+ is B -> buildChildren(docTag, setOf(TextStyle.Strong))
+ is I -> buildChildren(docTag, setOf(TextStyle.Italic))
+ is P -> buildChildren(docTag, newStyles = setOf(TextStyle.Paragraph))
+ is A -> listOf(
+ ContentResolvedLink(
+ buildChildren(docTag),
+ docTag.params.get("href")!!,
+ dci,
+ platforms,
+ styles,
+ extras
+ )
+ )
+ is DocumentationLink -> listOf(
+ ContentDRILink(
+ buildChildren(docTag),
+ docTag.dri,
+ DCI(
+ setOf(docTag.dri),
+ ContentKind.Symbol
+ ),
+ platforms,
+ styles,
+ extras
+ )
+ )
+ is BlockQuote -> listOf(
+ ContentCode(
+ buildChildren(docTag),
+ "",
+ dci,
+ platforms,
+ styles,
+ extras
+ )
+ )
+ is Code -> listOf(
+ ContentCode(
+ buildChildren(docTag),
+ "",
+ dci,
+ platforms,
+ styles,
+ extras
+ )
+ )
+ is Img -> listOf(
+ ContentEmbeddedResource(
+ address = docTag.params["href"]!!,
+ altText = docTag.params["alt"],
+ dci = dci,
+ platforms = platforms,
+ style = styles,
+ extras = extras
+ )
+ )
+ is HorizontalRule -> listOf(
+ ContentText(
+ "",
+ dci,
+ platforms,
+ setOf()
+ )
+ )
+ is Text -> listOf(
+ ContentText(
+ docTag.body,
+ dci,
+ platforms,
+ styles,
+ extras
+ )
+ )
+ else -> buildChildren(docTag)
+ }
+ }
+}