Skip to content

Commit cfd1b0a

Browse files
committed
Render math in RSS with MathML
1 parent 74d126a commit cfd1b0a

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

build.scala

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ object LaikaCustomizations {
283283
SpanDirectives.create("math") {
284284
import SpanDirectives.dsl.*
285285
rawBody.map { body =>
286-
RawContent(
287-
NonEmptySet.of("html", "rss"),
288-
KaTeX(body, false)
286+
SpanSequence(
287+
RawContent(NonEmptySet.of("html"), KaTeX(body, false)),
288+
RawContent(NonEmptySet.of("rss"), KaTeX(body, false, "mathml"))
289289
)
290290
}
291291
}
@@ -294,10 +294,13 @@ object LaikaCustomizations {
294294
BlockDirectives.create("math") {
295295
import BlockDirectives.dsl.*
296296
rawBody.map { body =>
297-
RawContent(
298-
NonEmptySet.of("html", "rss"),
299-
KaTeX(body, true),
300-
Styles("bulma-has-text-centered")
297+
BlockSequence(
298+
RawContent(
299+
NonEmptySet.of("html"),
300+
KaTeX(body, true),
301+
Styles("bulma-has-text-centered")
302+
),
303+
RawContent(NonEmptySet.of("rss"), KaTeX(body, true, "mathml"))
301304
)
302305
}
303306
},
@@ -342,6 +345,13 @@ object LaikaCustomizations {
342345
val defaultRenderer = {
343346
case (fmt, Title(_, _)) =>
344347
"" // don't render title b/c it is in the RSS metadata
348+
case (fmt, RawContent(formats, content, options)) =>
349+
if (formats.contains("rss")) // only render content designated for RSS
350+
HTML.defaultRenderer(
351+
fmt,
352+
RawContent(NonEmptySet.of("html"), content, options)
353+
)
354+
else ""
345355
case (fmt, elem) => HTML.defaultRenderer(fmt, elem)
346356
}
347357

@@ -436,12 +446,17 @@ object KaTeX {
436446
ctx.getBindings("js").getMember("katex")
437447
}
438448

439-
def apply(latex: String, displayMode: Boolean = false): String =
449+
def apply(
450+
latex: String,
451+
displayMode: Boolean = false,
452+
output: String = "htmlAndMathml"
453+
): String =
440454
synchronized {
441455
val options = Map(
442456
"throwOnError" -> true,
443457
"strict" -> true,
444-
"displayMode" -> displayMode
458+
"displayMode" -> displayMode,
459+
"output" -> output
445460
)
446461
katex.invokeMember("renderToString", latex, options.asJava).asString
447462
}

0 commit comments

Comments
 (0)