diff --git a/docs/environment.yml b/docs/environment.yml index 01ed28f61..da1637783 100644 --- a/docs/environment.yml +++ b/docs/environment.yml @@ -12,5 +12,6 @@ dependencies: - tornado - entrypoints - ipykernel +- pip - pip: - nbsphinx>=0.7.1 diff --git a/docs/source/nbconvert_library.ipynb b/docs/source/nbconvert_library.ipynb index 52dbd6bff..53318dfa6 100644 --- a/docs/source/nbconvert_library.ipynb +++ b/docs/source/nbconvert_library.ipynb @@ -46,7 +46,7 @@ "source": [ "from urllib.request import urlopen\n", "\n", - "url = 'http://jakevdp.github.com/downloads/notebooks/XKCD_plots.ipynb'\n", + "url = 'https://jakevdp.github.io/downloads/notebooks/XKCD_plots.ipynb'\n", "response = urlopen(url).read().decode()\n", "response[0:60] + ' ...'" ] diff --git a/docs/source/removing_cells.rst b/docs/source/removing_cells.rst index 69be245ee..5954f207f 100644 --- a/docs/source/removing_cells.rst +++ b/docs/source/removing_cells.rst @@ -15,7 +15,7 @@ Removing pieces of cells using cell tags The most straightforward way to control which pieces of cells are removed is to use **cell tags**. These are single-string snippets of metadata that are stored in each cells "tag" field. The -`TagRemovePreprocessor` can be used +`TagRemovePreprocessor` can be used to remove inputs, outputs, or entire cells. For example, here is a configuration that uses a different tag for @@ -27,17 +27,33 @@ we demonstrate using the nbconvert Python API. from traitlets.config import Config import nbformat as nbf from nbconvert.exporters import HTMLExporter + from nbconvert.preprocessors import TagRemovePreprocessor + # Setup config c = Config() - # Configure our tag removal + # Configure tag removal - be sure to tag your cells to remove using the + # words remove_cell to remove cells. You can also modify the code to use + # a different tag word c.TagRemovePreprocessor.remove_cell_tags = ("remove_cell",) c.TagRemovePreprocessor.remove_all_outputs_tags = ('remove_output',) c.TagRemovePreprocessor.remove_input_tags = ('remove_input',) + c.TagRemovePreprocessor.enabled = True # Configure and run out exporter - c.HTMLExporter.preprocessors = ["TagRemovePreprocessor"] - HTMLExporter(config=c).from_filename("path/to/mynotebook.ipynb") + c.HTMLExporter.preprocessors = ["nbconvert.preprocessors.TagRemovePreprocessor"] + + exporter = HTMLExporter(config=c) + exporter.register_preprocessor(TagRemovePreprocessor(config=c),True) + + # Configure and run our exporter - returns a tuple - first element with html, + # second with notebook metadata + output = HTMLExporter(config=c).from_filename("your-notebook-file-path.ipynb") + + # Write to output html file + with open("your-output-file-name.html", "w") as f: + f.write(output[0]) + Removing cells using Regular Expressions on cell content -------------------------------------------------------- @@ -63,4 +79,3 @@ an arbitrary number of whitespace characters followed by the end of the string. See https://regex101.com/ for an interactive guide to regular expressions (make sure to select the python flavor). See https://docs.python.org/library/re.html for the official regular expression documentation in python. -