From 9137caf56a9f2d1137da5d628634ddef5dacb344 Mon Sep 17 00:00:00 2001 From: Leah Wasser Date: Wed, 12 May 2021 17:28:40 -0600 Subject: [PATCH 1/5] small update to docs hide cell --- docs/source/removing_cells.rst | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/docs/source/removing_cells.rst b/docs/source/removing_cells.rst index 69be245ee..100b53e10 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 out 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. - From dad2bc1683d17639aeff5d3701bc718d2cd52040 Mon Sep 17 00:00:00 2001 From: Leah Wasser Date: Wed, 12 May 2021 18:29:11 -0600 Subject: [PATCH 2/5] fix bad url in docs --- docs/source/nbconvert_library.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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] + ' ...'" ] From bd6529a142b4bdb94961d0733183a85792c5df34 Mon Sep 17 00:00:00 2001 From: Leah Wasser Date: Wed, 12 May 2021 18:54:28 -0600 Subject: [PATCH 3/5] add pip to docs envt --- docs/environment.yml | 1 + 1 file changed, 1 insertion(+) 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 From cc30c289f2a27a9607649a30430b1761089731e7 Mon Sep 17 00:00:00 2001 From: Leah Wasser Date: Thu, 13 May 2021 12:44:40 -0600 Subject: [PATCH 4/5] undo environment update --- docs/environment.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/environment.yml b/docs/environment.yml index da1637783..01ed28f61 100644 --- a/docs/environment.yml +++ b/docs/environment.yml @@ -12,6 +12,5 @@ dependencies: - tornado - entrypoints - ipykernel -- pip - pip: - nbsphinx>=0.7.1 From 9f75d75832fc3fdf32ffed18abf3f4d5d5acd0f9 Mon Sep 17 00:00:00 2001 From: Leah Wasser Date: Thu, 13 May 2021 15:22:11 -0600 Subject: [PATCH 5/5] add pip to build --- docs/environment.yml | 1 + docs/source/removing_cells.rst | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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/removing_cells.rst b/docs/source/removing_cells.rst index 100b53e10..5954f207f 100644 --- a/docs/source/removing_cells.rst +++ b/docs/source/removing_cells.rst @@ -46,7 +46,7 @@ we demonstrate using the nbconvert Python API. exporter = HTMLExporter(config=c) exporter.register_preprocessor(TagRemovePreprocessor(config=c),True) - # Configure and run out exporter - returns a tuple - first element with html, + # 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")