diff options
| author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-09-14 13:49:54 +0200 |
|---|---|---|
| committer | Kamil Doległo <9080183+kamildoleglo@users.noreply.github.com> | 2020-10-07 02:36:57 +0200 |
| commit | ec637955575995011351b106d3a67194d21c4b15 (patch) | |
| tree | 5762d6ca0c49cc48dec01240380bc6fd436e81b0 /plugins | |
| parent | 7c4301a48af55e156538666b6e645d8d13caae9a (diff) | |
| download | dokka-ec637955575995011351b106d3a67194d21c4b15.tar.gz dokka-ec637955575995011351b106d3a67194d21c4b15.tar.bz2 dokka-ec637955575995011351b106d3a67194d21c4b15.zip | |
Introduce top-level DocTag
Diffstat (limited to 'plugins')
16 files changed, 415 insertions, 255 deletions
diff --git a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt index 23e59f8b..e7a36d3f 100644 --- a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt +++ b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt @@ -162,6 +162,12 @@ open class MarkdownParser( return linksHandler(linkText, link, linkTitle) } + private fun markdownFileHandler(node: ASTNode) = + DocTagsFromIElementFactory.getInstance( + node.type, + children = node.children.evaluateChildren() + ) + private fun autoLinksHandler(node: ASTNode): DocTag { val link = text.substring(node.startOffset + 1, node.endOffset - 1) @@ -206,11 +212,6 @@ open class MarkdownParser( body = text.substring(node.startOffset, node.endOffset).transform() ) - private fun markdownFileHandler(node: ASTNode) = if (node.children.size == 1) - visitNode(node.children.first()) - else - defaultHandler(node) - private fun strikeThroughHandler(node: ASTNode) = DocTagsFromIElementFactory.getInstance( node.type, children = node.children.evaluateChildrenWithDroppedEnclosingTokens(2) @@ -448,9 +449,9 @@ open class MarkdownParser( KDocKnownTag.SEE -> See( parseStringToDocNode(it.getContent()), it.getSubjectName().orEmpty(), - parseStringToDocNode("[${it.getSubjectName()}]") + (parseStringToDocNode("[${it.getSubjectName()}]")) .let { - val link = it.children[0] + val link = it.children[0].children[0] if (link is DocumentationLink) link.dri else null } diff --git a/plugins/base/src/main/kotlin/parsers/Parser.kt b/plugins/base/src/main/kotlin/parsers/Parser.kt index 894fa82f..228cc88b 100644 --- a/plugins/base/src/main/kotlin/parsers/Parser.kt +++ b/plugins/base/src/main/kotlin/parsers/Parser.kt @@ -18,8 +18,15 @@ abstract class Parser { "author" -> Author(parseStringToDocNode(it.second)) "version" -> Version(parseStringToDocNode(it.second)) "since" -> Since(parseStringToDocNode(it.second)) - "see" -> See(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' '), null) - "param" -> Param(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' ')) + "see" -> See( + parseStringToDocNode(it.second.substringAfter(' ')), + it.second.substringBefore(' '), + null + ) + "param" -> Param( + parseStringToDocNode(it.second.substringAfter(' ')), + it.second.substringBefore(' ') + ) "property" -> Property( parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' ') @@ -32,7 +39,10 @@ abstract class Parser { it.second.substringBefore(' ') ) "deprecated" -> Deprecated(parseStringToDocNode(it.second)) - "sample" -> Sample(parseStringToDocNode(it.second.substringAfter(' ')), it.second.substringBefore(' ')) + "sample" -> Sample( + parseStringToDocNode(it.second.substringAfter(' ')), + it.second.substringBefore(' ') + ) "suppress" -> Suppress(parseStringToDocNode(it.second)) else -> CustomTagWrapper(parseStringToDocNode(it.second), it.first) } diff --git a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt index 58b4b223..b714caec 100644 --- a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt +++ b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromIElementFactory.kt @@ -40,6 +40,7 @@ object DocTagsFromIElementFactory { GFMElementTypes.HEADER -> Th(children, params) GFMElementTypes.ROW -> Tr(children, params) GFMTokenTypes.CELL -> Td(children, params) - else -> CustomDocTag(children, params) + MarkdownElementTypes.MARKDOWN_FILE -> CustomDocTag(children, params, MarkdownElementTypes.MARKDOWN_FILE.name) + else -> CustomDocTag(children, params, type.name) } } diff --git a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt index 124dc3b4..1af4e719 100644 --- a/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt +++ b/plugins/base/src/main/kotlin/parsers/factories/DocTagsFromStringFactory.kt @@ -72,6 +72,6 @@ object DocTagsFromStringFactory { "var" -> Var(children, params) "documentationlink" -> DocumentationLink(dri ?: throw NullPointerException("DRI cannot be passed null while constructing documentation link!"), children, params) "hr" -> HorizontalRule - else -> CustomDocTag(children, params) + else -> CustomDocTag(children, params, name) } -}
\ No newline at end of file +} diff --git a/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt index 7914e88f..acff5ada 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/annotations/SinceKotlinTransformer.kt @@ -1,7 +1,9 @@ package org.jetbrains.dokka.base.transformers.pages.annotations +import org.intellij.markdown.MarkdownElementTypes import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.doc.CustomDocTag import org.jetbrains.dokka.model.doc.CustomTagWrapper import org.jetbrains.dokka.model.doc.Text import org.jetbrains.dokka.model.properties.WithExtraProperties @@ -73,10 +75,19 @@ class SinceKotlinTransformer(val context: DokkaContext) : DocumentableTransforme acc.mapValues { if (it.key == sourceSet) it.value.copy( it.value.children + listOf( - CustomTagWrapper(Text(version.dropWhile { it == '"' }.dropLastWhile { it == '"' }), "Since Kotlin") + CustomTagWrapper( + CustomDocTag( + listOf( + Text(version.dropWhile { it == '"' }.dropLastWhile { it == '"' } + ) + ), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ), + "Since Kotlin" + ) ) ) else it.value } } ?: acc } -}
\ No newline at end of file +} 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 51ab0858..0fea6b4f 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/comments/DocTagToContentConverter.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.base.transformers.pages.comments +import org.intellij.markdown.MarkdownElementTypes import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.model.doc.* import org.jetbrains.dokka.model.properties.PropertyContainer @@ -175,7 +176,24 @@ object DocTagToContentConverter : CommentsToContentConverter { styles ) ) + + is CustomDocTag -> if (docTag.isNonemptyFile()) { + listOf( + ContentGroup( + buildChildren(docTag), + dci, + sourceSets.toDisplaySourceSets(), + styles, + extra = extra + ) + ) + } else { + buildChildren(docTag) + } + else -> buildChildren(docTag) } } + + private fun CustomDocTag.isNonemptyFile() = name == MarkdownElementTypes.MARKDOWN_FILE.name && children.size > 1 } diff --git a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt index b4663b20..905d1898 100644 --- a/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt +++ b/plugins/base/src/main/kotlin/translators/psi/JavadocParser.kt @@ -6,6 +6,7 @@ import com.intellij.psi.impl.source.tree.JavaDocElementType import com.intellij.psi.impl.source.tree.LeafPsiElement import com.intellij.psi.javadoc.* import com.intellij.psi.util.PsiTreeUtil +import org.intellij.markdown.MarkdownElementTypes import org.jetbrains.dokka.analysis.from import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.doc.* @@ -55,8 +56,11 @@ class JavadocParser( return DocumentationNode(nodes) } - private fun wrapTagIfNecessary(list: List<DocTag>): DocTag = - if (list.size == 1) list.first() else P(list) + private fun wrapTagIfNecessary(list: List<DocTag>): CustomDocTag = + if (list.size == 1 && (list.first() as? CustomDocTag)?.name == MarkdownElementTypes.MARKDOWN_FILE.name) + list.first() as CustomDocTag + else + CustomDocTag(list, name = MarkdownElementTypes.MARKDOWN_FILE.name) private fun findClosestDocComment(element: PsiNamedElement): PsiDocComment? { (element as? PsiDocCommentOwner)?.docComment?.run { return this } diff --git a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt index 4f2bd8dc..1116dfa9 100644 --- a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt +++ b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt @@ -605,6 +605,6 @@ class ContentForParamsTest : AbstractCoreTest() { } private fun DocumentationNode.paramsDescription(): String = - children.firstIsInstanceOrNull<Param>()?.root?.children?.firstIsInstanceOrNull<Text>()?.body.orEmpty() + children.firstIsInstanceOrNull<Param>()?.root?.children?.first()?.children?.firstIsInstanceOrNull<Text>()?.body.orEmpty() } diff --git a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt index fd51c895..aa9ac045 100644 --- a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt +++ b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt @@ -89,7 +89,7 @@ class ContentForSeeAlsoTest : AbstractCoreTest() { group { //DRI should be "test//abc/#/-1/" link { +"abc" } - group { group { } } + group { } } } } @@ -201,9 +201,7 @@ class ContentForSeeAlsoTest : AbstractCoreTest() { group { //DRI should be "kotlin.collections/Collection////" link { +"Collection" } - group { - group { } - } + group { } } } } diff --git a/plugins/base/src/test/kotlin/markdown/ParserTest.kt b/plugins/base/src/test/kotlin/markdown/ParserTest.kt index c25678d4..0fdb10c1 100644 --- a/plugins/base/src/test/kotlin/markdown/ParserTest.kt +++ b/plugins/base/src/test/kotlin/markdown/ParserTest.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka.tests import markdown.KDocTest +import org.intellij.markdown.MarkdownElementTypes import org.jetbrains.dokka.model.doc.* import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test @@ -17,7 +18,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text("This is simple test of string Next line"))) + CustomDocTag( + listOf(P(listOf(Text("This is simple test of string Next line")))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -33,12 +37,17 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("This is simple test of string"), - Br, - Text("Next line") - ) + P( + listOf( + Text("This is simple test of string"), + Br, + Text("Next line") + ) + ) + ), + name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -55,15 +64,19 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("This is "), - B(listOf(Text("simple"))), - Text(" test of "), - I(listOf(Text("string"))), - Text(" Next "), - B(listOf(I(listOf(Text("line"))))) - ) + P( + listOf( + Text("This is "), + B(listOf(Text("simple"))), + Text(" test of "), + I(listOf(Text("string"))), + Text(" Next "), + B(listOf(I(listOf(Text("line"))))) + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -79,7 +92,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text("This is simple text with: colon!"))) + CustomDocTag( + listOf(P(listOf(Text("This is simple text with: colon!")))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -96,7 +112,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text("Text and String"))) + CustomDocTag( + listOf(P(listOf(Text("Text and String")))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -115,11 +134,11 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( P(listOf(Text("Paragraph number one"))), P(listOf(Text("Paragraph"), Br, Text("number two"))) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -133,7 +152,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(I(listOf(Text("text"))))) + CustomDocTag( + listOf(P(listOf(I(listOf(Text("text")))))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -146,7 +168,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text("text_with_underscores"))) + CustomDocTag( + listOf(P(listOf(Text("text_with_underscores")))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -159,7 +184,10 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(I(listOf(Text("text"))))) + CustomDocTag( + listOf(P(listOf(I(listOf(Text("text")))))), + name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -169,20 +197,25 @@ class ParserTest : KDocTest() { @Test fun `Stars as italic bounds`() { val kdoc = "The abstract syntax tree node for a multiplying expression. A multiplying\n" + - "expression is a binary expression where the operator is a multiplying operator\n" + - "such as \"*\", \"/\", or \"mod\". A simple example would be \"5*x\"." + "expression is a binary expression where the operator is a multiplying operator\n" + + "such as \"*\", \"/\", or \"mod\". A simple example would be \"5*x\"." val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("The abstract syntax tree node for a multiplying expression. A multiplying " + - "expression is a binary expression where the operator is a multiplying operator " + - "such as \"" - ), - I(listOf(Text("\", \"/\", or \"mod\". A simple example would be \"5"))), - Text("x\".") - ) + P( + listOf( + Text( + "The abstract syntax tree node for a multiplying expression. A multiplying " + + "expression is a binary expression where the operator is a multiplying operator " + + "such as \"" + ), + I(listOf(Text("\", \"/\", or \"mod\". A simple example would be \"5"))), + Text("x\".") + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -198,15 +231,20 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( - Text("The abstract syntax tree node for a multiplying expression. A multiplying " + - "expression is a binary expression where the operator is a multiplying operator " + - "such as \"" - ), - B(listOf(Text("\", \"/\", or \"mod\". A simple example would be \"5"))), - Text("x\".") - ) + P( + listOf( + Text( + "The abstract syntax tree node for a multiplying expression. A multiplying " + + "expression is a binary expression where the operator is a multiplying operator " + + "such as \"" + ), + B(listOf(Text("\", \"/\", or \"mod\". A simple example would be \"5"))), + Text("x\".") + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -220,7 +258,11 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text("Embedded*Star"))) + CustomDocTag( + listOf( + P(listOf(Text("Embedded*Star"))) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name + ) ) ) ) @@ -237,11 +279,15 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ul( + CustomDocTag( listOf( - Li(listOf(P(listOf(Text("list item 1"))))), - Li(listOf(P(listOf(Text("list item 2"))))) - ) + Ul( + listOf( + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -260,11 +306,15 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ul( + CustomDocTag( listOf( - Li(listOf(P(listOf(Text("list item 1 continue 1"))))), - Li(listOf(P(listOf(Text("list item 2"), Br, Text("continue 2"))))) - ) + Ul( + listOf( + Li(listOf(P(listOf(Text("list item 1 continue 1"))))), + Li(listOf(P(listOf(Text("list item 2"), Br, Text("continue 2"))))) + ) + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -283,31 +333,35 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ul( + CustomDocTag( listOf( - Li( + Ul( listOf( - P( + Li( listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 1 continue 1") + P( + listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 1 continue 1") + ) + ) ) - ) - ) - ), - Li( - listOf( - P( + ), + Li( listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 2 continue 2") + P( + listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 2 continue 2") + ) + ) ) ) ) ) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -333,7 +387,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P( + CustomDocTag( listOf( Ul( listOf( @@ -355,7 +409,7 @@ class ParserTest : KDocTest() { ) ), P(listOf(Text("New paragraph"))) - ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -372,12 +426,16 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ol( + CustomDocTag( listOf( - Li(listOf(P(listOf(Text("list item 1"))))), - Li(listOf(P(listOf(Text("list item 2"))))) - ), - mapOf("start" to "1") + Ol( + listOf( + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) + ), + mapOf("start" to "1") + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -395,12 +453,16 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ol( + CustomDocTag( listOf( - Li(listOf(P(listOf(Text("list item 1"))))), - Li(listOf(P(listOf(Text("list item 2"))))) - ), - mapOf("start" to "9") + Ol( + listOf( + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) + ), + mapOf("start" to "9") + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -419,12 +481,16 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ol( + CustomDocTag( listOf( - Li(listOf(P(listOf(Text("list item 1 continue 1"))))), - Li(listOf(P(listOf(Text("list item 2 continue 2"))))) - ), - mapOf("start" to "2") + Ol( + listOf( + Li(listOf(P(listOf(Text("list item 1 continue 1"))))), + Li(listOf(P(listOf(Text("list item 2 continue 2"))))) + ), + mapOf("start" to "2") + ) + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -443,32 +509,36 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - Ol( + CustomDocTag( listOf( - Li( + Ol( listOf( - P( + Li( listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 1 continue 1") + P( + listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 1 continue 1") + ) + ) ) - ) - ) - ), - Li( - listOf( - P( + ), + Li( listOf( - Text("list "), - B(listOf(Text("item"))), - Text(" 2 continue 2") + P( + listOf( + Text("list "), + B(listOf(Text("item"))), + Text(" 2 continue 2") + ) + ) ) ) - ) + ), + mapOf("start" to "1") ) - ), - mapOf("start" to "1") + ), name = MarkdownElementTypes.MARKDOWN_FILE.name ) ) ) @@ -494,7 +564,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( |
