显示格式化为Markdown的字符串。

函数签名[source]

st.markdown(body, unsafe_allow_html=False, *, help=None)

参数

body (any)

The text to display as GitHub-flavored Markdown. Syntax information can be found at: https://github.github.com/gfm. If anything other than a string is passed, it will be converted into a string behind the scenes using str(body).

This also supports:

  • Emoji shortcodes, such as :+1: and :sunglasses:. For a list of all supported codes, see https://share.streamlit.io/streamlit/emoji-shortcodes.
  • Streamlit logo shortcode. Use :streamlit: to add a little Streamlit flair to your text.
  • A limited set of typographical symbols. "<- -> <-> -- >= <= ~=" becomes "← → ↔ — ≥ ≤ ≈" when parsed as Markdown.
  • Google Material Symbols (rounded style), using the syntax :material/icon_name:, where "icon_name" is the name of the icon in snake case. For a complete list of icons, see Google's Material Symbols font library.
  • LaTeX expressions, by wrapping them in "$" or "$$" (the "$$" must be on their own lines). Supported LaTeX functions are listed at https://katex.org/docs/supported.html.
  • Colored text and background colors for text, using the syntax :color[text to be colored] and :color-background[text to be colored], respectively. color must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow, or primary. For example, you can use :orange[your text here] or :blue-background[your text here]. If you use "primary" for color, Streamlit will use the default primary accent color unless you set the theme.primaryColor configuration option.

unsafe_allow_html (bool)

是否在body中渲染HTML。如果为False (默认),在body中找到的任何HTML标签将被转义并 因此被视为原始文本。如果为Truebody中的任何HTML 表达式将被渲染。

向您的应用程序添加自定义HTML会影响安全性、样式和 可维护性。

注意

如果您只想插入HTML或CSS而不使用Markdown文本, 我们建议使用st.html代替。

help (str)

一个可选的工具提示,显示在Markdown旁边。

示例

import streamlit as st

st.markdown("*Streamlit* is **really** ***cool***.")
st.markdown('''
    :red[Streamlit] :orange[can] :green[write] :blue[text] :violet[in]
    :gray[pretty] :rainbow[colors] and :blue-background[highlight] text.''')
st.markdown("Here's a bouquet &mdash;\
            :tulip::cherry_blossom::rose::hibiscus::sunflower::blossom:")

multi = '''If you end a line with two spaces,
a soft return is used for the next line.

Two (or more) newline characters in a row will result in a hard return.
'''
st.markdown(multi)
import streamlit as st md = st.text_area('Type in your markdown string (without outer quotes)', "Happy Streamlit-ing! :balloon:") st.code(f""" import streamlit as st st.markdown('''{md}''') """) st.markdown(md)
forum

还有问题吗?

我们的 论坛 充满了有用的信息和Streamlit专家。