From e77e33cc8c2203df814068e5b3bb680b31b9ef7a Mon Sep 17 00:00:00 2001 From: Chris Holdgraf Date: Wed, 8 Apr 2020 15:27:00 -0700 Subject: [PATCH] tags use hyphens now (#144) --- docs/use/glue.md | 4 ++-- docs/use/hiding.md | 56 ++++++++++++++++++++++---------------------- docs/use/markdown.md | 4 ++-- myst_nb/__init__.py | 3 +++ myst_nb/parser.py | 10 +++++--- 5 files changed, 42 insertions(+), 35 deletions(-) diff --git a/docs/use/glue.md b/docs/use/glue.md index 53605625..fffb9160 100644 --- a/docs/use/glue.md +++ b/docs/use/glue.md @@ -61,7 +61,7 @@ to focus on the glueing part. +++ ```{code-cell} ipython3 -:tags: [hide_cell] +:tags: [hide-cell] # Simulate some data and bootstrap the mean of the data import numpy as np @@ -128,7 +128,7 @@ glue("df_tbl", df) ```{tip} Since we are going to paste this figure into our document at a later point, -you may wish to remove the output here, using the `remove_output` tag +you may wish to remove the output here, using the `remove-output` tag (see {ref}`use/removing`). ``` diff --git a/docs/use/hiding.md b/docs/use/hiding.md index e33d6cfc..a924d36b 100644 --- a/docs/use/hiding.md +++ b/docs/use/hiding.md @@ -29,47 +29,47 @@ You can **cell tags** to control the content hidden with code cells. Add the following tags to a cell's metadata to control what to hide in code cells: -* **`hide_input`** tag to hide the cell inputs -* **`hide_output`** to hide the cell outputs -* **`hide_cell`** to hide the entire cell +* **`hide-input`** tag to hide the cell inputs +* **`hide-output`** to hide the cell outputs +* **`hide-cell`** to hide the entire cell For example, we'll show cells with each below. ```{code-cell} ipython3 -:tags: [remove_cell] +:tags: [remove-cell] import matplotlib.pyplot as plt import numpy as np data = np.random.rand(2, 100) * 100 ``` -Here is a cell with a `hide_input` tag. Click the "toggle" button to the +Here is a cell with a `hide-input` tag. Click the "toggle" button to the right to show it. ```{code-cell} ipython3 -:tags: [hide_input] +:tags: [hide-input] -# This cell has a hide_input tag +# This cell has a hide-input tag fig, ax = plt.subplots() ax.scatter(*data, c=data[0], s=data[0]) ``` -Here's a cell with a `hide_output` tag: +Here's a cell with a `hide-output` tag: ```{code-cell} ipython3 -:tags: [hide_output] +:tags: [hide-output] -# This cell has a hide_output tag +# This cell has a hide-output tag fig, ax = plt.subplots() ax.scatter(*data, c=data[0], s=data[0]) ``` -And the following cell has a `hide_cell` tag: +And the following cell has a `hide-cell` tag: ```{code-cell} ipython3 -:tags: [hide_cell] +:tags: [hide-cell] -# This cell has a hide_cell tag +# This cell has a hide-cell tag fig, ax = plt.subplots() ax.scatter(*data, c=data[0], s=data[0]) ``` @@ -78,14 +78,14 @@ ax.scatter(*data, c=data[0], s=data[0]) # Hiding markdown cells -There are two ways to hide markdown cells. First, **you can add the `hide_input`** +There are two ways to hide markdown cells. First, **you can add the `hide-input`** cell metadata. This triggers the same hiding behavior described above for code cells. -+++ {"tags": ["hide_input"]} ++++ {"tags": ["hide-input"]} ```{note} -This cell was hidden by adding a `hide_input` tag to it! +This cell was hidden by adding a `hide-input` tag to it! ``` +++ @@ -139,40 +139,40 @@ Sometimes, you want to entirely remove parts of a cell so that it doesn't make i into the output at all. To do this, you can use the same tag pattern described above, but with the word `remove_` instead of `hide_`. Use the following tags: -* **`remove_input`** tag to remove the cell inputs -* **`remove_output`** to remove the cell outputs -* **`remove_cell`** to remove the entire cell +* **`remove-input`** tag to remove the cell inputs +* **`remove-output`** to remove the cell outputs +* **`remove-cell`** to remove the entire cell +++ -Here is a cell with a `remove_input` tag. The inputs will not make it into +Here is a cell with a `remove-input` tag. The inputs will not make it into the page at all. ```{code-cell} ipython3 -:tags: [remove_input] +:tags: [remove-input] -# This cell has a remove_input tag +# This cell has a remove-input tag fig, ax = plt.subplots() ax.scatter(*data, c=data[0], s=data[0]) ``` -Here's a cell with a `remove_output` tag: +Here's a cell with a `remove-output` tag: ```{code-cell} ipython3 -:tags: [remove_output] +:tags: [remove-output] -# This cell has a remove_output tag +# This cell has a remove-output tag fig, ax = plt.subplots() points = ax.scatter(*data, c=data[0], s=data[0]) ``` -And the following cell has a `remove_cell` tag (there should be nothing +And the following cell has a `remove-cell` tag (there should be nothing below, since the cell will be gone). ```{code-cell} ipython3 -:tags: [remove_cell] +:tags: [remove-cell] -# This cell has a remove_cell tag +# This cell has a remove-cell tag fig, ax = plt.subplots() points = ax.scatter(*data, c=data[0], s=data[0]) ``` diff --git a/docs/use/markdown.md b/docs/use/markdown.md index 6d35c894..e0ce4060 100644 --- a/docs/use/markdown.md +++ b/docs/use/markdown.md @@ -76,7 +76,7 @@ for example those discussed in {ref}`use/hiding/code`: ````md ```{code-cell} ipython3 -:tags: [hide_output] +:tags: [hide-output] for i in range(20): print("Millhouse did not test cootie positive") @@ -86,7 +86,7 @@ for i in range(20): Yields the following: ```{code-cell} ipython3 -:tags: [hide_output] +:tags: [hide-output] for i in range(20): print("Millhouse did not test cootie positive") diff --git a/myst_nb/__init__.py b/myst_nb/__init__.py index 57dc722c..456c4ea8 100644 --- a/myst_nb/__init__.py +++ b/myst_nb/__init__.py @@ -53,8 +53,11 @@ def set_valid_execution_paths(app): def update_togglebutton_classes(app, config): to_add = [ ".tag_hide_input div.cell_input", + ".tag_hide-input div.cell_input", ".tag_hide_output div.cell_output", + ".tag_hide-output div.cell_output", ".tag_hide_cell.cell", + ".tag_hide-cell.cell", ] for selector in to_add: config.togglebutton_selector += f", {selector}" diff --git a/myst_nb/parser.py b/myst_nb/parser.py index d4b56ea2..403dd0ae 100644 --- a/myst_nb/parser.py +++ b/myst_nb/parser.py @@ -130,7 +130,7 @@ def parse_block(src, start_line): # skip cells tagged for removal # TODO this logic should be deferred to a transform tags = nb_cell.metadata.get("tags", []) - if "remove_cell" in tags: + if ("remove_cell" in tags) or ("remove-cell" in tags): continue if nb_cell["cell_type"] == "markdown": @@ -219,7 +219,7 @@ def render_nb_code_cell(self, token: Token): classes.append(f"tag_{tag}") sphinx_cell = CellNode(classes=classes, cell_type=cell["cell_type"]) self.current_node += sphinx_cell - if "remove_input" not in tags: + if ("remove_input" not in tags) and ("remove-input" not in tags): cell_input = CellInputNode(classes=["cell_input"]) sphinx_cell += cell_input @@ -230,7 +230,11 @@ def render_nb_code_cell(self, token: Token): # ================== # Cell output # ================== - if "remove_output" not in tags and cell["outputs"]: + if ( + ("remove_output" not in tags) + and ("remove-output" not in tags) + and cell["outputs"] + ): cell_output = CellOutputNode(classes=["cell_output"]) sphinx_cell += cell_output