forked from ipython-contrib/jupyter_contrib_nbextensions
-
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 ipython-contrib#833 from jcb91/readme_and_docs
Readme and docs
- Loading branch information
Showing
8 changed files
with
346 additions
and
106 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
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,95 @@ | ||
Jupyter configuration files | ||
=========================== | ||
|
||
Jupyter configuration is based on the :mod:`traitlets.config` module. | ||
Essentially, each Jupyter application (e.g. :mod:`notebook`, or | ||
:mod:`nbconvert`) has a number of configurable values which: | ||
|
||
1. have default values | ||
2. can be altered form their default by values read from configuration files, | ||
which can be | ||
a) ``.json`` static files | ||
b) ``.py`` config python scripts | ||
3. can be overridden by command-line arguments | ||
|
||
|
||
.. _jupyter-config-path: | ||
|
||
Jupyter config path | ||
------------------- | ||
|
||
Jupyter applications search for configuration files in each directory in the | ||
*jupyter config path*. This path includes different locations in different | ||
operating systems, but you can use the root jupyter command to find a list of | ||
all jupyter paths, and look for the config section:: | ||
|
||
jupyter --paths | ||
|
||
There are at least three configuration directories | ||
|
||
1. a per-user directory | ||
2. a directory in the ``sys.prefix`` directory for the python installation in | ||
use | ||
3. a system-wide directory | ||
|
||
Note that it is likely that to write to the system-wide config directory will | ||
require elevated (admin) privileges. This may also be true for the sys-prefix | ||
directory, depending on the python installation in use. | ||
|
||
Finally, you can also specify a configuration file as a command line argument, | ||
for example:: | ||
|
||
jupyter notebook --config=/home/john/mystuff/jupyter_notebook_config.json | ||
|
||
Note that this can change which filenames are searched for, as noted below. | ||
|
||
|
||
.. _jupyter-config-filenames: | ||
|
||
Jupyter configuration filenames | ||
------------------------------- | ||
|
||
Jupyter applications search the :ref:`jupyter-config-path` for config files | ||
with names derived from the application name, with file extension of either | ||
``.json`` (loaded as json) or ``.py`` (run as a python script). | ||
For example, the ``jupyter notebook`` application searches for config files | ||
called ``jupyter_notebook_config``, while the ``jupyter nbconvert`` application | ||
searches for config files named ``jupyter_nbconvert_config``, with the file | ||
extensions mentioned above. | ||
In addition, all jupyter applications will load config files named | ||
``jupyter_config.json`` or ``jupyter_config.py``. | ||
|
||
Specifying a config file on the command line has the additional slightly subtle | ||
effect that it will also change the filename that the application searches for. | ||
For example, if I call the notebook using :: | ||
|
||
jupyter notebook --config=/home/john/mystuff/special_config_ftw.json | ||
|
||
then instead of searching the :ref:`jupyter-config-path` for files named | ||
``jupyter_notebook_config``, the notebook application will search the config | ||
path for other files also named ``special_config_ftw``, which can mean that the | ||
normal config files get missed. As a result, it may be preferable to name any | ||
custom config files with the standard filename for the jupyter application they | ||
pertain to. | ||
|
||
|
||
.. _jupyter-contrib-nbextensions-config-edits: | ||
|
||
Config files edited by jupyter_contrib_nbextensions | ||
--------------------------------------------------- | ||
|
||
The ``jupyter contrib nbextensions install`` command edits some config files as | ||
part of the install: | ||
|
||
* ``jupyter_notebook_config.json`` is edited in order to: | ||
- enable the | ||
`jupyter_nbextensions_configurator <https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator>`__. | ||
serverextension | ||
- enable the ``contrib_nbextensions_help_item`` nbextension, which adds | ||
a link to readthedocs to the help menu | ||
* ``jupyter_nbconvert_config.json`` is edited in order to: | ||
- edit the nbconvert template path, adding the | ||
``jupyter_contrib_nbextensions.nbconvert_support`` templates directory | ||
- add preprocessors ``CodeFoldingPreprocessor`` and | ||
``PyMarkdownPreprocessor`` from the | ||
``jupyter_contrib_nbextensions.nbconvert_support`` module |
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 |
---|---|---|
|
@@ -27,4 +27,5 @@ Contents: | |
nbextensions | ||
troubleshooting | ||
exporting | ||
config | ||
internals |
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
71 changes: 55 additions & 16 deletions
71
src/jupyter_contrib_nbextensions/nbextensions/hide_input/readme.md
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,31 +1,70 @@ | ||
Hide Input | ||
========== | ||
This extension allows hiding of an individual codecell in a notebook. This can be achieved by clicking on the toolbar | ||
button: | ||
|
||
This extension allows hiding of an individual codecell in a notebook. This can | ||
be achieved by clicking on the toolbar button: | ||
|
||
![](icon.png) | ||
|
||
|
||
Internals | ||
--------- | ||
|
||
The codecell hiding state is stored in the metadata `cell.metadata.hide_input`. | ||
If it is set to `true`, the codecell will be hidden on reload. | ||
|
||
To export a notebook with hidden cells using nbconvert, you need to add a custom template and a custom filter: | ||
``` | ||
|
||
Exporting with nbconvert | ||
------------------------ | ||
|
||
See also the general docs for exporting using nbconvert at | ||
[jupyter-contrib-nbextensions.readthedocs.io](http://jupyter-contrib-nbextensions.readthedocs.io/en/latest). | ||
|
||
To export a notebook with hidden cell inputs using nbconvert, you need to use a | ||
custom template and a custom filter. | ||
The required filter and template are supplied as part of | ||
`jupyter_contrib_nbextensions.nbconvert_support`, or you can roll your own | ||
using the provided ones as examples. Again, see the docs linked above for more | ||
information. | ||
|
||
The `nbextensions.tpl` template is provided in the | ||
`jupyter_contrib_nbextensions.nbconvert_support` templates directory (see the | ||
docs mentioned above for how to find it), while the necessary | ||
`strip_output_prompt` filter, is provided by | ||
`jupyter_contrib_nbextension.nbconvert_support.strip_output_prompt`. | ||
|
||
An example of a python config file which will arrange to use the correct | ||
template and filter: | ||
|
||
```python | ||
import os | ||
import jupyter_contrib_nbextensions.nbconvert_support | ||
|
||
c = get_config() | ||
c.Exporter.template_file = 'nbextensions' | ||
c.Exporter.filters = {'strip_output_prompt': 'strip_output_prompt.strip_output_prompt'} | ||
c.Exporter.template_file = os.path.join( | ||
jupyter_contrib_nbextensions.nbconvert_support.templates_directory(), | ||
'nbextensions') | ||
c.Exporter.setdefault('filters', {})['strip_output_prompt'] = ( | ||
'jupyter_contrib_nbextensions.nbconvert_support.' | ||
'strip_output_prompt.strip_output_prompt') | ||
``` | ||
|
||
The template will respect the `cell.metadata.hide_input` flag, and the filter will remove the cell output prompt | ||
that looks like `Out[27]:`. The filter is not used for PDF or LaTeX output. | ||
To use, put this config into a file named `jupyter_nbconvert_config.py` in the | ||
same directory as the notebook you wish to convert, and call using | ||
|
||
nbconvert --config=jupyter_nbconvert_config.py my_notebook.ipynb | ||
|
||
The nbextensions template will respect the `cell.metadata.hide_input` flag, and | ||
the filter will remove the cell's output prompt (the bit that looks like | ||
`Out[27]:`). | ||
The filter is only used for html output, not for PDF or LaTeX output. | ||
|
||
If you want to _keep_ the cell output prompt, you will have to change the line | ||
|
||
{{ super() | strip_output_prompt }} | ||
|
||
If you want to keep the cell output prompt, you will have to change the line | ||
``` | ||
{{ super() | strip_output_prompt }} | ||
``` | ||
to | ||
``` | ||
{{ super() }} | ||
``` | ||
in the `nbextensions.tpl` file. | ||
|
||
{{ super() }} | ||
|
||
in the `nbextensions.tpl` file. |