QuantEcon / sphinxcontrib-jupyter

A Sphinx Extension for Generating Jupyter Notebooks
BSD 3-Clause "New" or "Revised" License
76 stars 23 forks source link

DISC: Code Block Parsing behaviour for RST Files #35

Closed mmcky closed 6 years ago

mmcky commented 6 years ago

The current implementation will treat each code-block (or equivalent directive type) as a single input cell in the generated jupyter notebook.

Support for Python doctest code blocks::

    >>> 1+1
    2
    >>> for x in range(3):
    ...      print x
    ...
    0
    1
    2
    >>> x = 1
    >>> x = 2

will get rendered as

image

The rst2ipynb implementation seems to parse internally to the block and split this input out and remove the associated python syntax.

image

The approach taken in this extension so far is to use code-blocks as discrete In cells and then we have planned to implement a :class: output option for adding output to the code-block immediately above it. (not implemented yet). Adding output as an option gives the notebook the look and feel of an executed notebook. In my view I think the discrete block approach aligns nicely with jupyter but thought I would open this discussion.

mmcky commented 6 years ago

I see the method for adding non-autoparsed content in rst2ipynb is to use pycon as the highlighter

.. code:: pycon

   >>> def f(a, b, c):
   ...     """Multiline
   ...     docstring
   ...
   ...     """
   ...     # a comment
   ...
   ...     return a + b + c
   ...
   >>> f(1, 2, 3)
   6

which is parsed as

image

mmcky commented 6 years ago

For the time being we will simple include whatever is found in the code-block without any additional parsing. It should give users the most expected output. If they wish to have code in different In blocks they will need to use different code-block directives sequentially.

mmcky commented 6 years ago

See PR #37