diff --git a/build.scala b/build.scala index d0be8051..f75bb97b 100644 --- a/build.scala +++ b/build.scala @@ -283,9 +283,9 @@ object LaikaCustomizations { SpanDirectives.create("math") { import SpanDirectives.dsl.* rawBody.map { body => - RawContent( - NonEmptySet.of("html", "rss"), - KaTeX(body, false) + SpanSequence( + RawContent(NonEmptySet.of("html"), KaTeX(body, false)), + RawContent(NonEmptySet.of("rss"), KaTeX(body, false, "mathml")) ) } } @@ -294,10 +294,13 @@ object LaikaCustomizations { BlockDirectives.create("math") { import BlockDirectives.dsl.* rawBody.map { body => - RawContent( - NonEmptySet.of("html", "rss"), - KaTeX(body, true), - Styles("bulma-has-text-centered") + BlockSequence( + RawContent( + NonEmptySet.of("html"), + KaTeX(body, true), + Styles("bulma-has-text-centered") + ), + RawContent(NonEmptySet.of("rss"), KaTeX(body, true, "mathml")) ) } }, @@ -342,6 +345,13 @@ object LaikaCustomizations { val defaultRenderer = { case (fmt, Title(_, _)) => "" // don't render title b/c it is in the RSS metadata + case (fmt, RawContent(formats, content, options)) => + if (formats.contains("rss")) // only render content designated for RSS + HTML.defaultRenderer( + fmt, + RawContent(NonEmptySet.of("html"), content, options) + ) + else "" case (fmt, elem) => HTML.defaultRenderer(fmt, elem) } @@ -436,12 +446,18 @@ object KaTeX { ctx.getBindings("js").getMember("katex") } - def apply(latex: String, displayMode: Boolean = false): String = + def apply( + latex: String, + displayMode: Boolean = false, + output: String = "htmlAndMathml" + ): String = synchronized { + // https://katex.org/docs/options val options = Map( "throwOnError" -> true, "strict" -> true, - "displayMode" -> displayMode + "displayMode" -> displayMode, + "output" -> output ) katex.invokeMember("renderToString", latex, options.asJava).asString }