Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify that a code cell should be inactive in Jupyter in the Markdown format? #347

Closed
mwouts opened this issue Oct 14, 2019 · 5 comments
Milestone

Comments

@mwouts
Copy link
Owner

mwouts commented Oct 14, 2019

This is a follow-up on an earlier discussion with @choldgraf at #321.

The only way, currently, to have a code cell inactive in Jupyter, is to escape it with Markdown region markers (<!-- #region --> and <!-- #endregion -->).

It would be more user-friendly to offer a active-md tag or metadata to let Jupytext/Jupyter know that a given code chunk should not be executed in Jupyter.

The subject of inactive cells in Jupyter was discussed at ipython/ipython#2125, but inactive cells were finally not coded in base Jupyter (only, in Jupyter notebook, the runtools extension allows to mark some code cells as inactive).

In Jupytext, inactive cells for the other formats are currently mapped to Raw cells, but maybe we should reconsider that (that representation is not compatible with nbconvert and will break #321). Should we map them to a Markdown cell instead? Is this easier to do than to implement an 'inactive' cell functionalilty in the Jupytext extensions for Jupyter Notebook/Jupyter Lab, and also in Jupyter Book?

@mwouts mwouts added this to the 1.3.0 milestone Oct 14, 2019
@choldgraf
Copy link
Contributor

I'd be +1 on assuming that "any code blocks that aren't meant to be run should instead be rendered as markdown blocks". That seems like the most-common pattern to me.

@mwouts
Copy link
Owner Author

mwouts commented Oct 14, 2019

any code blocks that aren't meant to be run should instead be rendered as markdown blocks

Good! Now, say that we are parsing a Markdown file, and we find something like

```python this_cell_is_inactive_in_jupyter

Would it be OK for you if we simply continue parsing the markdown cell (i.e. don't start a new code/markdown cell there)? Which exact pattern would you like Jupytext to look for?

I'm asking as I am having second thought on using specialized markdown cells for inactive code. The initial reason for choosing raw cell is that one can switch easily between them and code cells (one keystroke), while with Markdown cells we would have to change the cell type and then manually remove the ```python and ``` lines.

@choldgraf
Copy link
Contributor

In my mind, it's fine not to create a new cell but to just keep it as a part of a single markdown cell, but it'd also be fine if it were easier to split off any "code-fences-in-markdown" chunks into their own separate cells. Does that clarify?

@mwouts
Copy link
Owner Author

mwouts commented Oct 18, 2019

@choldgraf , soon I will make sure that the active-md tag works for code extracts in Markdown files. But these cells will appear as raw cells in Jupyter (sorry that's not great regarding nbconvert compatibility - that's for consistency with the other formats).

So I think you will prefer another option to leave them as (non-executable) markdown cell. What do you think of something like ```python .noeval? Or any other name at your convenience? The .noeval attribute seems to cause no issue with GitHub:

def f(x)
    return x+1

@mwouts mwouts closed this as completed in 4faaf20 Oct 18, 2019
mwouts added a commit that referenced this issue Oct 18, 2019
mwouts added a commit that referenced this issue Oct 18, 2019
@mwouts
Copy link
Owner Author

mwouts commented Oct 18, 2019

@choldgraf , the .noeval attribute has reached master:

def test_inactive_cell_using_noeval(text='''This is text
```python .noeval
# This is python code.
# It should not become a code cell
```
'''):
expected = new_notebook(cells=[new_markdown_cell(text[:-1])])
nb = jupytext.reads(text, 'md')
compare_notebooks(nb, expected)
text2 = jupytext.writes(nb, 'md')
compare(text2, text)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants