markdownlit
markdownlit is a Python library that enhances Streamlit's native Markdown capabilities by introducing 'lit' features such as magic links, colored text, collapsible content, and improved arrow/dash rendering. Built upon the `Python-Markdown` project, it is currently at version 0.0.7 and is actively maintained, though releases follow an irregular cadence.
Common errors
-
NameError: name 'mdlit' is not defined
cause The `mdlit` function was not imported from the `markdownlit` library.fixAdd `from markdownlit import mdlit` at the top of your Streamlit script. -
AttributeError: module 'streamlit' has no attribute 'cache_data' (or similar caching errors)
cause This error often indicates an incompatibility between your `markdownlit` version and Streamlit's caching API, which underwent changes.fixEnsure both `markdownlit` (v0.0.7+) and Streamlit are updated to their latest versions. Review your code for deprecated caching decorators (`st.cache` should be `st.cache_data` or `st.cache_resource`). -
XMLSyntaxError: Start tag expected, '<' not found (or similar parsing/rendering issues)
cause This might be related to `markdownlit`'s interaction with other components that inject HTML, specifically a known issue with `streamlit-extras`'s `mention` package in older versions.fixUpgrade `markdownlit` to v0.0.4 or newer. If the problem persists, examine other Streamlit components or custom HTML that might conflict with Markdown parsing, especially those that dynamically alter HTML structure.
Warnings
- breaking Versions v0.0.6 and v0.0.7 included significant fixes related to Streamlit's caching primitives (`st.cache_data`, `st.cache_resource`). Applications using `markdownlit` with caching decorators might experience unexpected behavior or errors if not updated to match the latest Streamlit caching API and `markdownlit` versions. [cite: changelog]
- gotcha Prior to v0.0.4, `markdownlit` had a dependency issue with `streamlit-extras`'s `mention` package, leading to potential XML parsing errors due to HTML conflicts. [cite: changelog]
- gotcha While `markdownlit` provides colored text, Streamlit now offers native support for colored text within `st.markdown()` using similar syntax. Users should be aware they might not need `markdownlit` solely for this feature in newer Streamlit versions.
Install
-
pip install markdownlit
Imports
- mdlit
from markdownlit import mdlit
Quickstart
import streamlit as st
from markdownlit import mdlit
st.set_page_config(layout="centered")
st.header("markdownlit Demo")
mdlit("You should definitely check out @(https://streamlit.io/) for building awesome apps!")
mdlit("Here is some [red]colored[/red] text and a [blue]magic link[/blue] to @(twitter.com/arnaudmiribel).")
mdlit("Is this cool -> right? And what about <- this?!")