o
    h:                     @  s   U d dl mZ 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mZ d dlmZmZ er;d dlZd dlmZ d	Zd
ed< G dd dZdS )    )annotations)TYPE_CHECKINGFinalLiteralcast)Markdown)gather_metrics)
clean_textvalidate_icon_or_emoji)SupportsStris_sympy_expressionN)DeltaGeneratorz---r   #MARKDOWN_HORIZONTAL_RULE_EXPRESSIONc                   @  s   e Zd Zed	d%ddd&ddZed	d%ddd&ddZedddd'ddZedd(ddZeddddd)d!d"Ze	d(d#d$Z
dS )*MarkdownMixinmarkdownFN)helpbodyr   unsafe_allow_htmlboolr   
str | Nonereturnr   c                C  s8   t  }t||_||_t jj|_|r||_| j	d|S )u  Display string formatted as Markdown.

        Parameters
        ----------
        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 <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Rounded>`_
              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.

            - Colored badges, using the syntax ``:color-badge[text in the badge]``.
              ``color`` must be replaced with any of the following supported
              colors: blue, green, orange, red, violet, gray/grey, or primary.
              For example, you can use ``:orange-badge[your text here]`` or
              ``:blue-badge[your text here]``.

            - Small text, using the syntax ``:small[text to show small]``.


        unsafe_allow_html : bool
            Whether to render HTML within ``body``. If this is ``False``
            (default), any HTML tags found in ``body`` will be escaped and
            therefore treated as raw text. If this is ``True``, any HTML
            expressions within ``body`` will be rendered.

            Adding custom HTML to your app impacts safety, styling, and
            maintainability.

            .. note::
                If you only want to insert HTML or CSS without Markdown text,
                we recommend using ``st.html`` instead.

        help : str or None
            A tooltip that gets displayed next to the Markdown. If this is
            ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        Examples
        --------
        >>> 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)

        .. output::
           https://doc-markdown.streamlit.app/
           height: 350px

        r   )
MarkdownProtor	   r   
allow_htmlTypeNATIVEelement_typer   dg_enqueue)selfr   r   r   markdown_proto r    O/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/elements/markdown.pyr   !   s   g

zMarkdownMixin.markdowncaptionc                C  s>   t  }t||_||_d|_t jj|_|r||_| 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.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        unsafe_allow_html : bool
            Whether to render HTML within ``body``. If this is ``False``
            (default), any HTML tags found in ``body`` will be escaped and
            therefore treated as raw text. If this is ``True``, any HTML
            expressions within ``body`` will be rendered.

            Adding custom HTML to your app impacts safety, styling, and
            maintainability.

            .. note::
                If you only want to insert HTML or CSS without Markdown text,
                we recommend using ``st.html`` instead.

        help : str or None
            A tooltip that gets displayed next to the caption. If this is
            ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        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   
is_captionr   CAPTIONr   r   r   r   )r   r   r   r   caption_protor    r    r!   r"      s   6

zMarkdownMixin.captionlatexSupportsStr | sympy.Exprc                C  sP   t |rddl}||}t }dt| |_tjj|_|r!||_	| 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 or None
            A tooltip that gets displayed next to the LaTeX expression. If
            this is ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        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   LATEXr   r   r   r   )r   r   r   r(   latex_protor    r    r!   r&      s   (

zMarkdownMixin.latexdividerc                 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   r   r   r   DIVIDERr   r   r   )r   divider_protor    r    r!   r+     s   
zMarkdownMixin.dividerbadgeblue)iconcolorlabelstrr0   r1   YLiteral['blue', 'green', 'orange', 'red', 'violet', 'gray', 'grey', 'rainbow', 'primary']c                C  sd   |durt |d }nd}|dddd}t }d| d	| | d|_tjj|_| jd
|S )u  Display a colored badge with an icon and label.

        This is a thin wrapper around the color-badge Markdown directive.
        The following are equivalent:

        - ``st.markdown(":blue-badge[Home]")``
        - ``st.badge("Home", color="blue")``

        .. note::
            You can insert badges everywhere Streamlit supports Markdown by
            using the color-badge Markdown directive. See ``st.markdown`` for
            more information.

        Parameters
        ----------
        label : str
            The label to display in the badge. The label can optionally contain
            GitHub-flavored Markdown of the following types: Bold, Italics,
            Strikethroughs, Inline Code.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives. Because this command escapes square
            brackets (``[ ]``) in this parameter, any directive requiring
            square brackets is not supported.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        icon : str or None
            An optional emoji or icon to display next to the badge label. If
            ``icon`` is ``None`` (default), no icon is displayed. If ``icon``
            is a string, the following options are valid:

            - A single-character emoji. For example, you can set ``icon="🚨"``
              or ``icon="🔥"``. Emoji short codes are not supported.

            - An icon from the Material Symbols library (rounded style) in the
              format ``":material/icon_name:"`` where "icon_name" is the name
              of the icon in snake case.

              For example, ``icon=":material/thumb_up:"`` will display the
              Thumb Up icon. Find additional icons in the `Material Symbols               <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Rounded>`_
              font library.

        color : str
            The color to use for the badge. This defaults to ``"blue"``.

            This can be one of the following supported colors: blue, green,
            orange, red, violet, gray/grey, or primary. If you use
            ``"primary"``, Streamlit will use the default primary accent color
            unless you set the ``theme.primaryColor`` configuration option.

        Examples
        --------
        Create standalone badges with ``st.badge`` (with or without icons). If
        you want to have multiple, side-by-side badges, you can use the
        Markdown directive in ``st.markdown``.

        >>> import streamlit as st
        >>>
        >>> st.badge("New")
        >>> st.badge("Success", icon=":material/check:", color="green")
        >>>
        >>> st.markdown(
        >>>     ":violet-badge[:material/star: Favorite] :orange-badge[⚠️ Needs review] :gray-badge[Deprecated]"
        >>> )

        .. output ::
            https://doc-badge.streamlit.app/
            height: 220px

        N  [z\[]z\]:z-badge[r   )	r
   replacer   r   r   r   r   r   r   )r   r2   r0   r1   icon_strescaped_labelbadge_protor    r    r!   r.     s   [
zMarkdownMixin.badgec                 C  s
   t d| S )zGet our DeltaGenerator.r   )r   )r   r    r    r!   r     s   
zMarkdownMixin.dg)F)r   r   r   r   r   r   r   r   )r   r'   r   r   r   r   )r   r   )r2   r3   r0   r   r1   r4   r   r   )__name__
__module____qualname__r   r   r"   r&   r+   r.   propertyr   r    r    r    r!   r       s,    p>3gr   )
__future__r   typingr   r   r   r   streamlit.proto.Markdown_pb2r   r   streamlit.runtime.metrics_utilr   streamlit.string_utilr	   r
   streamlit.type_utilr   r   r(   streamlit.delta_generatorr   r   __annotations__r   r    r    r    r!   <module>   s   