aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/pages
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2019-11-05 22:10:13 +0100
committerKamil Doległo <kamilok1965@interia.pl>2019-11-05 22:11:14 +0100
commitae53f0525c676a5483609fdde144594a36d8d582 (patch)
treed20827c0c86344c7741e81a12641b2a33e7aa34b /core/src/main/kotlin/pages
parent508afa4fa2bddf4b05cb888340d0dbfc0ec40d9b (diff)
downloaddokka-ae53f0525c676a5483609fdde144594a36d8d582.tar.gz
dokka-ae53f0525c676a5483609fdde144594a36d8d582.tar.bz2
dokka-ae53f0525c676a5483609fdde144594a36d8d582.zip
Add merger (sort of)
Diffstat (limited to 'core/src/main/kotlin/pages')
-rw-r--r--core/src/main/kotlin/pages/ContentNodes.kt24
-rw-r--r--core/src/main/kotlin/pages/MarkdownToContentConverter.kt44
-rw-r--r--core/src/main/kotlin/pages/PageNodes.kt10
3 files changed, 42 insertions, 36 deletions
diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt
index 2dffbb17..a2b884a8 100644
--- a/core/src/main/kotlin/pages/ContentNodes.kt
+++ b/core/src/main/kotlin/pages/ContentNodes.kt
@@ -3,80 +3,80 @@ package org.jetbrains.dokka.pages
import org.jetbrains.dokka.links.DRI
interface ContentNode {
- val platforms: List<PlatformData>
+ val dci: DCI
val annotations: List<Annotation>
}
/** Comment consisting of parts, eg. [ContentText]s, [ContentLink]s and so on */
data class ContentComment(val parts: List<ContentNode>,
- override val platforms: List<PlatformData>,
+ override val dci: DCI,
override val annotations: List<Annotation> = emptyList()
): ContentNode
/** Simple text */
data class ContentText(val text: String,
- override val platforms: List<PlatformData>,
+ override val dci: DCI,
override val annotations: List<Annotation> = emptyList()
): ContentNode
///** Headers */ TODO for next iteration
data class ContentHeader(val items: List<ContentNode>,
val level: Int,
- override val platforms: List<PlatformData>,
+ override val dci: DCI,
override val annotations: List<Annotation> = emptyList()
): ContentNode
/** Lists */
data class ContentList(val items: List<ContentNode>,
val ordered: Boolean,
- override val platforms: List<PlatformData>,
+ override val dci: DCI,
override val annotations: List<Annotation> = emptyList()
): ContentNode
/** Styled elements, eg. bold, strikethrough, emphasis and so on **/
data class ContentStyle(val items: List<ContentNode>,
val style: IStyle,
- override val platforms: List<PlatformData>,
+ override val dci: DCI,
override val annotations: List<Annotation> = emptyList()
): ContentNode
/** Code blocks */
data class ContentCode(val code: String,
val language: String,
- override val platforms: List<PlatformData>,
+ override val dci: DCI,
override val annotations: List<Annotation> = emptyList()
): ContentNode
/** Symbols, eg. `open fun foo(): String`, or `class Bar`, consisting of parts like [ContentText] and [ContentLink] */
data class ContentSymbol(val parts: List<ContentNode>,
- override val platforms: List<PlatformData>,
+ override val dci: DCI,
override val annotations: List<Annotation> = emptyList()
): ContentNode
/** All links to classes, packages, etc. that have te be resolved */
data class ContentLink(val text: String,
val address: DRI,
- override val platforms: List<PlatformData>,
+ override val dci: DCI,
override val annotations: List<Annotation> = emptyList()
): ContentNode
/** All links that do not need to be resolved */
data class ContentResolvedLink(val text: String,
val address: String,
- override val platforms: List<PlatformData>,
+ override val dci: DCI,
override val annotations: List<Annotation> = emptyList()
): ContentNode
/** Blocks of [ContentNode]s with name, eg. Functions, Types, Properties, etc. */
data class ContentBlock(val name: String,
val children: List<ContentNode>,
- override val platforms: List<PlatformData>,
+ override val dci: DCI,
override val annotations: List<Annotation> = emptyList()
): ContentNode
/** Logical grouping of [ContentNode]s, eg. [ContentLink], [ContentText] and [ContentSymbol] for one entity */
data class ContentGroup(val children: List<ContentNode>,
- override val platforms: List<PlatformData>,
+ override val dci: DCI,
override val annotations: List<Annotation> = emptyList()
): ContentNode
diff --git a/core/src/main/kotlin/pages/MarkdownToContentConverter.kt b/core/src/main/kotlin/pages/MarkdownToContentConverter.kt
index 9b249878..022826fa 100644
--- a/core/src/main/kotlin/pages/MarkdownToContentConverter.kt
+++ b/core/src/main/kotlin/pages/MarkdownToContentConverter.kt
@@ -15,37 +15,37 @@ class MarkdownToContentConverter(
) {
fun buildContent(
node: MarkdownNode,
- platforms: List<PlatformData>,
+ dci: DCI,
documentationNode: DocumentationNode<*>
): List<ContentNode> {
// println(tree.toTestString())
fun buildChildren(node: MarkdownNode) = node.children.flatMap {
- buildContent(it, platforms, documentationNode)
+ buildContent(it, dci, documentationNode)
}.coalesceText()
return when (node.type) {
- MarkdownElementTypes.ATX_1 -> listOf(ContentHeader(buildChildren(node), 1, platforms))
- MarkdownElementTypes.ATX_2 -> listOf(ContentHeader(buildChildren(node), 2, platforms))
- MarkdownElementTypes.ATX_3 -> listOf(ContentHeader(buildChildren(node), 3, platforms))
- MarkdownElementTypes.ATX_4 -> listOf(ContentHeader(buildChildren(node), 4, platforms))
- MarkdownElementTypes.ATX_5 -> listOf(ContentHeader(buildChildren(node), 5, platforms))
- MarkdownElementTypes.ATX_6 -> listOf(ContentHeader(buildChildren(node), 6, platforms))
- MarkdownElementTypes.UNORDERED_LIST -> listOf(ContentList(buildChildren(node), false, platforms))
- MarkdownElementTypes.ORDERED_LIST -> listOf(ContentList(buildChildren(node), true, platforms))
+ MarkdownElementTypes.ATX_1 -> listOf(ContentHeader(buildChildren(node), 1, dci))
+ MarkdownElementTypes.ATX_2 -> listOf(ContentHeader(buildChildren(node), 2, dci))
+ MarkdownElementTypes.ATX_3 -> listOf(ContentHeader(buildChildren(node), 3, dci))
+ MarkdownElementTypes.ATX_4 -> listOf(ContentHeader(buildChildren(node), 4, dci))
+ MarkdownElementTypes.ATX_5 -> listOf(ContentHeader(buildChildren(node), 5, dci))
+ MarkdownElementTypes.ATX_6 -> listOf(ContentHeader(buildChildren(node), 6, dci))
+ MarkdownElementTypes.UNORDERED_LIST -> listOf(ContentList(buildChildren(node), false, dci))
+ MarkdownElementTypes.ORDERED_LIST -> listOf(ContentList(buildChildren(node), true, dci))
MarkdownElementTypes.LIST_ITEM -> TODO()
MarkdownElementTypes.EMPH -> listOf(
ContentStyle(
buildChildren(node),
Style.Emphasis,
- platforms
+ dci
)
)// TODO
MarkdownElementTypes.STRONG -> listOf(
ContentStyle(
buildChildren(node),
Style.Strong,
- platforms
+ dci
)
) // TODO
MarkdownElementTypes.CODE_SPAN -> TODO()
@@ -59,13 +59,13 @@ class MarkdownToContentConverter(
MarkdownElementTypes.CODE_BLOCK,
MarkdownElementTypes.CODE_FENCE -> {
val language = node.child(MarkdownTokenTypes.FENCE_LANG)?.text?.trim() ?: ""
- listOf(ContentCode(buildChildren(node).toString(), language, platforms)) // TODO
+ listOf(ContentCode(buildChildren(node).toString(), language, dci)) // TODO
}
MarkdownElementTypes.PARAGRAPH -> listOf(
ContentStyle(
buildChildren(node),
Style.Paragraph,
- platforms
+ dci
)
) // TODO
@@ -105,7 +105,7 @@ class MarkdownToContentConverter(
)
}
.firstOrNull()
- ?.let { ContentLink(destination, DRI.from(it), platforms) }
+ ?.let { ContentLink(destination, DRI.from(it), dci) }
.let(::listOfNotNull)
} else {
logger.error("Apparently descriptor for $documentationNode was needed in model")
@@ -119,7 +119,7 @@ class MarkdownToContentConverter(
// if (nodeStack.peek() !is ContentHeading || node.parent?.children?.first() != node) {
// parent.append(ContentText(node.text))
// }
- listOf(ContentText(" ", platforms))
+ listOf(ContentText(" ", dci))
}
MarkdownTokenTypes.EOL -> {
// if ((keepEol(nodeStack.peek()) && node.parent?.children?.last() != node) ||
@@ -131,7 +131,7 @@ class MarkdownToContentConverter(
}
MarkdownTokenTypes.CODE_LINE -> {
- listOf(ContentText(node.text, platforms)) // TODO check
+ listOf(ContentText(node.text, dci)) // TODO check
// if (parent is ContentBlockCode) {
// parent.append(content)
// } else {
@@ -155,7 +155,7 @@ class MarkdownToContentConverter(
// }
//
// parent.append(createEntityOrText(node.text))
- listOf(ContentText(node.text, platforms)) // TODO
+ listOf(ContentText(node.text, dci)) // TODO
MarkdownTokenTypes.EMPH ->
@@ -163,7 +163,7 @@ class MarkdownToContentConverter(
// if (parentNodeType != MarkdownElementTypes.EMPH && parentNodeType != MarkdownElementTypes.STRONG) {
// parent.append(ContentText(node.text))
// }
- listOf(ContentStyle(buildChildren(node), Style.Emphasis, platforms)) // TODO
+ listOf(ContentStyle(buildChildren(node), Style.Emphasis, dci)) // TODO
MarkdownTokenTypes.COLON,
MarkdownTokenTypes.SINGLE_QUOTE,
@@ -177,13 +177,13 @@ class MarkdownToContentConverter(
MarkdownTokenTypes.EXCLAMATION_MARK,
MarkdownTokenTypes.BACKTICK,
MarkdownTokenTypes.CODE_FENCE_CONTENT -> {
- listOf(ContentText(node.text, platforms))
+ listOf(ContentText(node.text, dci))
}
MarkdownElementTypes.LINK_DEFINITION -> TODO()
MarkdownTokenTypes.EMAIL_AUTOLINK ->
- listOf(ContentResolvedLink(node.text, "mailto:${node.text}", platforms))
+ listOf(ContentResolvedLink(node.text, "mailto:${node.text}", dci))
else -> buildChildren(node)
}
@@ -197,7 +197,7 @@ class MarkdownToContentConverter(
is ContentText -> listOf(
ContentText(
nodes.joinToString("") { (it as ContentText).text },
- nodes.first().platforms
+ nodes.first().dci
)
)
else -> nodes
diff --git a/core/src/main/kotlin/pages/PageNodes.kt b/core/src/main/kotlin/pages/PageNodes.kt
index 3d2b6fb7..34662720 100644
--- a/core/src/main/kotlin/pages/PageNodes.kt
+++ b/core/src/main/kotlin/pages/PageNodes.kt
@@ -57,9 +57,15 @@ class MemberPageNode(
documentationNode: DocumentationNode<*>?
): PageNode(name, content, parent, dri, documentationNode) // functions, extension functions, properties
-data class PlatformData(val platformName: String, val platformType: Platform)
+data class PlatformData(val platformName: String, val platformType: Platform) {
+ override fun toString() = platformName
+}
+
+data class DCI(val dri: DRI, val platformDataList: List<PlatformData>) {
+ override fun toString() = "$dri[$platformDataList]"
+}
-fun PageNode.platforms(): List<PlatformData> = this.content.flatMap { it.platforms }.distinct() // TODO: Override equals???
+fun PageNode.platforms(): List<PlatformData> = this.content.flatMap { it.dci.platformDataList }.distinct() // TODO: Override equals???
fun PageNode.dfs(predicate: (PageNode) -> Boolean): PageNode? = if (predicate(this)) { this } else { this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() }