Skip to content

Render math in RSS with MathML#584

Open
armanbilge wants to merge 2 commits intomainfrom
issue/149
Open

Render math in RSS with MathML#584
armanbilge wants to merge 2 commits intomainfrom
issue/149

Conversation

@armanbilge
Copy link
Member

Closes #149.

My RSS reader appears to support MathML. To make this work, needed a couple tweaks:

  1. When rendering to RSS, disable KaTeX's HTML output in favor of MathML.
  2. Because the RSS renderer secretly delegates to the HTML renderer, we need a bit of trickery to get the correct content to render.

Comment on lines +287 to +288
RawContent(NonEmptySet.of("html"), KaTeX(body, false)),
RawContent(NonEmptySet.of("rss"), KaTeX(body, false, "mathml"))
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.

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)
}
}

@armanbilge armanbilge requested a review from valencik February 19, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Render MathJax in an RSS-reader-friendly way

2 participants

Comments