From 288431f21b18f5311de77c9afcb29346cb7c6498 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Fri, 13 Dec 2019 16:24:16 +0100 Subject: Changes naming and applies pull request's requirements --- core/src/main/kotlin/CoreExtensions.kt | 4 +- core/src/main/kotlin/model/Documentable.kt | 23 +++--- core/src/main/kotlin/model/doc/DocNode.kt | 74 ------------------ core/src/main/kotlin/model/doc/DocTag.kt | 81 +++++++++++++++++++ core/src/main/kotlin/model/doc/DocType.kt | 18 ----- .../src/main/kotlin/model/doc/DocumentationNode.kt | 4 +- core/src/main/kotlin/model/doc/TagWrapper.kt | 18 +++++ .../kotlin/pages/CommentsToContentConverter.kt | 13 ++++ .../main/kotlin/pages/DocNodeToContentConverter.kt | 82 ------------------- .../main/kotlin/pages/DocTagToContentConverter.kt | 79 +++++++++++++++++++ .../kotlin/pages/MarkdownToContentConverter.kt | 15 ---- core/src/main/kotlin/pages/PageBuilder.kt | 14 ++-- core/src/main/kotlin/pages/PageContentBuilder.kt | 18 ++--- core/src/main/kotlin/parsers/HtmlParser.kt | 10 +-- core/src/main/kotlin/parsers/MarkdownParser.kt | 91 ++++++++++++---------- core/src/main/kotlin/parsers/Parser.kt | 12 +-- .../factories/DocNodesFromIElementFactory.kt | 6 +- .../parsers/factories/DocNodesFromStringFactory.kt | 6 +- .../main/kotlin/plugability/DefaultExtensions.kt | 4 +- .../DefaultDescriptorToDocumentationTranslator.kt | 2 +- .../DefaultDocumentationToPageTranslator.kt | 2 +- plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt | 11 +-- plugins/xml/src/main/kotlin/XmlPlugin.kt | 4 +- 23 files changed, 302 insertions(+), 289 deletions(-) delete mode 100644 core/src/main/kotlin/model/doc/DocNode.kt create mode 100644 core/src/main/kotlin/model/doc/DocTag.kt delete mode 100644 core/src/main/kotlin/model/doc/DocType.kt create mode 100644 core/src/main/kotlin/model/doc/TagWrapper.kt create mode 100644 core/src/main/kotlin/pages/CommentsToContentConverter.kt delete mode 100644 core/src/main/kotlin/pages/DocNodeToContentConverter.kt create mode 100644 core/src/main/kotlin/pages/DocTagToContentConverter.kt delete mode 100644 core/src/main/kotlin/pages/MarkdownToContentConverter.kt diff --git a/core/src/main/kotlin/CoreExtensions.kt b/core/src/main/kotlin/CoreExtensions.kt index 87509dc4..7393dd68 100644 --- a/core/src/main/kotlin/CoreExtensions.kt +++ b/core/src/main/kotlin/CoreExtensions.kt @@ -1,6 +1,6 @@ package org.jetbrains.dokka -import org.jetbrains.dokka.pages.MarkdownToContentConverter +import org.jetbrains.dokka.pages.CommentsToContentConverter import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.ExtensionPoint @@ -23,7 +23,7 @@ object CoreExtensions { val descriptorToDocumentationTranslator by coreExtension() val documentationMerger by coreExtension() val documentationTransformer by coreExtension() - val markdownToContentConverterFactory by coreExtension<(DokkaContext) -> MarkdownToContentConverter>() + val commentsToContentConverterFactory by coreExtension<(DokkaContext) -> CommentsToContentConverter>() val documentationToPageTranslator by coreExtension() val pageTransformer by coreExtension() val rendererFactory by coreExtension<(FileWriter, LocationProvider, DokkaContext) -> Renderer>() diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index 9f676a1e..4bdd41ae 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -1,6 +1,6 @@ package org.jetbrains.dokka.model -import model.doc.* +import org.jetbrains.dokka.model.doc.* import org.jetbrains.dokka.transformers.descriptors.KotlinTypeWrapper import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.pages.PlatformData @@ -106,7 +106,7 @@ abstract class Documentable { abstract val children: List override fun toString(): String { - return "${javaClass.simpleName}($dri)" + briefDocstring.takeIf { it.isNotBlank() }?.let { " [$it]" }.orEmpty() + return "${javaClass.simpleName}($dri)" + briefDocTagString.takeIf { it.isNotBlank() }?.let { " [$it]" }.orEmpty() } override fun equals(other: Any?) = other is Documentable && this.dri == other.dri @@ -118,15 +118,16 @@ abstract class Documentable { val commentsData: List get() = platformInfo.map { it.documentationNode } - val briefDocstring: String - get() = docNodeSummary(platformInfo.firstOrNull()?.documentationNode?.children?.firstOrNull()?.root ?: Text(body = "")).shorten(40) - - private fun docNodeSummary(docNode: DocNode): String { - if(docNode.children.isEmpty() && docNode is Text) - return docNode.body - - return docNode.children.joinToString(" ") { docNodeSummary(it) } - } + val briefDocTagString: String + get() = + platformInfo + .firstOrNull() + ?.documentationNode + ?.children + ?.firstOrNull() + ?.root + ?.docTagSummary() + ?.shorten(40) ?: "" open val extra: MutableSet = mutableSetOf() } diff --git a/core/src/main/kotlin/model/doc/DocNode.kt b/core/src/main/kotlin/model/doc/DocNode.kt deleted file mode 100644 index 0c643551..00000000 --- a/core/src/main/kotlin/model/doc/DocNode.kt +++ /dev/null @@ -1,74 +0,0 @@ -package model.doc - -import org.jetbrains.dokka.links.DRI - -sealed class DocNode( - val children: List, - val params: Map -) - -class A(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Big(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class B(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class BlockQuote(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Cite(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Code(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Dd(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Dfn(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Dir(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Div(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Dl(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Dt(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Em(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Font(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Footer(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Frame(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class FrameSet(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class H1(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class H2(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class H3(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class H4(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class H5(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class H6(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Head(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Header(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Html(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class I(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class IFrame(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Img(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Input(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Li(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Link(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Listing(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Main(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Menu(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Meta(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Nav(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class NoFrames(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class NoScript(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Ol(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class P(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Pre(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Script(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Section(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Small(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Span(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Strong(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Sub(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Sup(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Table(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Text(children: List = emptyList(), params: Map = emptyMap(), val body: String = "") : DocNode(children, params) -class TBody(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Td(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class TFoot(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Th(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class THead(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Title(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Tr(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Tt(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class U(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Ul(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class Var(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) -class DocumentationLink(children: List = emptyList(), params: Map = emptyMap(), val dri: DRI) : DocNode(children, params) -class HorizontalRule() : DocNode(emptyList(), emptyMap()) -class CustomNode(children: List = emptyList(), params: Map = emptyMap()) : DocNode(children, params) \ No newline at end of file diff --git a/core/src/main/kotlin/model/doc/DocTag.kt b/core/src/main/kotlin/model/doc/DocTag.kt new file mode 100644 index 00000000..6d5850a0 --- /dev/null +++ b/core/src/main/kotlin/model/doc/DocTag.kt @@ -0,0 +1,81 @@ +package org.jetbrains.dokka.model.doc + +import org.jetbrains.dokka.links.DRI + +sealed class DocTag( + val children: List, + val params: Map +) { + fun docTagSummary(): String { + if(this.children.isEmpty() && this is Text) + return this.body + + return this.children.joinToString(" ") { it.docTagSummary() } + } +} + +class A(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Big(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class B(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class BlockQuote(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Cite(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Code(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Dd(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Dfn(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Dir(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Div(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Dl(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Dt(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Em(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Font(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Footer(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Frame(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class FrameSet(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class H1(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class H2(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class H3(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class H4(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class H5(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class H6(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Head(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Header(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Html(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class I(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class IFrame(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Img(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Input(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Li(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Link(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Listing(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Main(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Menu(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Meta(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Nav(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class NoFrames(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class NoScript(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Ol(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class P(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Pre(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Script(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Section(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Small(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Span(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Strong(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Sub(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Sup(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Table(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Text(children: List = emptyList(), params: Map = emptyMap(), val body: String = "") : DocTag(children, params) +class TBody(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Td(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class TFoot(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Th(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class THead(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Title(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Tr(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Tt(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class U(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Ul(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class Var(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) +class DocumentationLink(children: List = emptyList(), params: Map = emptyMap(), val dri: DRI) : DocTag(children, params) +class HorizontalRule : DocTag(emptyList(), emptyMap()) +class CustomDocTag(children: List = emptyList(), params: Map = emptyMap()) : DocTag(children, params) \ No newline at end of file diff --git a/core/src/main/kotlin/model/doc/DocType.kt b/core/src/main/kotlin/model/doc/DocType.kt deleted file mode 100644 index 0888876e..00000000 --- a/core/src/main/kotlin/model/doc/DocType.kt +++ /dev/null @@ -1,18 +0,0 @@ -package model.doc - -sealed class DocType(val root: DocNode) -class Description(root: DocNode) : DocType(root) -class Author(root: DocNode) : DocType(root) -class Version(root: DocNode) : DocType(root) -class Since(root: DocNode) : DocType(root) -class See(root: DocNode, val name: String) : DocType(root) -class Param(root: DocNode, val name: String) : DocType(root) -class Return(root: DocNode) : DocType(root) -class Receiver(root: DocNode) : DocType(root) -class Constructor(root: DocNode) : DocType(root) -class Throws(root: DocNode, val name: String) : DocType(root) -class Sample(root: DocNode, val name: String) : DocType(root) -class Deprecated(root: DocNode) : DocType(root) -class Property(root: DocNode, val name: String) : DocType(root) -class Suppress(root: DocNode) : DocType(root) -class CustomTag(root: DocNode, val name: String) : DocType(root) diff --git a/core/src/main/kotlin/model/doc/DocumentationNode.kt b/core/src/main/kotlin/model/doc/DocumentationNode.kt index 73424616..a143a941 100644 --- a/core/src/main/kotlin/model/doc/DocumentationNode.kt +++ b/core/src/main/kotlin/model/doc/DocumentationNode.kt @@ -1,3 +1,3 @@ -package model.doc +package org.jetbrains.dokka.model.doc -data class DocumentationNode(val children: List) \ No newline at end of file +data class DocumentationNode(val children: List) \ No newline at end of file diff --git a/core/src/main/kotlin/model/doc/TagWrapper.kt b/core/src/main/kotlin/model/doc/TagWrapper.kt new file mode 100644 index 00000000..8def013e --- /dev/null +++ b/core/src/main/kotlin/model/doc/TagWrapper.kt @@ -0,0 +1,18 @@ +package org.jetbrains.dokka.model.doc + +sealed class TagWrapper(val root: DocTag) +class Description(root: DocTag) : TagWrapper(root) +class Author(root: DocTag) : TagWrapper(root) +class Version(root: DocTag) : TagWrapper(root) +class Since(root: DocTag) : TagWrapper(root) +class See(root: DocTag, val name: String) : TagWrapper(root) +class Param(root: DocTag, val name: String) : TagWrapper(root) +class Return(root: DocTag) : TagWrapper(root) +class Receiver(root: DocTag) : TagWrapper(root) +class Constructor(root: DocTag) : TagWrapper(root) +class Throws(root: DocTag, val name: String) : TagWrapper(root) +class Sample(root: DocTag, val name: String) : TagWrapper(root) +class Deprecated(root: DocTag) : TagWrapper(root) +class Property(root: DocTag, val name: String) : TagWrapper(root) +class Suppress(root: DocTag) : TagWrapper(root) +class CustomWrapperTag(root: DocTag, val name: String) : TagWrapper(root) \ No newline at end of file diff --git a/core/src/main/kotlin/pages/CommentsToContentConverter.kt b/core/src/main/kotlin/pages/CommentsToContentConverter.kt new file mode 100644 index 00000000..78c7ff4c --- /dev/null +++ b/core/src/main/kotlin/pages/CommentsToContentConverter.kt @@ -0,0 +1,13 @@ +package org.jetbrains.dokka.pages + +import org.jetbrains.dokka.model.doc.DocTag + +interface CommentsToContentConverter { + fun buildContent( + docTag: DocTag, + dci: DCI, + platforms: Set, + styles: Set