Streamlit-markdown: a streaming markdown component with LaTeX, Mermaid, Table, code support

Hey, everyone :hand_with_index_finger_and_thumb_crossed:

I created a new component as a drop-in replacement for st.markdown. It has the following extra advantages:

  • streaming rendering of markdown text
  • support for latex math, mermaid diagrams, and code highlighting
  • theme color

It is not easy to modify the native st.markdown to meet various demands. Therefore, I use react-markdown library and write a new component for streamlit. However, the hardest is to prevent re-rendering during streaming tokens into a custom component. Finally I did it, by hacking to enable streaming call on a custom component.


:seedling: Installation:

pip install streamlit-markdown

:smiling_face_with_three_hearts: Usage:

static content:

from streamlit_markdown import st_markdown

markdown_text = "$ y = f(x)$"

streaming content:

from streamlit_markdown import st_streaming_markdown

markdown_text = "$ y = f(x)$"
def token_stream():
    for token in markdown_text:
        yeild token
st_streaming_markdown(token_stream, key="token_stream") # key must be set to prevent re-rendering

Check it out and let me know what you build!