1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
package org.jetbrains.dokka.pages
import org.jetbrains.dokka.links.DRI
data class DCI(val dri: Set<DRI>, val kind: Kind) {
override fun toString() = "$dri[$kind]"
}
interface ContentNode {
val dci: DCI
val platforms: Set<PlatformData>
val style: Set<Style>
val extras: Set<Extra>
}
/** Simple text */
data class ContentText(
val text: String,
override val dci: DCI,
override val platforms: Set<PlatformData>,
override val style: Set<Style> = emptySet(),
override val extras: Set<Extra> = emptySet()
) : ContentNode
/** Headers */
data class ContentHeader(
override val children: List<ContentNode>,
val level: Int,
override val dci: DCI,
override val platforms: Set<PlatformData>,
override val style: Set<Style>,
override val extras: Set<Extra> = emptySet()
) : ContentComposite {
constructor(level: Int, c: ContentComposite) : this(c.children, level, c.dci, c.platforms, c.style, c.extras)
}
/** Code blocks */
data class ContentCode(
override val children: List<ContentNode>,
val language: String,
override val dci: DCI,
override val platforms: Set<PlatformData>,
override val style: Set<Style>,
override val extras: Set<Extra>
) : ContentComposite
/** Union type replacement */
interface ContentLink : ContentComposite
/** All links to classes, packages, etc. that have te be resolved */
data class ContentDRILink(
override val children: List<ContentNode>,
val address: DRI,
override val dci: DCI,
override val platforms: Set<PlatformData>,
override val style: Set<Style> = emptySet(),
override val extras: Set<Extra> = emptySet()
) : ContentLink
/** All links that do not need to be resolved */
data class ContentResolvedLink(
override val children: List<ContentNode>,
val address: String,
override val dci: DCI,
override val platforms: Set<PlatformData>,
override val style: Set<Style> = emptySet(),
override val extras: Set<Extra> = emptySet()
) : ContentLink
/** All links that do not need to be resolved */
data class ContentEmbeddedResource(
val address: String,
val altText: String?,
override val dci: DCI,
override val platforms: Set<PlatformData>,
override val style: Set<Style> = emptySet(),
override val extras: Set<Extra> = emptySet()
) : ContentLink {
override val children = emptyList<ContentNode>()
}
/** Logical grouping of [ContentNode]s */
interface ContentComposite : ContentNode {
val children: List<ContentNode>
}
/** Tables */
data class ContentTable(
val header: List<ContentGroup>,
override val children: List<ContentGroup>,
override val dci: DCI,
override val platforms: Set<PlatformData>,
override val style: Set<Style>,
override val extras: Set<Extra>
) : ContentComposite
/** Lists */
data class ContentList(
override val children: List<ContentNode>,
val ordered: Boolean,
override val dci: DCI,
override val platforms: Set<PlatformData>,
override val style: Set<Style>,
override val extras: Set<Extra>
) : ContentComposite
/** Default group, eg. for blocks of Functions, Properties, etc. **/
data class ContentGroup(
override val children: List<ContentNode>,
override val dci: DCI,
override val platforms: Set<PlatformData>,
override val style: Set<Style>,
override val extras: Set<Extra>
) : ContentComposite
data class PlatformHintedContent(
val inner: ContentNode,
override val platforms: Set<PlatformData>
): ContentComposite {
override val children = listOf(inner)
override val dci: DCI
get() = inner.dci
override val extras: Set<Extra>
get() = inner.extras
override val style: Set<Style>
get() = inner.style
}
/** All extras */
interface Extra
interface Style
interface Kind
enum class ContentKind : Kind {
Comment, Constructors, Functions, Parameters, Properties, Classlikes, Packages, Symbol, Sample, Main
}
enum class TextStyle : Style {
Bold, Italic, Strong, Strikethrough, Paragraph, Block
}
interface HTMLMetadata: Extra {
val key: String
val value: String
}
data class HTMLSimpleAttr(override val key: String, override val value: String): HTMLMetadata
data class HTMLTableMetadata(val item: String, override val key: String, override val value: String): HTMLMetadata
fun ContentNode.dfs(predicate: (ContentNode) -> Boolean): ContentNode? = if (predicate(this)) {
this
} else {
if (this is ContentComposite) {
this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull()
} else {
null
}
}
|