forked from PyWavelets/pywt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from gabalafou/notebook-header-directive
- Loading branch information
Showing
14 changed files
with
367 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* MyST-NB | ||
This stylesheet targets elements output by MyST-NB that represent notebook | ||
cells. | ||
In some cases these rules override MyST-NB. In some cases they override PyData | ||
Sphinx Theme or Sphinx. And in some cases they do not override existing styling | ||
but add new styling. */ | ||
|
||
/* Set up a few variables for this stylesheet */ | ||
.cell, | ||
.pywt-handcoded-cell-output { | ||
--pywt-cell-input-border-left-width: .2rem; | ||
|
||
/* This matches the padding applied to <pre> elements by PyData Sphinx Theme */ | ||
--pywt-code-block-padding: 1rem; | ||
|
||
/* override mystnb */ | ||
--mystnb-source-border-radius: .25rem; /* match PyData Sphinx Theme */ | ||
} | ||
|
||
.cell .cell_input::before { | ||
content: "In"; | ||
border-bottom: var(--mystnb-source-border-width) solid var(--pst-color-border); | ||
font-weight: var(--pst-font-weight-caption); | ||
|
||
/* Left-aligns the text in this box and the one that follows it */ | ||
padding-left: var(--pywt-code-block-padding); | ||
} | ||
|
||
/* Cannot use `.cell .cell_input` selector because the stylesheet from MyST-NB | ||
uses `div.cell div.cell_input` and we want to override those rules */ | ||
div.cell div.cell_input { | ||
background-color: inherit; | ||
border-color: var(--pst-color-border); | ||
border-left-width: var(--pywt-cell-input-border-left-width); | ||
background-clip: padding-box; | ||
overflow: hidden; | ||
} | ||
|
||
.cell .cell_output, | ||
.pywt-handcoded-cell-output { | ||
border: var(--mystnb-source-border-width) solid var(--pst-color-surface); | ||
border-radius: var(--mystnb-source-border-radius); | ||
background-clip: padding-box; | ||
overflow: hidden; | ||
} | ||
|
||
.cell .cell_output::before, | ||
.pywt-handcoded-cell-output::before { | ||
content: "Out"; | ||
display: block; | ||
font-weight: var(--pst-font-weight-caption); | ||
|
||
/* Left-aligns the text in this box and the one that follows it */ | ||
padding-left: var(--pywt-code-block-padding); | ||
} | ||
|
||
.cell .cell_output .output { | ||
background-color: inherit; | ||
border: none; | ||
margin-top: 0; | ||
} | ||
|
||
.cell .cell_output, | ||
/* must prefix the following selector with `div.` to override Sphinx margin rule on div[class*=highlight-] */ | ||
div.pywt-handcoded-cell-output { | ||
/* Left-align the text in the output with the text in the input */ | ||
margin-left: calc(var(--pywt-cell-input-border-left-width) - var(--mystnb-source-border-width)); | ||
} | ||
|
||
.cell .cell_output .output, | ||
.cell .cell_input pre, | ||
.cell .cell_output pre, | ||
.pywt-handcoded-cell-output .highlight, | ||
.pywt-handcoded-cell-output pre { | ||
border-radius: 0; | ||
} | ||
|
||
.pywt-handcoded-cell-output pre { | ||
border: none; /* MyST-NB sets border to none for <pre> tags inside div.cell */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,37 @@ | ||
/* Custom CSS rules for the interactive documentation button */ | ||
|
||
.try_examples_button { | ||
color: white; | ||
background-color: #0054a6; | ||
border: none; | ||
padding: 5px 10px; | ||
border-radius: 10px; | ||
margin-bottom: 5px; | ||
box-shadow: 0 2px 5px rgba(108,108,108,0.2); | ||
font-weight: bold; | ||
font-size: small; | ||
color: white; | ||
background-color: #0054a6; | ||
border: none; | ||
padding: 5px 10px; | ||
border-radius: 10px; | ||
margin-bottom: 5px; | ||
box-shadow: 0 2px 5px rgba(108,108,108,0.2); | ||
font-weight: bold; | ||
font-size: small; | ||
} | ||
|
||
.try_examples_button:hover { | ||
background-color: #0066cc; | ||
transform: scale(1.02); | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); | ||
cursor: pointer; | ||
background-color: #0066cc; | ||
transform: scale(1.02); | ||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); | ||
cursor: pointer; | ||
} | ||
|
||
.try_examples_button_container { | ||
display: flex; | ||
justify-content: flex-start; | ||
gap: 10px; | ||
margin-bottom: 20px; | ||
display: flex; | ||
justify-content: flex-start; | ||
gap: 10px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
/* | ||
Admonitions on this site are styled with some top margin. This makes sense when | ||
the admonition appears within the flow of the article. But when it is the very | ||
first child of an article, its top margin gets added to the article's top | ||
padding, resulting in too much whitespace. | ||
*/ | ||
.admonition.pywt-margin-top-0 { | ||
margin-top: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Regression folder | ||
|
||
This folder contains various useful examples illustrating how to use and how not | ||
to use PyWavelets. | ||
|
||
The examples are written in the [MyST markdown notebook | ||
format](https://myst-nb.readthedocs.io/en/v0.13.2/use/markdown.html). This | ||
allows each .md file to function simultaneously as documentation that can be fed | ||
into Sphinx and as a source file that can be converted to the Jupyter notebook | ||
format (.ipynb), which can then be opened in notebook applications such as | ||
JupyterLab. For this reason, each example page in this folder includes a header template | ||
that adds a blurb to the top of each page about how the page can be | ||
run or downloaded as a Jupyter notebook. | ||
|
||
There a few shortcomings to this approach of generating the code cell outputs in | ||
the documentation pages at build time rather than hand editing them into the | ||
document source file. One is that we can no longer compare the generated outputs | ||
with the expected outputs as we used to do with doctest. Another is that we | ||
lose some control over how we want the outputs to appear, unless we use a workaround. | ||
|
||
Here is the workaround we created. First we tell MyST-NB to remove the generated | ||
cell output from the documentation page by adding the `remove-output` tag to the | ||
`code-cell` directive in the markdown file. Then we hand code the output in a | ||
`code-block` directive, not to be confused with `code-cell`! The `code-cell` | ||
directive says "I am notebook code cell input, run me!" The `code-block` | ||
directive says, "I am just a block of code for documentation purposes, don't run | ||
me!" To the code block, we add the `.pywt-handcoded-cell-output` class so that | ||
we can style it to look the same as other cell outputs on the same HTML page. | ||
Finally, we tag the handcoded output with `jupyterlite_sphinx_strip` so that we | ||
can exclude it when converting from .md to .ipynb. That way only generated | ||
output appears in the .ipynb notebook. | ||
|
||
To recap: | ||
|
||
- We use the `remove-output` tag to remove the **generated** code cell output | ||
during .md to .html conversion (this conversion is done by MyST-NB). | ||
- We use the `jupyterlite_sphinx_strip` tag to remove the **handcoded** output | ||
during .md to .ipynb conversion (this conversion is done by Jupytext). | ||
|
||
Example markdown: | ||
|
||
```{code-cell} | ||
:tags: [raises-exception, remove-output] | ||
1 / 0 | ||
``` | ||
|
||
+++ {"tags" ["jupyterlite_sphinx_strip"]} | ||
|
||
```{code-block} python | ||
:class: pywt-handcoded-cell-output | ||
Traceback (most recent call last): | ||
... | ||
ZeroDivisionError: division by zero | ||
``` |
Oops, something went wrong.