diff options
Diffstat (limited to 'plugins/mathjax')
3 files changed, 47 insertions, 0 deletions
diff --git a/plugins/mathjax/build.gradle b/plugins/mathjax/build.gradle index a4a59c50..6578ff45 100644 --- a/plugins/mathjax/build.gradle +++ b/plugins/mathjax/build.gradle @@ -1,6 +1,17 @@ import javax.tools.ToolProvider +apply plugin: 'maven-publish' dependencies { compileOnly project(':core') +} + +publishing { + publications { + dokkaCore(MavenPublication) { publication -> + artifactId = 'mathjax-plugin' + + from components.java + } + } }
\ No newline at end of file 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 diff --git a/plugins/mathjax/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin b/plugins/mathjax/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin new file mode 100644 index 00000000..9f9736f3 --- /dev/null +++ b/plugins/mathjax/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin @@ -0,0 +1 @@ +org.jetbrains.dokka.mathjax.MathjaxPlugin |