diff options
| author | BarkingBad <32793002+BarkingBad@users.noreply.github.com> | 2019-12-13 14:01:25 +0100 |
|---|---|---|
| committer | Kamil Doległo <kamilok1965@interia.pl> | 2019-12-13 14:02:13 +0100 |
| commit | dd017a44ed7baae83f4f09a92d9691231f424eaa (patch) | |
| tree | ad9a7b6634ff4e4ead43122b13b0fb6dcdfcea85 /core | |
| parent | 0900b0f1c3a593301a6229ce93a23b8228771d24 (diff) | |
| download | dokka-dd017a44ed7baae83f4f09a92d9691231f424eaa.tar.gz dokka-dd017a44ed7baae83f4f09a92d9691231f424eaa.tar.bz2 dokka-dd017a44ed7baae83f4f09a92d9691231f424eaa.zip | |
Add abstract structure for MD/HTML comments and MD parser
Diffstat (limited to 'core')
22 files changed, 721 insertions, 335 deletions
diff --git a/core/build.gradle b/core/build.gradle index 20ff8760..f9ab0f37 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -28,7 +28,7 @@ dependencies { compile "org.jetbrains.kotlin:kotlin-reflect:$bundled_kotlin_compiler_version" compile group: 'com.google.inject', name: 'guice', version: '3.0' - compile "org.jsoup:jsoup:1.8.3" + implementation "org.jsoup:jsoup:1.12.1" compile "org.jetbrains.kotlin:kotlin-compiler:$bundled_kotlin_compiler_version" compile "org.jetbrains.kotlin:kotlin-script-runtime:$bundled_kotlin_compiler_version" diff --git a/core/src/main/kotlin/model/DocumentationNode.kt b/core/src/main/kotlin/model/Documentable.kt index 77225eca..9f676a1e 100644 --- a/core/src/main/kotlin/model/DocumentationNode.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -1,11 +1,11 @@ package org.jetbrains.dokka.model +import model.doc.* import org.jetbrains.dokka.transformers.descriptors.KotlinTypeWrapper import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.pages.PlatformData -import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag -class Module(val packages: List<Package>) : DocumentationNode() { +class Module(val packages: List<Package>) : Documentable() { override val dri: DRI = DRI.topLevel override val children: List<Package> = packages override val extra: MutableSet<Extra> = mutableSetOf() @@ -70,73 +70,77 @@ class Parameter( val type: TypeWrapper, override val actual: List<PlatformInfo>, override val extra: MutableSet<Extra> = mutableSetOf() -) : DocumentationNode() { - override val children: List<DocumentationNode> +) : Documentable() { + override val children: List<Documentable> get() = emptyList() } interface PlatformInfo { - val docTag: KDocTag? - val links: Map<String, DRI> + val documentationNode: DocumentationNode val platformData: List<PlatformData> } class BasePlatformInfo( - override val docTag: KDocTag?, - override val links: Map<String, DRI>, + override val documentationNode: DocumentationNode, override val platformData: List<PlatformData>) : PlatformInfo { override fun equals(other: Any?): Boolean = - other is PlatformInfo && ( - docTag?.text == other.docTag?.text && - links == other.links) + other is PlatformInfo && documentationNode == other.documentationNode override fun hashCode(): Int = - listOf(docTag?.text, links).hashCode() + documentationNode.hashCode() } class ClassPlatformInfo( val info: PlatformInfo, val inherited: List<DRI>) : PlatformInfo by info -abstract class DocumentationNode { +abstract class Documentable { open val expected: PlatformInfo? = null open val actual: List<PlatformInfo> = emptyList() open val name: String? = null val platformInfo by lazy { listOfNotNull(expected) + actual } val platformData by lazy { platformInfo.flatMap { it.platformData }.toSet() } - abstract val dri: DRI - abstract val children: List<DocumentationNode> + abstract val children: List<Documentable> override fun toString(): String { return "${javaClass.simpleName}($dri)" + briefDocstring.takeIf { it.isNotBlank() }?.let { " [$it]" }.orEmpty() } - override fun equals(other: Any?) = other is DocumentationNode && this.dri == other.dri + override fun equals(other: Any?) = other is Documentable && this.dri == other.dri override fun hashCode() = dri.hashCode() - val commentsData: List<Pair<String, Map<String, DRI>>> - get() = platformInfo.mapNotNull { it.docTag?.let { tag -> Pair(tag.getContent(), it.links) } } + + + val commentsData: List<DocumentationNode> + get() = platformInfo.map { it.documentationNode } val briefDocstring: String - get() = platformInfo.firstOrNull()?.docTag?.getContent().orEmpty().shorten(40) + 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) } + } open val extra: MutableSet<Extra> = mutableSetOf() } -abstract class ScopeNode : DocumentationNode() { +abstract class ScopeNode : Documentable() { abstract val functions: List<Function> abstract val properties: List<Property> abstract val classes: List<Class> - override val children: List<DocumentationNode> + override val children: List<Documentable> get() = functions + properties + classes } -abstract class CallableNode : DocumentationNode() { +abstract class CallableNode : Documentable() { abstract val receiver: Parameter? } @@ -152,7 +156,7 @@ interface TypeWrapper { } interface ClassKind -fun DocumentationNode.dfs(predicate: (DocumentationNode) -> Boolean): DocumentationNode? = +fun Documentable.dfs(predicate: (Documentable) -> Boolean): Documentable? = if (predicate(this)) { this } else { diff --git a/core/src/main/kotlin/model/doc/DocNode.kt b/core/src/main/kotlin/model/doc/DocNode.kt new file mode 100644 index 00000000..0c643551 --- /dev/null +++ b/core/src/main/kotlin/model/doc/DocNode.kt @@ -0,0 +1,74 @@ +package model.doc + +import org.jetbrains.dokka.links.DRI + +sealed class DocNode( + val children: List<DocNode>, + val params: Map<String, String> +) + +class A(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Big(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class B(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class BlockQuote(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Cite(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Code(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Dd(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Dfn(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Dir(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Div(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Dl(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Dt(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Em(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Font(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Footer(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Frame(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class FrameSet(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class H1(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class H2(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class H3(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class H4(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class H5(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class H6(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Head(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Header(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Html(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class I(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class IFrame(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Img(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Input(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Li(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Link(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Listing(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Main(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Menu(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Meta(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Nav(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class NoFrames(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class NoScript(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Ol(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class P(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Pre(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Script(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Section(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Small(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Span(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Strong(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Sub(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Sup(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Table(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Text(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap(), val body: String = "") : DocNode(children, params) +class TBody(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Td(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class TFoot(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Th(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class THead(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Title(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Tr(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Tt(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class U(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Ul(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class Var(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(children, params) +class DocumentationLink(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap(), val dri: DRI) : DocNode(children, params) +class HorizontalRule() : DocNode(emptyList(), emptyMap()) +class CustomNode(children: List<DocNode> = emptyList(), params: Map<String, String> = emptyMap()) : DocNode(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 new file mode 100644 index 00000000..0888876e --- /dev/null +++ b/core/src/main/kotlin/model/doc/DocType.kt @@ -0,0 +1,18 @@ +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 new file mode 100644 index 00000000..73424616 --- /dev/null +++ b/core/src/main/kotlin/model/doc/DocumentationNode.kt @@ -0,0 +1,3 @@ +package model.doc + +data class DocumentationNode(val children: List<DocType>)
\ No newline at end of file diff --git a/core/src/main/kotlin/pages/DefaultMarkdownToContentConverter.kt b/core/src/main/kotlin/pages/DefaultMarkdownToContentConverter.kt deleted file mode 100644 index bb8a826d..00000000 --- a/core/src/main/kotlin/pages/DefaultMarkdownToContentConverter.kt +++ /dev/null @@ -1,229 +0,0 @@ -package org.jetbrains.dokka.pages - -import org.intellij.markdown.MarkdownElementTypes -import org.intellij.markdown.MarkdownTokenTypes -import org.jetbrains.dokka.markdown.MarkdownNode -import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.plugability.DokkaContext - -class DefaultMarkdownToContentConverter( - private val context: DokkaContext -) : MarkdownToContentConverter { - override fun buildContent( - node: MarkdownNode, - dci: DCI, - platforms: Set<PlatformData>, - links: Map<String, DRI>, - styles: Set<Style>, - extras: Set<Extra> - - ): List<ContentNode> { -// println(tree.toTestString()) - - fun buildChildren(node: MarkdownNode, newStyles: Set<Style> = emptySet(), newExtras: Set<Extra> = emptySet()) = - node.children.flatMap { - buildContent(it, dci, platforms, links, styles + newStyles, extras + newExtras) - }.coalesceText(platforms, styles + newStyles, extras + newExtras) - - fun buildHeader(level: Int) = - ContentHeader(buildChildren(node), level, dci, platforms, styles) - - return when (node.type) { - MarkdownElementTypes.ATX_1 -> listOf(buildHeader(1)) - MarkdownElementTypes.ATX_2 -> listOf(buildHeader(2)) - MarkdownElementTypes.ATX_3 -> listOf(buildHeader(3)) - MarkdownElementTypes.ATX_4 -> listOf(buildHeader(4)) - MarkdownElementTypes.ATX_5 -> listOf(buildHeader(5)) - MarkdownElementTypes.ATX_6 -> listOf(buildHeader(6)) - MarkdownElementTypes.UNORDERED_LIST -> listOf( - ContentList( - buildChildren(node), - false, - dci, - platforms, - styles, - extras - ) - ) - MarkdownElementTypes.ORDERED_LIST -> listOf( - ContentList( - buildChildren(node), - true, - dci, - platforms, - styles, - extras - ) - ) - MarkdownElementTypes.LIST_ITEM -> TODO() - MarkdownElementTypes.STRONG, - MarkdownTokenTypes.EMPH, - MarkdownElementTypes.EMPH -> - buildChildren(node, setOf(TextStyle.Strong)) - // TODO - MarkdownElementTypes.CODE_SPAN -> TODO() -// val startDelimiter = node.child(MarkdownTokenTypes.BACKTICK)?.text -// if (startDelimiter != null) { -// val text = node.text.substring(startDelimiter.length).removeSuffix(startDelimiter) -// val codeSpan = ContentCode().apply { append(ContentText(text)) } -// parent.append(codeSpan) -// } - - MarkdownElementTypes.CODE_BLOCK, - MarkdownElementTypes.CODE_FENCE -> { - val language = node.child(MarkdownTokenTypes.FENCE_LANG)?.text?.trim() ?: "" - listOf(ContentCode(buildChildren(node), language, dci, platforms, styles, extras)) // TODO - } - MarkdownElementTypes.PARAGRAPH -> buildChildren(node, newStyles = setOf(TextStyle.Paragraph)) - - MarkdownElementTypes.INLINE_LINK -> { -// val linkTextNode = node.child(MarkdownElementTypes.LINK_TEXT) -// val destination = node.child(MarkdownElementTypes.LINK_DESTINATION) -// if (linkTextNode != null) { -// if (destination != null) { -// val link = ContentExternalLink(destination.text) -// renderLinkTextTo(linkTextNode, link, linkResolver) -// parent.append(link) -// } else { -// val link = ContentExternalLink(linkTextNode.getLabelText()) -// renderLinkTextTo(linkTextNode, link, linkResolver) -// parent.append(link) -// } -// } - //TODO: Linking!!! -// ContentLink() - TODO() - } - MarkdownElementTypes.SHORT_REFERENCE_LINK, - MarkdownElementTypes.FULL_REFERENCE_LINK -> { - val destinationNode = node.children.find { it.type == MarkdownElementTypes.LINK_DESTINATION } - ?: node.children.first { it.type == MarkdownElementTypes.LINK_LABEL } - val destination = destinationNode.children.find { it.type == MarkdownTokenTypes.TEXT }?.text - ?: destinationNode.text - links[destination]?.let { dri -> - listOf( - ContentDRILink( // TODO: differentiate between KDoc link and some external link (http://...) - buildChildren(node), - dri, - DCI(dri, ContentKind.Symbol), - platforms, - styles, - extras - ) - ) - } ?: let { - context.logger.error("Apparently there is no link resolved for $destination") - emptyList<ContentNode>() - } - } - MarkdownTokenTypes.WHITE_SPACE -> { - // Don't append first space if start of header (it is added during formatting later) - // v - // #### Some Heading -// if (nodeStack.peek() !is ContentHeading || node.parent?.children?.first() != node) { -// parent.append(ContentText(node.text)) -// } - listOf(ContentText(" ", dci, platforms, styles, extras)) - } - MarkdownTokenTypes.EOL -> { -// if ((keepEol(nodeStack.peek()) && node.parent?.children?.last() != node) || -// // Keep extra blank lines when processing lists (affects Markdown formatting) -// (processingList(nodeStack.peek()) && node.previous?.type == MarkdownTokenTypes.EOL)) { -// parent.append(ContentText(node.text)) -// } - listOf(ContentText(" ", dci, platforms, styles, extras)) - } - - MarkdownTokenTypes.CODE_LINE -> { - listOf(ContentText(node.text, dci, platforms, styles, extras)) // TODO check -// if (parent is ContentBlockCode) { -// parent.append(content) -// } else { -// parent.append(ContentBlockCode().apply { append(content) }) -// } - } - - MarkdownTokenTypes.TEXT -> -// fun createEntityOrText(text: String): ContentNode { -// if (text == "&" || text == """ || text == "<" || text == ">") { -// return ContentEntity(text) -// } -// if (text == "&") { -// return ContentEntity("&") -// } -// val decodedText = EntityConverter.replaceEntities(text, true, true) -// if (decodedText != text) { -// return ContentEntity(text) -// } -// return ContentText(text) -// } -// -// parent.append(createEntityOrText(node.text)) - listOf(ContentText(node.text, dci, platforms, styles, extras)) // TODO - - MarkdownTokenTypes.COLON, - MarkdownTokenTypes.SINGLE_QUOTE, - MarkdownTokenTypes.DOUBLE_QUOTE, - MarkdownTokenTypes.LT, - MarkdownTokenTypes.GT, - MarkdownTokenTypes.LPAREN, - MarkdownTokenTypes.RPAREN, - MarkdownTokenTypes.LBRACKET, - MarkdownTokenTypes.RBRACKET, - MarkdownTokenTypes.EXCLAMATION_MARK, - MarkdownTokenTypes.BACKTICK, - MarkdownTokenTypes.CODE_FENCE_CONTENT -> { - listOf(ContentText(node.text, dci, platforms, styles, extras)) - } - - MarkdownElementTypes.LINK_DEFINITION -> TODO() - - MarkdownTokenTypes.EMAIL_AUTOLINK -> - listOf( - ContentResolvedLink( - listOf(ContentText(node.text, dci, platforms, styles, extras)), - "mailto:${node.text}", - dci, platforms, styles, extras - ) - ) - - else -> buildChildren(node) - } - } - - private fun Collection<ContentNode>.coalesceText( - platforms: Set<PlatformData>, - styles: Set<Style>, - extras: Set<Extra> - ) = - this - .sliceWhen { prev, next -> prev::class != next::class } - .flatMap { nodes -> - when (nodes.first()) { - is ContentText -> listOf( - ContentText( - nodes.joinToString("") { (it as ContentText).text }, - nodes.first().dci, platforms, styles, extras - ) - ) - else -> nodes - } - } -} - -fun <T> Collection<T>.sliceWhen(predicate: (before: T, after: T) -> Boolean): Collection<Collection<T>> { - val newCollection = mutableListOf<Collection<T>>() - var currentSlice = mutableListOf<T>() - for ((prev, next) in this.windowed(2, 1, false)) { - currentSlice.add(prev) - if (predicate(prev, next)) { - newCollection.add(currentSlice) - currentSlice = mutableListOf<T>() - } - } - if (this.isNotEmpty()) { - currentSlice.add(this.last()) - newCollection.add(currentSlice) - } - return newCollection -}
\ No newline at end of file diff --git a/core/src/main/kotlin/pages/DocNodeToContentConverter.kt b/core/src/main/kotlin/pages/DocNodeToContentConverter.kt new file mode 100644 index 00000000..dce69114 --- /dev/null +++ b/core/src/main/kotlin/pages/DocNodeToContentConverter.kt @@ -0,0 +1,82 @@ +package org.jetbrains.dokka.pages + +import model.doc.* +import org.intellij.markdown.MarkdownElementTypes +import org.intellij.markdown.MarkdownTokenTypes +import org.jetbrains.dokka.markdown.MarkdownNode +import org.jetbrains.dokka.plugability.DokkaContext + +class DocNodeToContentConverter( + private val context: DokkaContext +) : MarkdownToContentConverter { + override fun buildContent( + docNode: DocNode, + dci: DCI, + platforms: Set<PlatformData>, + styles: Set<Style>, + extras: Set<Extra> + + ): List<ContentNode> { + + fun buildChildren(docNode: DocNode, newStyles: Set<Style> = emptySet(), newExtras: Set<Extra> = emptySet()) = + docNode.children.flatMap { + buildContent(it, dci, platforms, styles + newStyles, extras + newExtras) + } + + fun buildHeader(level: Int) = + listOf(ContentHeader(buildChildren(docNode), level, dci, platforms, styles, extras)) + + fun buildList(ordered: Boolean) = + listOf(ContentList(buildChildren(docNode), ordered, dci, platforms, styles, extras)) + + return when (docNode) { + 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(docNode) + is B -> buildChildren(docNode, setOf(TextStyle.Strong)) + is I -> buildChildren(docNode, setOf(TextStyle.Italic)) + is P -> buildChildren(docNode, newStyles = setOf(TextStyle.Paragraph)) + is A -> listOf( + ContentResolvedLink( + buildChildren(docNode), + docNode.params.get("href")!!, + dci, + platforms, + styles, + extras + ) + ) + is DocumentationLink -> listOf( + ContentDRILink( + buildChildren(docNode), + docNode.dri, + DCI(docNode.dri, ContentKind.Symbol), + platforms, + styles, + extras + ) + ) + is BlockQuote -> throw NotImplementedError("Implement DocNotToContent BlockQuote!") + is Code -> listOf( + ContentCode( + buildChildren(docNode), + "", + dci, + platforms, + styles, + extras + ) + ) + is Img -> throw NotImplementedError("Implement DocNotToContent Img!") + is HorizontalRule -> listOf(ContentText("", dci, platforms, setOf())) + is Text -> listOf(ContentText(docNode.body, dci, platforms, styles, extras)) + else -> buildChildren(docNode) + } + } +} diff --git a/core/src/main/kotlin/pages/MarkdownToContentConverter.kt b/core/src/main/kotlin/pages/MarkdownToContentConverter.kt index cd96ff79..321a3f02 100644 --- a/core/src/main/kotlin/pages/MarkdownToContentConverter.kt +++ b/core/src/main/kotlin/pages/MarkdownToContentConverter.kt @@ -1,14 +1,14 @@ package org.jetbrains.dokka.pages +import model.doc.DocNode import org.jetbrains.dokka.markdown.MarkdownNode import org.jetbrains.dokka.links.DRI interface MarkdownToContentConverter { fun buildContent( - node: MarkdownNode, + docNode: DocNode, dci: DCI, platforms: Set<PlatformData>, - links: Map<String, DRI> = emptyMap(), styles: Set<Style> = emptySet(), extras: Set<Extra> = emptySet() ): List<ContentNode> diff --git a/core/src/main/kotlin/pages/PageBuilder.kt b/core/src/main/kotlin/pages/PageBuilder.kt index 92e2c5fe..8951219a 100644 --- a/core/src/main/kotlin/pages/PageBuilder.kt +++ b/core/src/main/kotlin/pages/PageBuilder.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.pages +import model.doc.DocType import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.Function @@ -29,7 +30,7 @@ class DefaultPageBuilder( else -> throw IllegalStateException("$m should not be present here") } - private fun group(node: DocumentationNode, content: PageContentBuilderFunction) = + private fun group(node: Documentable, content: PageContentBuilderFunction) = rootContentGroup(node, ContentKind.Main, content) private fun contentForModule(m: Module) = group(m) { @@ -60,7 +61,13 @@ class DefaultPageBuilder( header(2) { text("SuperInterfaces") } linkTable(it) } - c.commentsData.forEach { (doc, links) -> comment(doc, links) } + c.commentsData.forEach { + it.children.forEach { + header(3) { text(it.toHeaderString()) } + comment(it.root) + text("\n") + } + } block("Constructors", 2, ContentKind.Functions, c.constructors, c.platformData) { link(it.name, it.dri) signature(it) @@ -71,20 +78,26 @@ class DefaultPageBuilder( signature(it) text(it.briefDocstring) } + block("Properties", 2, ContentKind.Properties, c.properties, c.platformData) { + link(it.name, it.dri) + text(it.briefDocstring) + } } private fun contentForFunction(f: Function) = group(f) { header(1) { text(f.name) } signature(f) - f.commentsData.forEach { (doc, links) -> markdown(doc, links) } + f.commentsData.forEach { it.children.forEach { comment(it.root) } } block("Parameters", 2, ContentKind.Parameters, f.children, f.platformData) { text(it.name ?: "<receiver>") - i |
