U
    ARd$                     @   sz   d dl mZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZ dZerhd dlZd dlmZ G d	d
 d
ZdS )    )TYPE_CHECKINGOptionalUnioncast)Markdown)gather_metrics)
clean_text)SupportsStris_sympy_expessionz---N)DeltaGeneratorc                   @   s   e Zd Zeddddeeee ddddZed	deee ddddZ	eddddeeee ddddZ
edddeedf ee ddddZedddddZeddddZdS )MarkdownMixinmarkdownFN)helpr   )bodyunsafe_allow_htmlr   returnc                C   s8   t  }t||_||_t jj|_|r*||_| j	d|S )u5  Display string formatted as Markdown.

        Parameters
        ----------
        body : str
            The string to display as Github-flavored Markdown. Syntax
            information can be found at: https://github.github.com/gfm.

            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.

            * 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, using the syntax ``:color[text to be colored]``,
              where ``color`` needs to be replaced with any of the following
              supported colors: blue, green, orange, red, violet.

        unsafe_allow_html : bool
            By default, any HTML tags found in the body 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:

            https://github.com/streamlit/streamlit/issues/152

        help : str
            An optional tooltip that gets displayed next to the Markdown.

        Examples
        --------
        >>> import streamlit as st
        >>>
        >>> st.markdown('Streamlit is **_really_ cool**.')
        >>> st.markdown(”This text is :red[colored red], and this is **:blue[colored]** and bold.”)
        >>> st.markdown(":green[$\sqrt{x^2+y^2}=1$] is a Pythagorean identity. :pencil:")

        r   )
MarkdownProtor   r   
allow_htmlTypeZNATIVEelement_typer   dg_enqueue)selfr   r   r   Zmarkdown_proto r   ?/tmp/pip-unpacked-wheel-b9et7o5g/streamlit/elements/markdown.pyr      s    5

zMarkdownMixin.markdowncodepython)r   languager   c                 C   s>   t  }d|pd d| d}t||_t jj|_| jd|S )a+  Display a code block with optional syntax highlighting.

        (This is a convenience wrapper around `st.markdown()`)

        Parameters
        ----------
        body : str
            The string to display as code.

        language : str or None
            The language that the code is written in, for syntax highlighting.
            If ``None``, the code will be unstyled. Defaults to ``"python"``.

            For a list of available ``language`` values, see:

            https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_PRISM.MD

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> code = '''def hello():
        ...     print("Hello, Streamlit!")'''
        >>> st.code(code, language='python')

        z``` 
z
```r   )r   r   r   r   ZCODEr   r   r   )r   r   r   Z
code_protor   r   r   r   r   ^   s
     

zMarkdownMixin.codecaptionc                C   s>   t  }t||_||_d|_t jj|_|r0||_| j	
d|S )a:  Display text in small font.

        This should be used for captions, asides, footnotes, sidenotes, and
        other explanatory text.

        Parameters
        ----------
        body : str
            The text to display as Github-flavored Markdown. Syntax
            information can be found at: https://github.github.com/gfm.

            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.

            * 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, using the syntax ``:color[text to be colored]``,
              where ``color`` needs to be replaced with any of the following
              supported colors: blue, green, orange, red, violet.

        unsafe_allow_html : bool
            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:

            https://github.com/streamlit/streamlit/issues/152

        help : str
            An optional tooltip that gets displayed next to the caption.

        Examples
        --------
        >>> import streamlit as st
        >>>
        >>> st.caption('This is a string that explains something above.')
        >>> st.caption('A caption with _italics_ :blue[colors] and emojis :sunglasses:')

        Tr   )r   r   r   r   Z
is_captionr   ZCAPTIONr   r   r   r   )r   r   r   r   Zcaption_protor   r   r   r       s    7

zMarkdownMixin.captionlatexz
sympy.Expr)r   r   r   c                C   sP   t |rddl}||}t }dt| |_tjj|_|rB||_	| j
d|S )a  Display mathematical expressions formatted as LaTeX.

        Supported LaTeX functions are listed at
        https://katex.org/docs/supported.html.

        Parameters
        ----------
        body : str or SymPy expression
            The string or SymPy expression to display as LaTeX. If str, it's
            a good idea to use raw Python strings since LaTeX uses backslashes
            a lot.

        help : str
            An optional tooltip that gets displayed next to the LaTeX expression.


        Example
        -------
        >>> import streamlit as st
        >>>
        >>> st.latex(r'''
        ...     a + ar + a r^2 + a r^3 + \cdots + a r^{n-1} =
        ...     \sum_{k=0}^{n-1} ar^k =
        ...     a \left(\frac{1-r^{n}}{1-r}\right)
        ...     ''')

        r   Nz$$
%s
$$r   )r
   sympyr!   r   r   r   r   ZLATEXr   r   r   r   )r   r   r   r"   Zlatex_protor   r   r   r!      s    $

zMarkdownMixin.latexdivider)r   c                 C   s$   t  }t|_t jj|_| jd|S )a  Display a horizontal rule.

        .. note::
            You can achieve the same effect with st.write("---") or
            even just "---" in your script (via magic).

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> st.divider()

        r   )r   #MARKDOWN_HORIZONTAL_RULE_EXPRESSIONr   r   ZDIVIDERr   r   r   )r   Zdivider_protor   r   r   r#      s    
zMarkdownMixin.dividerc                 C   s
   t d| S )zGet our DeltaGenerator.r   )r   )r   r   r   r   r     s    zMarkdownMixin.dg)F)r   )F)__name__
__module____qualname__r   r	   boolr   strr   r   r    r   r!   r#   propertyr   r   r   r   r   r      sL    > % ?
/r   )typingr   r   r   r   Zstreamlit.proto.Markdown_pb2r   r   Zstreamlit.runtime.metrics_utilr   Zstreamlit.string_utilr   Zstreamlit.type_utilr	   r
   r$   r"   Zstreamlit.delta_generatorr   r   r   r   r   r   <module>   s   