diff options
author | Jacob Wysko <jacob@wysko.org> | 2022-02-21 10:30:59 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-21 18:30:59 +0300 |
commit | f54597c754c9be6afb4ea374dc959dcc9fd551ce (patch) | |
tree | 8342c5d14a6f7641eabe2361c2fe5fed899053cd /plugins | |
parent | f5b7797255576e5f1c230e2ca3fcb5f4e602387c (diff) | |
download | dokka-f54597c754c9be6afb4ea374dc959dcc9fd551ce.tar.gz dokka-f54597c754c9be6afb4ea374dc959dcc9fd551ce.tar.bz2 dokka-f54597c754c9be6afb4ea374dc959dcc9fd551ce.zip |
Fix MathJax rendering bug (#2342)
* Fix MathJax rendering bug (#2175)
Fix a bug where using the `@usesMathJax` custom tag would cause the
documentation to fail to render.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/mathjax/api/mathjax.api | 8 | ||||
-rw-r--r-- | plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt | 18 | ||||
-rw-r--r-- | plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt | 24 |
3 files changed, 39 insertions, 11 deletions
diff --git a/plugins/mathjax/api/mathjax.api b/plugins/mathjax/api/mathjax.api index 47612ecb..da5caeb2 100644 --- a/plugins/mathjax/api/mathjax.api +++ b/plugins/mathjax/api/mathjax.api @@ -1,8 +1,16 @@ public final class org/jetbrains/dokka/mathjax/MathjaxPlugin : org/jetbrains/dokka/plugability/DokkaPlugin { public fun <init> ()V + public final fun getMathjaxTagContentProvider ()Lorg/jetbrains/dokka/plugability/Extension; public final fun getTransformer ()Lorg/jetbrains/dokka/plugability/Extension; } +public final class org/jetbrains/dokka/mathjax/MathjaxTagContentProvider : org/jetbrains/dokka/base/transformers/pages/tags/CustomTagContentProvider { + public static final field INSTANCE Lorg/jetbrains/dokka/mathjax/MathjaxTagContentProvider; + public fun contentForBrief (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;Lorg/jetbrains/dokka/model/doc/CustomTagWrapper;)V + public fun contentForDescription (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;Lorg/jetbrains/dokka/model/doc/CustomTagWrapper;)V + public fun isApplicable (Lorg/jetbrains/dokka/model/doc/CustomTagWrapper;)Z +} + public final class org/jetbrains/dokka/mathjax/MathjaxTransformer : org/jetbrains/dokka/transformers/pages/PageTransformer { public static final field INSTANCE Lorg/jetbrains/dokka/mathjax/MathjaxTransformer; public fun invoke (Lorg/jetbrains/dokka/pages/RootPageNode;)Lorg/jetbrains/dokka/pages/RootPageNode; diff --git a/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt index 6a00a3da..89c13202 100644 --- a/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt +++ b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt @@ -16,6 +16,12 @@ class MathjaxPlugin : DokkaPlugin() { val transformer by extending { CoreExtensions.pageTransformer with MathjaxTransformer } + + val mathjaxTagContentProvider by extending { + plugin<DokkaBase>().customTagContentProvider with MathjaxTagContentProvider order { + before(plugin<DokkaBase>().sinceKotlinTagContentProvider) + } + } } private const val ANNOTATION = "usesMathJax" @@ -34,3 +40,15 @@ object MathjaxTransformer : PageTransformer { .orEmpty() .any { (it as? CustomTagWrapper)?.name == ANNOTATION } } + +object MathjaxTagContentProvider : CustomTagContentProvider { + + override fun isApplicable(customTag: CustomTagWrapper) = customTag.name == ANNOTATION + + override fun DocumentableContentBuilder.contentForDescription( + sourceSet: DokkaConfiguration.DokkaSourceSet, + customTag: CustomTagWrapper + ) { + comment(customTag.root, sourceSets = setOf(sourceSet)) + } +}
\ No newline at end of file diff --git a/plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt b/plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt index da166083..a354365b 100644 --- a/plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt +++ b/plugins/mathjax/src/test/kotlin/MathjaxPluginTest.kt @@ -53,15 +53,15 @@ class MathjaxPluginTest : BaseAbstractTest() { } } } + val math = "a^2 = b^2 + c^2" val source = """ |/src/main/kotlin/test/Test.kt |package example | /** | * @usesMathJax - | * - | * \(\alpha_{out} = \alpha_{dst}\) - | * \(C_{out} = C_{dst}\) + | * + | * \($math\) | */ | fun test(): String = "" """.trimIndent() @@ -71,14 +71,16 @@ class MathjaxPluginTest : BaseAbstractTest() { configuration, pluginOverrides = listOf(writerPlugin, MathjaxPlugin()) ) { - renderingStage = { - _, _ -> Jsoup - .parse(writerPlugin.writer.contents["root/example/test.html"]) - .head() - .select("link, script") - .let { - assert(it.`is`("[href=$LIB_PATH], [src=$LIB_PATH]")) - } + renderingStage = { _, _ -> + val parsed = Jsoup.parse(writerPlugin.writer.contents["root/example/test.html"]) + + // Ensure the MathJax CDN is loaded + assert(parsed.select("link, script").`is`("[href=$LIB_PATH], [src=$LIB_PATH]")) + + // Ensure the contents are displayed + assert(parsed.select("p").any { + it.text().contains(math) + }) } } } |