-
-
Notifications
You must be signed in to change notification settings - Fork 106
Render math in RSS with MathML #584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 "" | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It doesn't, because perhaps counter-intuitively I implemented the typelevel.github.com/build.scala Lines 330 to 335 in cfd1b0a
|
||||||||||||||
| 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 | ||||||||||||||
armanbilge marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| ) | ||||||||||||||
| katex.invokeMember("renderToString", latex, options.asJava).asString | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
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
@mathdirective, 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
mathmloutput.