feat(den-web): render LaTeX math in user message bubbles#2528
feat(den-web): render LaTeX math in user message bubbles#2528PriyeshPandey2000 wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@PriyeshPandey2000 is attempting to deploy a commit to the Different AI Team on Vercel. A member of the Team first needs to authorize it. |
8e407b8 to
afc0d83
Compare
Pablosinyores
left a comment
There was a problem hiding this comment.
Good to see math rendering in the bubbles. Two things worth weighing before merge, both stemming from user messages moving from inert whitespace-pre-wrap text to full markdown:
-
Single-
$inline math vs currency.markedKatex({ throwOnError: false })uses the default delimiters, so$...$is live inline math. In user-typed chat that false-triggers on ordinary dollar amounts — e.g. "it costs $5 and $10 more" parses$5 and $as a math span, typesetting "5 and " and eating the literal dollar signs. Prices in chat are common enough that this will bite regularly. Options: drop the single-$inline delimiter and keep only$$...$$for display math, or configure the extension so a$immediately followed by a digit is not treated as an opener. Worth trying a couple of price messages. -
Trust boundary on user text. Routing user messages through the markdown renderer means their text is now interpreted as markdown/HTML rather than shown verbatim. Two sub-points: (a) formatting surprises — a user who types
*,_,#, or>now gets it reformatted instead of shown literally, a behavior change from the old bubble; (b) security —[x](...)links become active, so please confirm this path runs the same DOMPurify config as assistant markdown and that it rejectsjavascript:/data:URL schemes, since this is the first place raw user input gets HTML-rendered. Thearia-hiddenADD_ATTR andthrowOnError: falseare both the right calls.
The documented skill-chip fallback tradeoff reads reasonable — agree chips plus math in one message is rare today.
afc0d83 to
d5aebdd
Compare
Replace the markdown-parser approach with a dedicated math-only renderer for user message bubbles. This avoids false-positives on currency ($5), markdown formatting surprises (#headings, *italic*, _underscores_), and the trust-boundary concerns of routing raw user input through a full markdown parser. The renderer handles $$...$$ display math and $...$ inline math. Inline opener requires the character after $ to be non-digit and non-whitespace, and the closer $ must not be followed by a digit — this prevents currency like "$5 and $10" from pairing into a math span. Plain text is HTML-escaped verbatim; output runs through the same DOMPurify config as assistant messages. Falls back to plain-text + skill-chip rendering when skill tokens are present. Closes different-ai#2501
d5aebdd to
2df04d6
Compare
Thanks for the detailed review , reworked the approach to address both points.
Security: renderer never produces links or user-controlled HTML. Plain text goes through |
Summary
Why
KaTeX was already wired for assistant messages but user messages bypassed the markdown renderer entirely, causing LaTeX to appear as raw
$$...$$text in user bubbles.Issue
Closes #2501
Scope
Out of scope
Segment-based rendering to support LaTeX inside skill-chip messages.
Testing
Ran
pnpm typecheck— passManual
What is $E = mc^2$?— inline math renders in user bubble ✓$$\int_0^\infty e^{-x^2}dx = \frac{\sqrt{\pi}}{2}$$— display math renders ✓$$\begin{cases} x+y=1 \\ x-y=0 \end{cases}$$— multi-line environment renders ✓ (this was the known failure case in the DevTools workaround from the issue)Evidence