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
34 changes: 25 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"))
Comment on lines +287 to +288
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the idea is roughly:

We register a @math directive, usable as a span or block.
It is formatted as a span with to pieces of content (SpanSequence).
This first RawContent only renders if we are targeting the html format, and in that case we use the default of KaTex output which is htmlAndMathml.
The second RawContent only renders if we are targeting our custom rss format in which case we use the mathml output.

)
}
}
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 ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here, in the custom RSS render format, we are saying we should only render RawContent if it's format specifically has rss in it, otherwise return the empty string (as opposed to using the default html renderer, which is what we had been doing).

So would this mean that raw html content, like the every.org button on https://typelevel.org/foundation/ would not render in RSS at all anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So would this mean that raw html content, like the every.org button on typelevel.org/foundation would not render in RSS at all anymore?

It doesn't, because perhaps counter-intuitively I implemented the @:html directive to output content for both HTML and RSS!

BlockDirectives.create("html") {
import BlockDirectives.dsl.*
rawBody.map { body =>
RawContent(NonEmptySet.of("html", "rss"), body)
}
}

case (fmt, elem) => HTML.defaultRenderer(fmt, elem)
}

Expand Down Expand Up @@ -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
}
Expand Down