diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2019-11-20 15:20:04 +0100 |
---|---|---|
committer | Błażej Kardyś <bkardys@virtuslab.com> | 2019-11-25 16:24:16 +0100 |
commit | ca3d34cc9e5be2d9616cfde3d2cac489c07bf102 (patch) | |
tree | 6a9f8eec6c90f474b69909846edfc3015d5aa12f /plugins/xml/src/main | |
parent | a6c81760b5a308fff94743f2dfeaab3488b389e1 (diff) | |
download | dokka-ca3d34cc9e5be2d9616cfde3d2cac489c07bf102.tar.gz dokka-ca3d34cc9e5be2d9616cfde3d2cac489c07bf102.tar.bz2 dokka-ca3d34cc9e5be2d9616cfde3d2cac489c07bf102.zip |
Initial XML plugin 2
Diffstat (limited to 'plugins/xml/src/main')
-rw-r--r-- | plugins/xml/src/main/kotlin/XmlPlugin.kt | 104 | ||||
-rw-r--r-- | plugins/xml/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin | 1 |
2 files changed, 105 insertions, 0 deletions
diff --git a/plugins/xml/src/main/kotlin/XmlPlugin.kt b/plugins/xml/src/main/kotlin/XmlPlugin.kt new file mode 100644 index 00000000..4a932062 --- /dev/null +++ b/plugins/xml/src/main/kotlin/XmlPlugin.kt @@ -0,0 +1,104 @@ +package org.jetbrains.dokka.xml + +import org.jetbrains.dokka.CoreExtensions +import org.jetbrains.dokka.DefaultExtra +import org.jetbrains.dokka.Model.DocumentationNode +import org.jetbrains.dokka.Model.dfs +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.DokkaPlugin +import org.jetbrains.dokka.transformers.PageNodeTransformer + +class XmlPlugin : DokkaPlugin() { + val transformer by extending { + CoreExtensions.pageTransformer with XmlTransformer + } +} + +private const val ANNOTATION = "@usesMathJax" +private const val LIB_PATH = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_SVG&latest" + +object XmlTransformer : PageNodeTransformer { + enum class XMLKind : Kind { + Main, XmlList + } + + override fun invoke(original: ModulePageNode, dokkaContext: DokkaContext): ModulePageNode { + original.findAll { it is ClassPageNode }.forEach { node -> + val refs = node.documentationNode?.extra?.filterIsInstance<DefaultExtra>()?.filter { it.key == "@attr ref"}.orEmpty() + val elementsToAdd = mutableListOf<DocumentationNode<*>>() + + refs.forEach { ref -> + val toFind = DRI.from(ref.value) + original.documentationNode?.dfs { it.dri == toFind }?.let { elementsToAdd.add(it) } + } + + val refTable = ContentGroup( + listOf( + ContentHeader( + listOf( + ContentText( + "XML Attributes", + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + ), + 2, + DCI(node.dri, XMLKind.Main), + node.platforms().toSet(), emptySet(), emptySet() + ), + ContentTable( + emptyList(), + elementsToAdd.map { + ContentGroup( + listOf( + ContentDRILink( + listOf( + ContentText( + it.descriptors.first().name.toString(), + DCI(node.dri, XMLKind.Main), + node.platforms().toSet(), emptySet(), emptySet() + ) + ), + it.dri, + DCI(it.dri, XMLKind.XmlList), + it.platformData.toSet(), emptySet(), emptySet() + ), + ContentText( + it.briefDocstring, + DCI(it.dri, XMLKind.XmlList), + it.platformData.toSet(), emptySet(), emptySet() + ) + ), + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + }, + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + ), + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + + val content = node.content as ContentGroup + val children = (node.content as ContentGroup).children + node.content = content.copy(children = children + refTable) + } + return original + } + + private fun PageNode.findAll(predicate: (PageNode) -> Boolean): Set<PageNode> { + val found = mutableSetOf<PageNode>() + if (predicate(this)) { + found.add(this) + } else { + this.children.asSequence().mapNotNull { it.findAll(predicate) }.forEach { found.addAll(it) } + } + return found + } + + private fun PageNode.platforms() = this.content.platforms.toList() +}
\ No newline at end of file diff --git a/plugins/xml/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin b/plugins/xml/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin new file mode 100644 index 00000000..ebc3e551 --- /dev/null +++ b/plugins/xml/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin @@ -0,0 +1 @@ +org.jetbrains.dokka.xml.XmlPlugin |