-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: add KaTeX support for block and inline math rendering in Markdown #1643
Conversation
With this commit, LaTeX rendering is fully functional. For rendering chemical formulas, the https://github.com/KaTeX/KaTeX/tree/main/contrib/mhchem |
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.
@calycekr My mistake. I added const marked = new Marked({
hooks: {
preprocess: (md) => addInlineCitations(md, sources),
postprocess: (html) => DOMPurify.sanitize(html),
},
extensions: [katexBlockExtension, katexInlineExtension],
renderer: {
html: (html) => escapeHTML(html),
link: (href, title, text) =>
`<a href="${href?.replace(/>$/, "")}" target="_blank" rel="noreferrer">${text}</a>`,
},
gfm: true,
}); |
- Properly escape user-generated HTML to avoid DOM injection vulnerabilities. - Ensures KaTeX rendering remains unaffected while blocking malicious content.
…tions from the mhchem package. - https://github.com/KaTeX/KaTeX/tree/main/contrib/mhchem
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.
Looks great, thanks for the contribution!
Add KaTeX Support for Block and Inline Math Rendering in Markdown
This update introduces KaTeX support for rendering block and inline math expressions within Markdown content. The changes include new tokenizer and renderer extensions for handling KaTeX syntax.
This update will fix #1599 and any other issues related to LaTeX or Markdown parsing.
Changes
katexBlockExtension
andkatexInlineExtension
for KaTeX block and inline math rendering.escapeHTML
andprocessLatex
functions.MarkdownRenderer.svelte
to import and use the new extensions.