pydantic / FastUI

Build better UIs faster.
https://fastui-demo.onrender.com
MIT License
8.13k stars 312 forks source link

Plan for adding remark-math for math formula rendering in markdown? #241

Open zhoubin-me opened 6 months ago

zhoubin-me commented 6 months ago

As titled

samuelcolvin commented 6 months ago

Please can you do a bit more research and tell us how to do this. E.g. goes the library we use now support this?

zhoubin-me commented 6 months ago

@samuelcolvin basially you need to update

https://github.com/pydantic/FastUI/blob/main/src/npm-fastui/src/components/MarkdownLazy.tsx

by using react-markdown's plugins like

import React from 'react'
import {createRoot} from 'react-dom/client'
import Markdown from 'react-markdown'
import rehypeKatex from 'rehype-katex'
import remarkMath from 'remark-math'
import 'katex/dist/katex.min.css' // `rehype-katex` does not import the CSS for you

const markdown = `The lift coefficient ($C_L$) is a dimensionless coefficient.`

createRoot(document.body).render(
  <Markdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]}>
    {markdown}
  </Markdown>
)
samuelcolvin commented 6 months ago

PR welcome to try this. I've no idea how much it increase the bundle size. If it has a big affect, we might need a different lazy module for markdown with math.