Skip to content

Commit

Permalink
tags use hyphens now (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
choldgraf authored Apr 8, 2020
1 parent 61c2d71 commit e77e33c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 35 deletions.
4 changes: 2 additions & 2 deletions docs/use/glue.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`).
```

Expand Down
56 changes: 28 additions & 28 deletions docs/use/hiding.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
```
Expand All @@ -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!
```

+++
Expand Down Expand Up @@ -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])
```
4 changes: 2 additions & 2 deletions docs/use/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions myst_nb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
10 changes: 7 additions & 3 deletions myst_nb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit e77e33c

Please sign in to comment.