FastUI icon indicating copy to clipboard operation
FastUI copied to clipboard

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

Open zhoubin-me opened this issue 1 year ago • 3 comments

As titled

zhoubin-me avatar Mar 11 '24 06:03 zhoubin-me

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?

samuelcolvin avatar Mar 11 '24 08:03 samuelcolvin

@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>
)

zhoubin-me avatar Mar 11 '24 09:03 zhoubin-me

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.

samuelcolvin avatar Mar 14 '24 10:03 samuelcolvin