-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix(frontend): silence noisy KaTeX warning on Unicode symbols in math spans #1208
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 |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ import rehypeKatex from 'rehype-katex' | |
| import rehypeSanitize, { defaultSchema } from 'rehype-sanitize' | ||
| import type { PluggableList } from 'unified' | ||
|
|
||
| import { KATEX_OPTIONS } from '@/lib/utils/katex-options' | ||
|
|
||
| const MDEditor = dynamic( | ||
| () => import('@uiw/react-md-editor').then((mod) => mod.default), | ||
| { ssr: false } | ||
|
|
@@ -46,7 +48,7 @@ const SANITIZE_SCHEMA = { | |
|
|
||
| export const PREVIEW_OPTIONS = { | ||
| remarkPlugins: [remarkMath] as PluggableList, | ||
| rehypePlugins: [[rehypeSanitize, SANITIZE_SCHEMA], rehypeKatex] as PluggableList, | ||
| rehypePlugins: [[rehypeSanitize, SANITIZE_SCHEMA], [rehypeKatex, KATEX_OPTIONS]] as PluggableList, | ||
|
Contributor
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. P2: The Unicode-warning fix has no regression test for the behavior it changes, so future edits can reintroduce KaTeX warnings while the current math-rendering test still passes. A preview test for a case such as Prompt for AI agents |
||
| } | ||
|
|
||
| export interface MarkdownEditorProps { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import type { KatexOptions } from 'katex' | ||
|
|
||
| // AI-generated content often contains Unicode punctuation (en/em dashes, | ||
| // smart quotes) inside single-dollar math spans that models emit for | ||
| // legitimate inline math (see prompts/*/system.jinja "MATH FORMATTING" | ||
| // sections). KaTeX's default strict mode logs a console warning for each | ||
| // character outside its symbol table. It still renders - falling back to | ||
| // text-mode handling for that character (see katex's Parser: unknown | ||
| // codepoints get `mode: 'text'` instead of proper math-mode metrics) - so | ||
| // this is not universally cosmetic: an unrecognized symbol can come out | ||
| // with approximated spacing/metrics rather than a "real" glyph. Acceptable | ||
| // for stray punctuation like a dash; don't extend this ignore to justify | ||
| // dumping arbitrary Unicode into math mode. Every other strict check (e.g. | ||
| // deprecated commands) is untouched. | ||
| export const KATEX_OPTIONS: KatexOptions = { | ||
| strict: (errorCode) => (errorCode === 'unknownSymbol' ? 'ignore' : 'warn'), | ||
| } |
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.
P2: The bracket-wrapped error code filter (
[unknownSymbol],[commentAtEnd]) may not match KaTeX's actual console.warn format, which usesKaTeX <code>: <message>without brackets. If so, the first test passes trivially (no filter match even when warnings exist) and the second fails. Suggest checking the actual format by inspecting KaTeX's Settings.reportError or running the tests once. If format lacks brackets, the test would need updated assertion strings.Prompt for AI agents