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

Markdown active and inactive cells #688

Closed
amin-nejad opened this issue Dec 11, 2020 · 4 comments
Closed

Markdown active and inactive cells #688

amin-nejad opened this issue Dec 11, 2020 · 4 comments

Comments

@amin-nejad
Copy link

In markdown, we can add the active="md" cell metadata to have a code snippet not turn into a cell in the jupyter notebook version.

Similarly, we can add the active-ipynb tag to notebook cells in order to control whether or not they are commented out in the python version.

However it doesn't seem like there are any tags to control whether a notebook cell appears or doesn't appear in markdown. Am I mistaken?

If not, in that same vein, I was wondering if we could either:

  • add an active-md tag where only the cells with that tag are outputted to the markdown version of the notebook
  • make active-ipynb also apply to the markdown format

Or something similar. Thanks!

@mwouts
Copy link
Owner

mwouts commented Jan 3, 2021

Hi @amin-nejad , sorry to answer so late! Yes I agree that I find useful to have control over which code cells are active or not in either the ipynb or the py file. I'd be curious to learn more about why you'd find useful to have some parts of the text included or not in the md or ipynb files... do you have a concrete example in mind?

Also there is a technical detail that we must take into consideration here: currently, the text files (py or md files) always contain all the input cells of the notebook. So, if we ever implement something like this, maybe I'd have a preference to hide some markdown cells inside HTML comments rather than completely removing them. Is that something that would fit your use case? Or not? Thanks

@amin-nejad
Copy link
Author

Hi @mwouts, no worries, thanks for your reply!

My use case is when doing data analysis/modelling/visualisation, etc., a notebook is my preferred method because of its flexibility. But if I then want to present my findings/results to a wider group of people, I don't want to share the whole notebook showing all the iterations of things or things that might be less relevant/important to them (pretty much all the code input cells fall into this category, really just want some of the code outputs and some of the markdown cells). Given that most cells don't make it into the final report, it would be significantly easier to have all cells be not included by default unless they have a tag like active-md.

Having them hidden would still fit my use case as I only care about what the rendered version would look like.

I think including the outputs in markdown cells is still not there yet though if I'm right? It seems #220 concerns this which is still open.

@mwouts
Copy link
Owner

mwouts commented Feb 7, 2021

Hi @amin-nejad, I don't think #220 can be solved in the near future.
Instead I think I'd recommend to give a try to the filtering option in nbconvert.

According to the nbconvert documentation and to jupyter nbconvert --help-all there is now a TagRemovePreprocessor so you might want to try adding tags like remove_in_final_report to some of your (code or Markdown) cells and call

jupyter nbconvert --TagRemovePreprocessor.remove_cell_tags=remove_in_final_report --to html notebook.ipynb

(not tested) to build the final report. If you do so, please let us know how it works! Thanks.

@amin-nejad
Copy link
Author

No worries and thanks for the tip, I have actually been using this in the meantime and it works well! It's not quite what I want as I want the inverse where we you choose what cells to include rather than what cells to exclude but it's close enough!

I actually have an open issue there regarding this: jupyter/nbconvert#1488

I'll close this issue for now then if it's likely to be long term. Thanks again

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