You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HTML comments in Python docstring are not removed when rendering by streamlit #1
HTML comments like <!-- md --> in Python docstring are not removed when rendering by streamlit. This is different than what I was expecting. We need investigate how Python docstring is rendered by streamlit.
This promblem is like below:
Solution
Maybe, we can find the solution to this problem by reading a part of docstring parser in streamlit's implementation:
How it works is simple: any time Streamlit sees either a variable or literal value on its own line, it automatically writes that to your app using st.write (which you’ll learn about later).
unsafe_allow_html (bool) –
This is a keyword-only argument that defaults to False.
By default, any HTML tags found in strings will be escaped and therefore treated as pure text. This behavior may be turned off by setting this argument to True.
That said, we strongly advise against it*. It is hard to write secure HTML, so by using this argument you may be compromising your users’ security. For more information, see:
This will help us come up with safe APIs that allow you to do what you want.
According to the above, HTML tags are escaped by default, so comments like <!-- md -->, <!-- end-md --> in Python docstring are treated as pure text and rendered as pure text.
Is it better to solve this issue in Python side, not an extension side?
Activity
nukopy commentedon Jun 10, 2020
A problem in this issue is by design for security, HTML.
After Python docstring is parsed, it is passed to
streamlit.write(body: str, unsafe_allow_html).Description of
unsafe_allow_htmlis below:According to the above, HTML tags are escaped by default, so comments like
<!-- md -->,<!-- end-md -->in Python docstring are treated as pure text and rendered as pure text.Is it better to solve this issue in Python side, not an extension side?
TezRomacH commentedon Jul 18, 2021
Hi, @nukopy ! How is it going on this fix?
TezRomacH commentedon Jul 18, 2021
for now, I tried using a solution like
but the extension isn't working inside functions

