
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "tutorials/plot_parse.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_tutorials_plot_parse.py>`
        to download the full example code. or to run this example in your browser via Binder

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_tutorials_plot_parse.py:


Alternating text and code
=========================

Sphinx-Gallery is capable of transforming Python files into reST files
with a notebook structure. For this to be used you need to respect some syntax
rules. This example demonstrates how to alternate text and code blocks and some
edge cases. It was designed to be compared with the
:download:`source Python script <plot_parse.py>`.

.. GENERATED FROM PYTHON SOURCE LINES 12-13

This is the first text block and directly follows the header docstring above.

.. GENERATED FROM PYTHON SOURCE LINES 13-16

.. code-block:: Python


    import numpy as np  # noqa: F401








.. GENERATED FROM PYTHON SOURCE LINES 17-25

.. code-block:: Python


    # You can separate code blocks using either a single line of ``#``'s
    # (>=20 columns), ``#%%``, or ``# %%``. For consistency, it is recommend that
    # you use only one of the above three 'block splitter' options in your project.
    A = 1

    import matplotlib.pyplot as plt  # noqa: F401








.. GENERATED FROM PYTHON SOURCE LINES 26-28

Block splitters allow you alternate between code and text blocks **and**
separate sequential blocks of code (above) and text (below).

.. GENERATED FROM PYTHON SOURCE LINES 30-34

A line of ``#``'s also works for separating blocks. The above line of ``#``'s
separates the text block above from this text block. Notice however, that
separated text blocks only shows as a new lines between text, in the rendered
output.

.. GENERATED FROM PYTHON SOURCE LINES 34-46

.. code-block:: Python



    def dummy():
        """This should not be part of a 'text' block'"""  # noqa: D404

        # %%
        # This comment inside a code block will remain in the code block
        pass


    # this line should not be part of a 'text' block








.. GENERATED FROM PYTHON SOURCE LINES 47-51

####################################################################

The above syntax makes a line cut in Sphinx. Note the space between the first
``#`` and the line of ``#``'s.

.. GENERATED FROM PYTHON SOURCE LINES 54-69

.. warning::
    The next kind of comments are not supported (notice the line of ``#``'s
    and the ``# %%`` start at the margin instead of being indented like
    above) and become too hard to escape so just don't use code like this::

        def dummy2():
            """Function docstring"""
        ####################################
        # This comment
        # %%
        # and this comment inside python indentation
        # breaks the block structure and is not
        # supported
            dummy2


.. GENERATED FROM PYTHON SOURCE LINES 69-72

.. code-block:: Python


    """Free strings are not supported. They will be rendered as a code block"""








.. GENERATED FROM PYTHON SOURCE LINES 73-81

New lines can be included in your text block and the parser
is capable of retaining this important whitespace to work with Sphinx.
Everything after a block splitter and starting with ``#`` then one space,
is interpreted by Sphinx-Gallery to be a reST text block. Keep your text
block together using ``#`` and a space at the beginning of each line.

reST header within text block
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. GENERATED FROM PYTHON SOURCE LINES 81-84

.. code-block:: Python


    print("one")





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    one




.. GENERATED FROM PYTHON SOURCE LINES 86-90

.. code-block:: Python


    # another way to separate code blocks shown above
    B = 1








.. GENERATED FROM PYTHON SOURCE LINES 91-97

Code blocks containing Jupyter magic are executable
    .. code-block:: bash

      %%bash
      # This could be run!


.. GENERATED FROM PYTHON SOURCE LINES 99-106

Last text block.

That's all folks !

.. literalinclude:: plot_parse.py




.. _sphx_glr_download_tutorials_plot_parse.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: binder-badge

      .. image:: images/binder_badge_logo.svg
        :target: https://mybinder.org/v2/gh/sphinx-gallery/sphinx-gallery.github.io/master?urlpath=lab/tree/notebooks/tutorials/plot_parse.ipynb
        :alt: Launch binder
        :width: 150 px

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_parse.ipynb <plot_parse.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_parse.py <plot_parse.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_parse.zip <plot_parse.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
