aboutsummaryrefslogtreecommitdiff
path: root/plugins/mathjax/src/main/kotlin
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2019-11-20 08:09:59 +0100
committerBłażej Kardyś <bkardys@virtuslab.com>2019-11-25 16:24:16 +0100
commit87c65d1bf22dc0dbc6da8d007fafc73382432812 (patch)
tree6191094093bd0162c7adf3b5ca16474c2448f74d /plugins/mathjax/src/main/kotlin
parent8a057a4611684a6a4616e136d480c005997070cd (diff)
downloaddokka-87c65d1bf22dc0dbc6da8d007fafc73382432812.tar.gz
dokka-87c65d1bf22dc0dbc6da8d007fafc73382432812.tar.bz2
dokka-87c65d1bf22dc0dbc6da8d007fafc73382432812.zip
Mathjax plugin implemented
Diffstat (limited to 'plugins/mathjax/src/main/kotlin')
-rw-r--r--plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt35
1 files changed, 35 insertions, 0 deletions
diff --git a/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt
new file mode 100644
index 00000000..63512966
--- /dev/null
+++ b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt
@@ -0,0 +1,35 @@
+package org.jetbrains.dokka.mathjax
+
+import org.jetbrains.dokka.CoreExtensions
+import org.jetbrains.dokka.pages.ModulePageNode
+import org.jetbrains.dokka.pages.PageNode
+import org.jetbrains.dokka.plugability.DokkaContext
+import org.jetbrains.dokka.plugability.DokkaPlugin
+import org.jetbrains.dokka.transformers.PageNodeTransformer
+
+class MathjaxPlugin : DokkaPlugin() {
+ val transformer by extending {
+ CoreExtensions.pageTransformer with MathjaxTransformer
+ }
+}
+
+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 MathjaxTransformer : PageNodeTransformer {
+ override fun invoke(input: ModulePageNode, dokkaContext: DokkaContext) = input.modified(
+ children = input.children.map { transform(it) }
+ )
+
+ private fun transform(input: PageNode): PageNode = input.modified(
+ embeddedResources = input.embeddedResources + if (input.isNeedingMathjax) listOf(LIB_PATH) else emptyList(),
+ children = input.children.map { transform(it) }
+ )
+
+
+ private val PageNode.isNeedingMathjax
+ get() = documentationNode?.descriptors
+ ?.flatMap { it.docTag?.children?.toList().orEmpty() }
+ .orEmpty()
+ .any { it.text == ANNOTATION }
+} \ No newline at end of file