aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/transformers/pages/comments
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2023-11-10 11:46:54 +0100
committerGitHub <noreply@github.com>2023-11-10 11:46:54 +0100
commit8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch)
tree1b915207b2b9f61951ddbf0ff2e687efd053d555 /plugins/base/src/main/kotlin/transformers/pages/comments
parenta44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff)
downloaddokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing * Update Gradle to 8.4 * Refactor and simplify convention plugins and build scripts Fixes #3132 --------- Co-authored-by: Adam <897017+aSemy@users.noreply.github.com> Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers/pages/comments')
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt22
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt270
2 files changed, 0 insertions, 292 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt
deleted file mode 100644
index 6ca3f8d0..00000000
--- a/plugins/base/src/main/kotlin/transformers/pages/comments/CommentsToContentConverter.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.pages.comments
-
-import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
-import org.jetbrains.dokka.model.doc.DocTag
-import org.jetbrains.dokka.model.properties.PropertyContainer
-import org.jetbrains.dokka.pages.ContentNode
-import org.jetbrains.dokka.pages.DCI
-import org.jetbrains.dokka.pages.Style
-
-public interface CommentsToContentConverter {
- public fun buildContent(
- docTag: DocTag,
- dci: DCI,
- sourceSets: Set<DokkaSourceSet>,
- styles: Set<Style> = emptySet(),
- extras: PropertyContainer<ContentNode> = PropertyContainer.empty()
- ): 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
deleted file mode 100644
index e4e0f53f..00000000
--- a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.pages.comments
-
-
-import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
-import org.jetbrains.dokka.analysis.markdown.jb.MARKDOWN_ELEMENT_FILE_NAME
-import org.jetbrains.dokka.model.doc.*
-import org.jetbrains.dokka.model.properties.PropertyContainer
-import org.jetbrains.dokka.model.properties.plus
-import org.jetbrains.dokka.model.toDisplaySourceSets
-import org.jetbrains.dokka.pages.*
-import org.jetbrains.dokka.utilities.firstIsInstanceOrNull
-
-public open class DocTagToContentConverter : CommentsToContentConverter {
- override fun buildContent(
- docTag: DocTag,
- dci: DCI,
- sourceSets: Set<DokkaSourceSet>,
- styles: Set<Style>,
- extras: PropertyContainer<ContentNode>
- ): List<ContentNode> {
-
- fun buildChildren(docTag: DocTag, newStyles: Set<Style> = emptySet(), newExtras: SimpleAttr? = null) =
- docTag.children.flatMap {
- buildContent(it, dci, sourceSets, styles + newStyles, newExtras?.let { extras + it } ?: extras)
- }
-
- fun buildTableRows(rows: List<DocTag>, newStyle: Style): List<ContentGroup> =
- rows.flatMap {
- @Suppress("UNCHECKED_CAST")
- buildContent(it, dci, sourceSets, styles + newStyle, extras) as List<ContentGroup>
- }
-
- fun buildHeader(level: Int) =
- listOf(
- ContentHeader(
- buildChildren(docTag),
- level,
- dci,
- sourceSets.toDisplaySourceSets(),
- styles
- )
- )
-
- fun buildList(ordered: Boolean, newStyles: Set<Style> = emptySet(), start: Int = 1) =
- listOf(
- ContentList(
- buildChildren(docTag),
- ordered,
- dci,
- sourceSets.toDisplaySourceSets(),
- styles + newStyles,
- ((PropertyContainer.empty<ContentNode>()) + SimpleAttr("start", start.toString()))
- )
- )
-
- fun buildNewLine() = listOf(
- ContentBreakLine(
- sourceSets.toDisplaySourceSets()
- )
- )
-
- fun P.collapseParagraphs(): P =
- if (children.size == 1 && children.first() is P) (children.first() as P).collapseParagraphs() else this
-
- 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, start = docTag.params["start"]?.toInt() ?: 1)
- is Li -> listOf(
- ContentGroup(buildChildren(docTag), dci, sourceSets.toDisplaySourceSets(), styles, extras)
- )
- is Dl -> buildList(false, newStyles = setOf(ListStyle.DescriptionList))
- is Dt -> listOf(
- ContentGroup(
- buildChildren(docTag),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles + ListStyle.DescriptionTerm
- )
- )
- is Dd -> listOf(
- ContentGroup(
- buildChildren(docTag),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles + ListStyle.DescriptionDetails
- )
- )
- is Br -> buildNewLine()
- is B -> buildChildren(docTag, setOf(TextStyle.Strong))
- is I -> buildChildren(docTag, setOf(TextStyle.Italic))
- is P -> listOf(
- ContentGroup(
- buildChildren(docTag.collapseParagraphs()),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles + setOf(TextStyle.Paragraph),
- extras
- )
- )
- is A -> listOf(
- ContentResolvedLink(
- buildChildren(docTag),
- docTag.params.getValue("href"),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles
- )
- )
- is DocumentationLink -> listOf(
- ContentDRILink(
- buildChildren(docTag),
- docTag.dri,
- DCI(
- setOf(docTag.dri),
- ContentKind.Main
- ),
- sourceSets.toDisplaySourceSets(),
- styles
- )
- )
- is BlockQuote -> listOf(
- ContentGroup(
- buildChildren(docTag),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles + TextStyle.Quotation,
- )
- )
- is Pre, is CodeBlock -> listOf(
- ContentCodeBlock(
- buildChildren(docTag),
- docTag.params.getOrDefault("lang", ""),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles
- )
- )
- is CodeInline -> listOf(
- ContentCodeInline(
- buildChildren(docTag),
- "",
- dci,
- sourceSets.toDisplaySourceSets(),
- styles
- )
- )
- is Img -> listOf(
- ContentEmbeddedResource(
- address = docTag.params["href"]!!,
- altText = docTag.params["alt"],
- dci = dci,
- sourceSets = sourceSets.toDisplaySourceSets(),
- style = styles,
- extra = extras
- )
- )
- is HorizontalRule -> listOf(
- ContentText(
- "",
- dci,
- sourceSets.toDisplaySourceSets(),
- setOf()
- )
- )
- is Text -> listOf(
- ContentText(
- docTag.body,
- dci,
- sourceSets.toDisplaySourceSets(),
- styles,
- extras + HtmlContent.takeIf { docTag.params["content-type"] == "html" }
- )
- )
- is Strikethrough -> buildChildren(docTag, setOf(TextStyle.Strikethrough))
- is Table -> {
- //https://html.spec.whatwg.org/multipage/tables.html#the-caption-element
- if (docTag.children.any { it is TBody }) {
- val head = docTag.children.filterIsInstance<THead>().flatMap { it.children }
- val body = docTag.children.filterIsInstance<TBody>().flatMap { it.children }
- listOf(
- ContentTable(
- header = buildTableRows(head.filterIsInstance<Th>(), CommentTable),
- caption = docTag.children.firstIsInstanceOrNull<Caption>()?.let {
- ContentGroup(
- buildContent(it, dci, sourceSets),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles,
- extras
- )
- },
- buildTableRows(body.filterIsInstance<Tr>(), CommentTable),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles + CommentTable
- )
- )
- } else {
- listOf(
- ContentTable(
- header = buildTableRows(docTag.children.filterIsInstance<Th>(), CommentTable),
- caption = null,
- buildTableRows(docTag.children.filterIsInstance<Tr>(), CommentTable),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles + CommentTable
- )
- )
- }
- }
- is Th,
- is Tr -> listOf(
- ContentGroup(
- docTag.children.map {
- ContentGroup(buildChildren(it), dci, sourceSets.toDisplaySourceSets(), styles, extras)
- },
- dci,
- sourceSets.toDisplaySourceSets(),
- styles
- )
- )
- is Index -> listOf(
- ContentGroup(
- buildChildren(docTag, newStyles = styles + ContentStyle.InDocumentationAnchor),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles
- )
- )
- is CustomDocTag -> if (docTag.isNonemptyFile()) {
- listOf(
- ContentGroup(
- buildChildren(docTag),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles,
- extra = extras
- )
- )
- } else {
- buildChildren(docTag)
- }
- is Caption -> listOf(
- ContentGroup(
- buildChildren(docTag),
- dci,
- sourceSets.toDisplaySourceSets(),
- styles + ContentStyle.Caption,
- extra = extras
- )
- )
- is Var -> buildChildren(docTag, setOf(TextStyle.Var))
- is U -> buildChildren(docTag, setOf(TextStyle.Underlined))
-
- else -> buildChildren(docTag)
- }
- }
-
- private fun CustomDocTag.isNonemptyFile() = name == MARKDOWN_ELEMENT_FILE_NAME && children.size > 1
-}