Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion content/develop/api-reference/text/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ keywords: markdown, text, formatting, html, display

```python
import streamlit as st
import re
import streamlit as st

md = st.text_area('Type in your markdown string (without outer quotes)',
"Happy Streamlit-ing! :balloon:")
Expand All @@ -22,4 +24,22 @@ st.markdown('''{md}''')
st.markdown(md)
```

<Cloud name="doc-markdown1" height="500px" />
<Cloud name="doc-markdown1" ```python
import re
import streamlit as st

HEX = re.compile(r"^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$")

def chip(h: str, size: int = 16) -> str:
# Return empty string for anything that is not a valid hex code
if not HEX.match(h):
return ""
return (
f'<span style="display:inline-block;width:{size}px;height:{size}px;'
f'background:{h};border:1px solid #ccc;margin-right:8px;'
f'vertical-align:middle;"></span> {h}'
)

hex_values = ["#FF5733", "#1E90FF", "#2ECC71", "#8E44AD"]
html = "".join(chip(h) for h in hex_values)
st.markdown(html, unsafe_allow_html=True)