Merged
Conversation
Implements server-side LaTeX rendering using katex-rs when processing markdown content. Supports both inline math ($...$) and display math ($$...$$) notation. Features: - Server-side rendering converts LaTeX to HTML at build time - Auto-injects KaTeX CSS from CDN when math is detected - Prints informative message during build - Fails build on invalid LaTeX syntax with clear error messages - Environment variable SIMPLE_DISABLE_KATEX_CSS to disable auto-injection Implementation: - Added katex dependency for LaTeX rendering - Post-processes comrak HTML output to find and render math spans - Injects KaTeX CSS link into page <head> when math is used - Clean separation of concerns with katex_assets module
- Add KaTeX CSS injection to entries.rs for .md file processing - Reset KaTeX flag at start of process_entry - Inject KaTeX CSS when math is detected in entries - Rename binary from "replacer" to "simple" in Cargo.toml This ensures KaTeX works for both: - HTML files with <markdown> blocks (pages.rs) - .md files processed through templates (entries.rs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds automatic KaTeX math rendering and CSS injection for pages that contain math expressions. It introduces a new
katex_assetsmodule to manage KaTeX usage tracking and conditional CSS injection, ensuring the KaTeX stylesheet is only included when needed. The PR also updates the binary name and adds thekatexcrate as a dependency.KaTeX math rendering and CSS injection:
katexcrate as a dependency inCargo.tomland created a newkatex_assetsmodule to track and manage KaTeX usage, CSS injection, and related messaging. [1] [2] [3]src/handlers/markdown.rsto detect and render math expressions using KaTeX, and to mark when KaTeX is used. Errors in math rendering are now handled with clear error messages. [1] [2] [3] [4]src/handlers/pages.rsandsrc/handlers/entries.rsto reset the KaTeX usage flag at the start of each page, and to conditionally inject the KaTeX CSS link into the HTML output only if math has been rendered and injection is not disabled by environment variable. [1] [2] [3] [4] [5] [6]Other changes:
Cargo.tomlfromreplacertosimple.