diff --git a/src/components/ui/markdown/customize.md b/src/components/ui/markdown/customize.md index 9dd30dc846..915a0edfb8 100644 --- a/src/components/ui/markdown/customize.md +++ b/src/components/ui/markdown/customize.md @@ -241,6 +241,12 @@ $c = \pm\sqrt{a^2 + b^2}$ ``` $c = \pm\sqrt{a^2 + b^2}$ +$P(x) = a_nx^n+a_{n-1}x^{n-1} + \dots + a_1x + a_0$ + +``` +$P(x) = a_nx^n+a_{n-1}x^{n-1} + \dots + a_1x + a_0$ +``` + ``` $$ diff --git a/src/components/ui/markdown/parsers/katex.tsx b/src/components/ui/markdown/parsers/katex.tsx index beb912f15d..3347314429 100644 --- a/src/components/ui/markdown/parsers/katex.tsx +++ b/src/components/ui/markdown/parsers/katex.tsx @@ -1,10 +1,5 @@ import React, { useState } from 'react' -import { - blockRegex, - parseCaptureInline, - Priority, - simpleInlineRegex, -} from 'markdown-to-jsx' +import { blockRegex, Priority, simpleInlineRegex } from 'markdown-to-jsx' import type { MarkdownToJSX } from 'markdown-to-jsx' import type { FC } from 'react' @@ -17,17 +12,16 @@ export const KateXRule: MarkdownToJSX.Rule = { match: simpleInlineRegex( /^\$\s{0,}((?:\[.*?\]|<.*?>(?:.*?<.*?>)?|`.*?`|.)*?)\s{0,}\$/, ), - order: Priority.LOW, - parse: parseCaptureInline, - react(node, _, state?) { - try { - const str = node.content.map((item: any) => item.content).join('') - - return {str} - } catch { - return null as any + order: Priority.MED, + parse(capture) { + return { + type: 'kateX', + katex: capture[1], } }, + react(node, output, state) { + return {node.katex} + }, } type LateXProps = { @@ -52,7 +46,10 @@ const LateX: FC = (props) => { 'https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js', ).then(() => { // @ts-ignore - const html = window.katex.renderToString(children, { displayMode, throwOnError }) + const html = window.katex.renderToString(children, { + displayMode, + throwOnError, + }) setHtml(html) }) }, [])