From c68c05a1e8876e9b8555df7bcdfeaca3e100f0d1 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Mon, 6 Dec 2021 16:20:51 +0300 Subject: Description list support for JavaDocs (#2213) --- .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 28 +++++- .../pages/comments/DocTagToContentConverter.kt | 25 ++++- .../documentables/PageContentBuilder.kt | 12 +++ .../translators/psi/parsers/JavadocParser.kt | 11 ++- .../src/test/kotlin/parsers/JavadocParserTest.kt | 104 ++++++++++++++++++++- .../test/kotlin/renderers/html/ListStylesTest.kt | 41 ++++++++ .../transformers/CommentsToContentConverterTest.kt | 57 ++++++++++- 7 files changed, 264 insertions(+), 14 deletions(-) create mode 100644 plugins/base/src/test/kotlin/renderers/html/ListStylesTest.kt (limited to 'plugins/base/src') diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index b61d513a..304b96fa 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -8,7 +8,6 @@ import org.jetbrains.dokka.base.DokkaBaseConfiguration import org.jetbrains.dokka.base.DokkaBaseConfiguration.Companion.defaultFooterMessage import org.jetbrains.dokka.base.renderers.* import org.jetbrains.dokka.base.renderers.html.command.consumers.ImmediateResolutionTagConsumer -import org.jetbrains.dokka.base.renderers.pageId import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint import org.jetbrains.dokka.base.resolvers.local.DokkaBaseLocationProvider import org.jetbrains.dokka.base.templating.* @@ -295,8 +294,31 @@ open class HtmlRenderer( node: ContentList, pageContext: ContentPage, sourceSetRestriction: Set? - ) = if (node.ordered) ol { buildListItems(node.children, pageContext, sourceSetRestriction) } - else ul { buildListItems(node.children, pageContext, sourceSetRestriction) } + ) = if (node.ordered) { + ol { buildListItems(node.children, pageContext, sourceSetRestriction) } + } else if (node.hasStyle(ListStyle.DescriptionList)) { + dl { buildListItems(node.children, pageContext, sourceSetRestriction) } + } else { + ul { buildListItems(node.children, pageContext, sourceSetRestriction) } + } + + open fun DL.buildListItems( + items: List, + pageContext: ContentPage, + sourceSetRestriction: Set? = null + ) { + items.forEach { + when { + it.hasStyle(ListStyle.DescriptionTerm) -> dt { + it.build(this@buildListItems, pageContext, sourceSetRestriction) + } + it.hasStyle(ListStyle.DescriptionDetails) -> dd { + it.build(this@buildListItems, pageContext, sourceSetRestriction) + } + else -> it.build(this, pageContext, sourceSetRestriction) + } + } + } open fun OL.buildListItems( items: List, diff --git a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt index 8c2e1c99..2b4317c5 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt @@ -4,10 +4,10 @@ import org.intellij.markdown.MarkdownElementTypes import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet 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.kotlin.utils.addToStdlib.firstIsInstanceOrNull -import org.jetbrains.dokka.model.properties.plus open class DocTagToContentConverter : CommentsToContentConverter { override fun buildContent( @@ -39,14 +39,14 @@ open class DocTagToContentConverter : CommentsToContentConverter { ) ) - fun buildList(ordered: Boolean, start: Int = 1) = + fun buildList(ordered: Boolean, newStyles: Set