Hey, everyone
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.
Installation:
pip install streamlit-markdown
Usage:
static content:
from streamlit_markdown import st_markdown
markdown_text = "$ y = f(x)$"
st_markdown(markdown_text)
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!