Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
)
}
}
Expand All @@ -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"))
)
}
},
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -436,12 +446,17 @@ 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 {
val options = Map(
"throwOnError" -> true,
"strict" -> true,
"displayMode" -> displayMode
"displayMode" -> displayMode,
"output" -> output
)
katex.invokeMember("renderToString", latex, options.asJava).asString
}
Expand Down