This extension adds codefolding functionality from CodeMirror to a codecell.
In edit mode, clicking on the triangle in the gutter (left margin of codecell) or typing the codefolding hotkey (default is Alt+F
), folds the code. In command mode, the folding hotkey relates to the first line of the codecell.
See the examples below. The folding status is saved in the cell metadata of the notebook, so reloading of a notebook will restore the folding view.
Supported modes¶Three different folding modes are supported:
Indent Folding¶Python-style code folding, detetects indented code.
The unfolded code above can be folded like this:
or this:
Bracket Folding¶Other languages like Javascript use brackets to designate code blocks. Codefolding is supported for Javascript in using the %%javascript
magic in a codecell.
If you specify a magic in the first line of a cell, it can be folded, too.
Folded:
Internals¶When saving a notebook, the folding information is saved in the metadata of each codecell. The number of the folding start line (beginning with 0) is stored in an array:
cell.metadata.code_folding = [ 3, 20, 33 ]
When reloading the notebook, the folding status is restored.
The codefolding hotkey can be customized using the notebook extensions configurator. The settings are stored as "codefolding_hotkey": "alt-f"
in the notebook.json
configuration file.
To export a notebook containing folded cells, you will need to apply a custom preprocessor for nbconvert. The preprocessor is located in jupyter_contrib_nbextensions.nbconvert_support.pre_codefolding
.
The preprocessor is installed when you install the jupyter_contrib_nbextensions
package. To activate the preprocessor manually, add the following lines to jupyter_nbconvert_config.py
:
Exporter.preprocessors += ['jupyter_contrib_nbextensions.nbconvert_support.CodeFoldingPreprocessor']
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4