aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt7
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt2
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt4
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt76
-rw-r--r--plugins/gfm/src/main/kotlin/GfmPlugin.kt148
5 files changed, 139 insertions, 98 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
index f4d547e3..a946aa6f 100644
--- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
@@ -117,11 +117,18 @@ abstract class DefaultRenderer<T>(
is ContentBreakLine -> buildNewLine()
is PlatformHintedContent -> buildPlatformDependent(node, pageContext, sourceSetRestriction)
is ContentDivergentGroup -> buildDivergent(node, pageContext)
+ is ContentDivergentInstance -> buildDivergentInstance(node, pageContext)
else -> buildError(node)
}
}
}
+ open fun T.buildDivergentInstance(node: ContentDivergentInstance, pageContext: ContentPage) {
+ node.before?.build(this, pageContext)
+ node.divergent.build(this, pageContext)
+ node.after?.build(this, pageContext)
+ }
+
open fun buildPageContent(context: T, page: ContentPage) {
context.buildNavigation(page)
page.content.build(context, page)
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index 28c26dea..5a497878 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -289,7 +289,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
is OtherParameter -> link(p.name, p.declarationDRI)
is TypeConstructor -> if (p.function)
- +funType(mainDRI.single(), mainPlatformData, p)
+ +funType(mainDRI.single(), mainSourcesetData, p)
else
group(styles = emptySet()) {
link(p.dri.classNames.orEmpty(), p.dri)
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
index a926857f..fec986a9 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
@@ -145,7 +145,9 @@ open class DefaultPageCreator(
if (map.values.any()) {
header(2, "Inheritors") { }
+ContentTable(
- emptyList(),
+ listOf(contentBuilder.contentFor(mainDRI, mainSourcesetData){
+ text("Name")
+ }),
map.entries.flatMap { entry -> entry.value.map { Pair(entry.key, it) } }
.groupBy({ it.second }, { it.first }).map { (classlike, platforms) ->
buildGroup(setOf(dri), platforms.toSet(), ContentKind.Inheritors) {
diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
index 76e92268..babcc1c7 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
@@ -58,7 +58,7 @@ open class PageContentBuilder(
@ContentBuilderMarker
open inner class DocumentableContentBuilder(
val mainDRI: Set<DRI>,
- val mainPlatformData: Set<DokkaSourceSet>,
+ val mainSourcesetData: Set<DokkaSourceSet>,
val mainStyles: Set<Style>,
val mainExtra: PropertyContainer<ContentNode>
) {
@@ -85,11 +85,21 @@ open class PageContentBuilder(
contents += this
}
+ private val defaultHeaders
+ get() = listOf(
+ contentFor(mainDRI, mainSourcesetData){
+ text("Name")
+ },
+ contentFor(mainDRI, mainSourcesetData){
+ text("Summary")
+ }
+ )
+
fun header(
level: Int,
text: String,
kind: Kind = ContentKind.Main,
- platformData: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
block: DocumentableContentBuilder.() -> Unit = {}
@@ -98,7 +108,7 @@ open class PageContentBuilder(
level,
contentFor(
mainDRI,
- platformData,
+ sourceSets,
kind,
styles,
extra + SimpleAttr("anchor", text.replace("\\s".toRegex(), "").toLowerCase())
@@ -111,18 +121,18 @@ open class PageContentBuilder(
fun cover(
text: String,
- platformData: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles + TextStyle.Cover,
extra: PropertyContainer<ContentNode> = mainExtra,
block: DocumentableContentBuilder.() -> Unit = {}
) {
- header(1, text, platformData = platformData, styles = styles, extra = extra, block = block)
+ header(1, text, sourceSets = sourceSets, styles = styles, extra = extra, block = block)
}
fun text(
text: String,
kind: Kind = ContentKind.Main,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra
) {
@@ -131,34 +141,15 @@ open class PageContentBuilder(
fun buildSignature(d: Documentable) = signatureProvider.signature(d)
- fun linkTable(
- elements: List<DRI>,
- kind: Kind = ContentKind.Main,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
- styles: Set<Style> = mainStyles,
- extra: PropertyContainer<ContentNode> = mainExtra
- ) {
- contents += ContentTable(
- emptyList(),
- elements.map {
- contentFor(it, sourceSets, kind, styles, extra) {
- link(it.classNames ?: "", it)
- }
- },
- DCI(mainDRI, kind),
- sourceSets, styles, extra
- )
- }
-
fun table(
kind: Kind = ContentKind.Main,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
operation: DocumentableContentBuilder.() -> List<ContentGroup>
) {
contents += ContentTable(
- emptyList(),
+ defaultHeaders,
operation(),
DCI(mainDRI, kind),
sourceSets, styles, extra
@@ -170,17 +161,18 @@ open class PageContentBuilder(
level: Int,
kind: Kind = ContentKind.Main,
elements: Iterable<T>,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
renderWhenEmpty: Boolean = false,
needsSorting: Boolean = true,
+ headers: List<ContentGroup>? = null,
operation: DocumentableContentBuilder.(T) -> Unit
) {
if (renderWhenEmpty || elements.any()) {
header(level, name) { }
contents += ContentTable(
- emptyList(),
+ headers ?: defaultHeaders,
elements
.let {
if (needsSorting)
@@ -203,7 +195,7 @@ open class PageContentBuilder(
prefix: String = "",
suffix: String = "",
separator: String = ", ",
- sourceSets: Set<DokkaSourceSet> = mainPlatformData, // TODO: children should be aware of this platform data
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData, // TODO: children should be aware of this platform data
operation: DocumentableContentBuilder.(T) -> Unit
) {
if (elements.isNotEmpty()) {
@@ -221,7 +213,7 @@ open class PageContentBuilder(
text: String,
address: DRI,
kind: Kind = ContentKind.Main,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra
) {
@@ -232,7 +224,7 @@ open class PageContentBuilder(
text: String,
address: DRI,
kind: Kind = ContentKind.Main,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra
) = ContentDRILink(
@@ -246,7 +238,7 @@ open class PageContentBuilder(
text: String,
address: String,
kind: Kind = ContentKind.Main,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra
) =
@@ -262,7 +254,7 @@ open class PageContentBuilder(
fun link(
address: DRI,
kind: Kind = ContentKind.Main,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
block: DocumentableContentBuilder.() -> Unit
@@ -278,7 +270,7 @@ open class PageContentBuilder(
fun comment(
docTag: DocTag,
kind: Kind = ContentKind.Comment,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra
) {
@@ -292,7 +284,7 @@ open class PageContentBuilder(
fun group(
dri: Set<DRI> = mainDRI,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
kind: Kind = ContentKind.Main,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
@@ -318,7 +310,7 @@ open class PageContentBuilder(
fun buildGroup(
dri: Set<DRI> = mainDRI,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
kind: Kind = ContentKind.Main,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
@@ -327,7 +319,7 @@ open class PageContentBuilder(
fun sourceSetDependentHint(
dri: Set<DRI> = mainDRI,
- sourceSets: Set<DokkaSourceSet> = mainPlatformData,
+ sourceSets: Set<DokkaSourceSet> = mainSourcesetData,
kind: Kind = ContentKind.Main,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
@@ -341,15 +333,15 @@ open class PageContentBuilder(
fun sourceSetDependentHint(
dri: DRI,
- platformData: Set<DokkaSourceSet> = mainPlatformData,
+ sourcesetData: Set<DokkaSourceSet> = mainSourcesetData,
kind: Kind = ContentKind.Main,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
block: DocumentableContentBuilder.() -> Unit
) {
contents += PlatformHintedContent(
- buildGroup(setOf(dri), platformData, kind, styles, extra, block),
- platformData
+ buildGroup(setOf(dri), sourcesetData, kind, styles, extra, block),
+ sourcesetData
)
}
@@ -383,7 +375,7 @@ open class PageContentBuilder(
private val instances: MutableList<ContentDivergentInstance> = mutableListOf()
fun instance(
dri: Set<DRI>,
- sourceSets: Set<DokkaSourceSet>, // Having correct PlatformData is crucial here, that's why there's no default
+ sourceSets: Set<DokkaSourceSet>, // Having correct sourcesetData is crucial here, that's why there's no default
kind: Kind = mainKind,
styles: Set<Style> = mainStyles,
extra: PropertyContainer<ContentNode> = mainExtra,
diff --git a/plugins/gfm/src/main/kotlin/GfmPlugin.kt b/plugins/gfm/src/main/kotlin/GfmPlugin.kt
index 53ee2b53..b955d403 100644
--- a/plugins/gfm/src/main/kotlin/GfmPlugin.kt
+++ b/plugins/gfm/src/main/kotlin/GfmPlugin.kt
@@ -15,7 +15,6 @@ import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.query
import org.jetbrains.dokka.transformers.pages.PageTransformer
-
class GfmPlugin : DokkaPlugin() {
val gfmPreprocessors by extensionPoint<PageTransformer>()
@@ -49,6 +48,20 @@ open class CommonmarkRenderer(
override val preprocessors = context.plugin<GfmPlugin>().query { gfmPreprocessors }
+ override fun StringBuilder.wrapGroup(
+ node: ContentGroup,
+ pageContext: ContentPage,
+ childrenCallback: StringBuilder.() -> Unit
+ ) {
+ return when {
+ node.hasStyle(TextStyle.Block) -> {
+ childrenCallback()
+ buildNewLine()
+ }
+ else -> childrenCallback()
+ }
+ }
+
override fun StringBuilder.buildHeader(level: Int, node: ContentHeader, content: StringBuilder.() -> Unit) {
buildParagraph()
append("#".repeat(level) + " ")
@@ -57,48 +70,40 @@ open class CommonmarkRenderer(
}
override fun StringBuilder.buildLink(address: String, content: StringBuilder.() -> Unit) {
- append("[")
+ append("""<a href="$address">""")
content()
- append("]($address)")
+ append("</a>")
}
override fun StringBuilder.buildList(
node: ContentList,
pageContext: ContentPage,
- platformRestriction: Set<DokkaSourceSet>?
+ sourceSetRestriction: Set<DokkaSourceSet>?
) {
- buildParagraph()
buildListLevel(node, pageContext)
- buildParagraph()
}
- private val indent = " ".repeat(4)
-
- private fun StringBuilder.buildListItem(items: List<ContentNode>, pageContext: ContentPage, bullet: String = "*") {
+ private fun StringBuilder.buildListItem(items: List<ContentNode>, pageContext: ContentPage) {
items.forEach {
if (it is ContentList) {
- val builder = StringBuilder()
- builder.append(indent)
- builder.buildListLevel(it, pageContext)
- append(builder.toString().replace(Regex(" \n(?!$)"), " \n$indent"))
+ buildList(it, pageContext)
} else {
- append("$bullet ")
+ append("<li>")
it.build(this, pageContext)
- buildNewLine()
+ append("</li>")
}
}
}
private fun StringBuilder.buildListLevel(node: ContentList, pageContext: ContentPage) {
if (node.ordered) {
- buildListItem(
- node.children,
- pageContext,
- "${node.extra.allOfType<SimpleAttr>().find { it.extraKey == "start" }?.extraValue
- ?: 1.also { context.logger.error("No starting number specified for ordered list in node ${pageContext.dri.first()}!") }}."
- )
+ append("<ol>")
+ buildListItem(node.children, pageContext)
+ append("</ol>")
} else {
- buildListItem(node.children, pageContext, "*")
+ append("<ul>")
+ buildListItem(node.children, pageContext)
+ append("</ul>")
}
}
@@ -115,20 +120,30 @@ open class CommonmarkRenderer(
pageContext: ContentPage,
sourceSetRestriction: Set<DokkaSourceSet>?
) {
- val distinct = content.sourceSets.map {
- it to StringBuilder().apply { buildContentNode(content.inner, pageContext, setOf(it)) }.toString()
- }.groupBy(Pair<DokkaSourceSet, String>::second, Pair<DokkaSourceSet, String>::first)
-
- if (distinct.size == 1)
- append(distinct.keys.single())
- else
- distinct.forEach { text, platforms ->
+ buildPlatformDependentItem(content.inner, content.sourceSets, pageContext)
+ }
+
+ private fun StringBuilder.buildPlatformDependentItem(
+ content: ContentNode,
+ sourceSets: Set<DokkaSourceSet>,
+ pageContext: ContentPage,
+ ) {
+ if(content is ContentGroup && content.children.firstOrNull{ it is ContentTable } != null){
+ buildContentNode(content, pageContext)
+ } else {
+ val distinct = sourceSets.map {
+ it to StringBuilder().apply { buildContentNode(content, pageContext, setOf(it)) }.toString()
+ }.groupBy(Pair<DokkaSourceSet, String>::second, Pair<DokkaSourceSet, String>::first)
+
+ distinct.filter { it.key.isNotBlank() }.forEach { (text, platforms) ->
append(
platforms.joinToString(
prefix = " [",
- postfix = "] $text"
+ postfix = "] $text "
) { "${it.moduleName}/${it.sourceSetID}" })
+ buildNewLine()
}
+ }
}
override fun StringBuilder.buildResource(node: ContentEmbeddedResource, pageContext: ContentPage) {
@@ -138,43 +153,53 @@ open class CommonmarkRenderer(
override fun StringBuilder.buildTable(
node: ContentTable,
pageContext: ContentPage,
- platformRestriction: Set<DokkaSourceSet>?
+ sourceSetRestriction: Set<DokkaSourceSet>?
) {
+ if(node.dci.kind == ContentKind.Sample || node.dci.kind == ContentKind.Parameters){
+ node.sourceSets.forEach {sourcesetData ->
+ append("${sourcesetData.moduleName}/${sourcesetData.sourceSetID}")
+ buildNewLine()
+ buildTable(node.copy(children = node.children.filter { it.sourceSets.contains(sourcesetData) }, dci = node.dci.copy(kind = ContentKind.Main)), pageContext, sourceSetRestriction)
+ buildNewLine()
+ }
+ } else {
+ val size = node.header.size
- buildParagraph()
- val size = node.children.firstOrNull()?.children?.size ?: 0
-
- if (node.header.size > 0) {
- node.header.forEach {
- it.children.forEach {
+ if (node.header.isNotEmpty()) {
+ append("| ")
+ node.header.forEach {
+ it.children.forEach {
+ append(" ")
+ it.build(this, pageContext)
+ }
append("| ")
- it.build(this, pageContext)
}
- append("|\n")
+ append("\n")
+ } else {
+ append("| ".repeat(size))
+ if (size > 0) append("|\n")
}
- } else {
- append("| ".repeat(size))
- if (size > 0) append("|\n")
- }
- append("|---".repeat(size))
- if (size > 0) append("|\n")
+ append("|---".repeat(size))
+ if (size > 0) append("|\n")
- node.children.forEach {
- it.children.forEach {
- append("| ")
- it.build(this, pageContext)
+ node.children.forEach {
+ val builder = StringBuilder()
+ it.children.forEach {
+ builder.append("| ")
+ it.build(builder, pageContext)
+ }
+ append(builder.toString().withEntersAsHtml())
+ append(" | ".repeat(size - it.children.size))
+ append("\n")
}
- append("|\n")
}
-
- buildParagraph()
}
override fun StringBuilder.buildText(textNode: ContentText) {
val decorators = decorators(textNode.style)
append(decorators)
- append(textNode.text.replace(Regex("[<>]"), ""))
+ append(textNode.text)
append(decorators.reversed())
}
@@ -196,6 +221,19 @@ open class CommonmarkRenderer(
context.logger.warn("Markdown renderer has encountered problem. The unmatched node is $node")
}
+ override fun StringBuilder.buildDivergentInstance(node: ContentDivergentInstance, pageContext: ContentPage) {
+ node.before?.let {
+ buildPlatformDependentItem(it, it.sourceSets, pageContext)
+ buildNewLine()
+ }
+ node.divergent.build(this, pageContext)
+ buildNewLine()
+ node.after?.let {
+ buildPlatformDependentItem(it, it.sourceSets, pageContext)
+ buildNewLine()
+ }
+ }
+
private fun decorators(styles: Set<Style>) = StringBuilder().apply {
styles.forEach {
when (it) {
@@ -231,6 +269,8 @@ open class CommonmarkRenderer(
)
}
}
+
+ private fun String.withEntersAsHtml(): String = replace("\n", "<br>")
}
class MarkdownLocationProviderFactory(val context: DokkaContext) : LocationProviderFactory {