Example #1
0
    def title(self, body, anchor=None):
        """Display text in title formatting.

        Each document should have a single `st.title()`, although this is not
        enforced.

        Parameters
        ----------
        body : str
            The text to display.

        anchor : str
            The anchor name of the header that can be accessed with #anchor
            in the URL. If omitted, it generates an anchor using the body.

        Example
        -------
        >>> st.title('This is a title')

        .. output::
           https://static.streamlit.io/0.25.0-2JkNY/index.html?id=SFcBGANWd8kWXF28XnaEZj
           height: 100px

        """
        title_proto = MarkdownProto()
        if anchor is None:
            title_proto.body = f"# {clean_text(body)}"
        else:
            title_proto.body = f'<h1 data-anchor="{anchor}">{clean_text(body)}</h1>'
            title_proto.allow_html = True
        return self.dg._enqueue("markdown", title_proto)
Example #2
0
    def header(self, body, anchor=None):
        """Display text in header formatting.

        Parameters
        ----------
        body : str
            The text to display.

        anchor : str
            The anchor name of the header that can be accessed with #anchor
            in the URL. If omitted, it generates an anchor using the body.

        Example
        -------
        >>> st.header('This is a header')

        .. output::
           https://static.streamlit.io/0.25.0-2JkNY/index.html?id=AnfQVFgSCQtGv6yMUMUYjj
           height: 100px

        """
        header_proto = MarkdownProto()
        if anchor is None:
            header_proto.body = f"## {clean_text(body)}"
        else:
            header_proto.body = f'<h2 data-anchor="{anchor}">{clean_text(body)}</h2>'
            header_proto.allow_html = True
        return self.dg._enqueue("markdown", header_proto)
Example #3
0
    def caption(self, body):
        """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.

        Example
        -------
        >>> st.caption('This is a string that explains something above.')

        .. output::
           https://static.streamlit.io/0.25.0-2JkNY/index.html?id=SFcBGANWd8kWXF28XnaEZj
           height: 100px

        """
        caption_proto = MarkdownProto()
        caption_proto.body = body
        caption_proto.allow_html = False
        caption_proto.is_caption = True
        return self.dg._enqueue("markdown", caption_proto)
Example #4
0
    def subheader(self, body, anchor=None):
        """Display text in subheader formatting.

        Parameters
        ----------
        body : str
            The text to display.

        anchor : str
            The anchor name of the header that can be accessed with #anchor
            in the URL. If omitted, it generates an anchor using the body.

        Example
        -------
        >>> st.subheader('This is a subheader')

        .. output::
           https://static.streamlit.io/0.25.0-2JkNY/index.html?id=LBKJTfFUwudrbWENSHV6cJ
           height: 100px

        """
        subheader_proto = MarkdownProto()
        if anchor is None:
            subheader_proto.body = f"### {clean_text(body)}"
        else:
            subheader_proto.body = f'<h3 data-anchor="{anchor}">{clean_text(body)}</h3>'
            subheader_proto.allow_html = True

        return self.dg._enqueue("markdown", subheader_proto)
Example #5
0
    def title(self, body, anchor=None):
        """Display text in title formatting.

        Each document should have a single `st.title()`, although this is not
        enforced.

        Parameters
        ----------
        body : str
            The text to display.

        anchor : str
            The anchor name of the header that can be accessed with #anchor
            in the URL. If omitted, it generates an anchor using the body.

        Example
        -------
        >>> st.title('This is a title')

        """
        title_proto = MarkdownProto()
        if anchor is None:
            title_proto.body = f"# {clean_text(body)}"
        else:
            title_proto.body = f'<h1 data-anchor="{anchor}">{clean_text(body)}</h1>'
            title_proto.allow_html = True
        return self.dg._enqueue("markdown", title_proto)
Example #6
0
    def subheader(self, body, anchor=None):
        """Display text in subheader formatting.

        Parameters
        ----------
        body : str
            The text to display.

        anchor : str
            The anchor name of the header that can be accessed with #anchor
            in the URL. If omitted, it generates an anchor using the body.

        Example
        -------
        >>> st.subheader('This is a subheader')

        """
        subheader_proto = MarkdownProto()
        if anchor is None:
            subheader_proto.body = f"### {clean_text(body)}"
        else:
            subheader_proto.body = f'<h3 data-anchor="{anchor}">{clean_text(body)}</h3>'
            subheader_proto.allow_html = True

        return self.dg._enqueue("markdown", subheader_proto)
Example #7
0
    def header(self,
               body: str,
               anchor: Optional[str] = None) -> "DeltaGenerator":
        """Display text in header formatting.

        Parameters
        ----------
        body : str
            The text to display.

        anchor : str
            The anchor name of the header that can be accessed with #anchor
            in the URL. If omitted, it generates an anchor using the body.

        Example
        -------
        >>> st.header('This is a header')

        """
        header_proto = MarkdownProto()
        if anchor is None:
            header_proto.body = f"## {clean_text(body)}"
        else:
            header_proto.body = f'<h2 data-anchor="{anchor}">{clean_text(body)}</h2>'
            header_proto.allow_html = True
        dg = self.dg._enqueue("markdown", header_proto)
        return cast("DeltaGenerator", dg)
Example #8
0
    def markdown(self, body, unsafe_allow_html=False):
        """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://raw.githubusercontent.com/omnidan/node-emoji/master/lib/emoji.json.

            * 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.

        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

            *Also note that `unsafe_allow_html` is a temporary measure and may
            be removed from Streamlit at any time.*

            If you decide to turn on HTML anyway, we ask you to please tell us
            your exact use case here:

            https://discuss.streamlit.io/t/96

            This will help us come up with safe APIs that allow you to do what
            you want.

        Example
        -------
        >>> st.markdown('Streamlit is **_really_ cool**.')

        .. output::
           https://static.streamlit.io/0.25.0-2JkNY/index.html?id=PXz9xgY8aB88eziDVEZLyS
           height: 50px

        """
        markdown_proto = MarkdownProto()

        markdown_proto.body = clean_text(body)
        markdown_proto.allow_html = unsafe_allow_html

        return self.dg._enqueue("markdown", markdown_proto)
Example #9
0
    def caption(self,
                body: str,
                unsafe_allow_html: bool = False) -> "DeltaGenerator":
        """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.

        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

            **Also note that `unsafe_allow_html` is a temporary measure and may be
            removed from Streamlit at any time.**

            If you decide to turn on HTML anyway, we ask you to please tell us your
            exact use case here:
            https://discuss.streamlit.io/t/96 .

            This will help us come up with safe APIs that allow you to do what you
            want.

        Example
        -------
        >>> st.caption('This is a string that explains something above.')

        """
        caption_proto = MarkdownProto()
        caption_proto.body = clean_text(body)
        caption_proto.allow_html = unsafe_allow_html
        caption_proto.is_caption = True
        dg = self.dg._enqueue("markdown", caption_proto)
        return cast("DeltaGenerator", dg)