Streamlit无法正确渲染Markdown
我尝试使用 .markdown 方法来渲染以下Markdown:
**Stellar Bank** requested a finance vertical campaign focused on **in‑view rate** with a budget of **$80,000**. We evaluated **50** benchmark products, of which **10** matched the finance vertical. One product was excluded for exceeding the budget, leaving **9** eligible products. After vertical and budget filtering, only **Vortex AR** was selected because it optimizes the in‑view rate, fits within the total budget (minimum $75,000) and was the highest‑ranked product. The selected budget is **$75,000**, leaving **$5,000** unspent. The other finance products (Aurora Story, Echo Shoppable, Lumen Expandable, Orbit Carousel, Nebula Banner, Zenith Interstitial, Pulse Playable, Nimbus Native) were not selected because higher‑ranked selections consumed the available budget
它生成了如下输出:
下面是我的代码:
with tab_ai_summary:
if summary_info['error']:
tab_ai_summary.error("Could not generate AI summary")
st.stop()
sanitized_summary = summary_info['data']
tab_ai_summary.markdown(sanitized_summary)
解决方案
问题在于 $,但如果你使用 \$,看起来就正常。
因此你可以尝试添加 .replace('$', r'\$')
问题在于:Markdown中的 $ 可以用于数学公式和LaTeX。
用于测试的最小可工作代码:
因为 \ 会创建特殊代码——例如 \f 表示 formfeed——因此我用 r"" 来表示原始文本。
# streamlit run main.py
import streamlit as st
st.title("Minimal Markdown Example")
st.markdown(r"$a^2 + b^2 = c^2$")
st.markdown(r"$\sum_{x=0}^{\infty} \frac{1}{x^2}$")
st.markdown(
"""
**Stellar Bank** requested a finance vertical campaign focused on **in‑view rate** with a budget of **$80,000**. We evaluated **50** benchmark products, of which **10** matched the finance vertical. One product was excluded for exceeding the budget, leaving **9** eligible products. After vertical and budget filtering, only **Vortex AR** was selected because it optimizes the in‑view rate, fits within the total budget (minimum $75,000) and was the highest‑ranked product. The selected budget is **$75,000**, leaving **$5,000** unspent. The other finance products (Aurora Story, Echo Shoppable, Lumen Expandable, Orbit Carousel, Nebula Banner, Zenith Interstitial, Pulse Playable, Nimbus Native) were not selected because higher‑ranked selections consumed the available budget
""".replace("$", r"\$")
)
结果:
没有 .replace("$", r"\$")
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。



