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

convert to RST - cell magics in code blocks? #47

Closed
balacuit opened this issue Jun 19, 2015 · 5 comments
Closed

convert to RST - cell magics in code blocks? #47

balacuit opened this issue Jun 19, 2015 · 5 comments
Milestone

Comments

@balacuit
Copy link

When converting a notebook to RST, code blocks with magics are still converted into python code blocks. For example, this:

%%bash
git checkout master

... gets translated to this:

.. code:: python
    %%bash
    git checkout master

Shouldn't it be converted to recognize the language specific cell magics, like the following?

.. code:: bash
    git checkout master
@takluyver
Copy link
Member

The template doesn't look at the code of the cell at all, it just puts it all in a .. code:: python block (this is also wrong - it should match the language the notebook is written in).

You could write a custom template which would look at cell magics and produce appropriate rst directives. I think this would probably be useful for us too, now that we're converting notebooks into rst docs.

@Carreau
Copy link
Member

Carreau commented Jun 20, 2015

On Jun 20, 2015, at 01:23, Thomas Kluyver notifications@github.com wrote:

The template https://github.com/jupyter/nbconvert/blob/master/nbconvert/templates/rst.tpl#L10 doesn't look at the code of the cell at all, it just puts it all in a .. code:: python block (this is also wrong - it should match the language the notebook is written in).

You could write a custom template which would look at cell magics and produce appropriate rst directives. I think this would probably be useful for us too, now that we're converting notebooks into rst docs.

And what if you pass relevant option to the first line that are necessary for the comprehension of the program ?
Moreover magic are “just” syntactic sugar for actual function call as hist -t shows.

@mpacer
Copy link
Member

mpacer commented Aug 18, 2016

It seems like there are two pieces to this issue, one part should be fixed (it should put the language the notebook is written in not .. code:: python as @takluyver points out) and the other would seem to require a level of code parsing beyond templating that, based on what @takluyver and @Carreau are saying, is not on the roadmap.

The former should be dealt with for 5.0, the latter maybe no_action (or wishlist if it is something we plan to implement) is that right?

I'm going to open a new issue for dealing with the former, and mark this as no_action.

@takluyver
Copy link
Member

One possibility for the latter part is that we could specify the language as IPython, relying on our own lexers to deal with highlighting magics. I don't know how well they do currently with cell magics using other languages.

@MSeal
Copy link
Contributor

MSeal commented Jun 12, 2019

Closing as there's no action taken and the complexity of the change is questionable.

@MSeal MSeal closed this as completed Jun 12, 2019
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

5 participants