mirror of
https://github.com/wassname/jupyter_contrib_nbextensions.git
synced 2026-08-09 12:10:23 +08:00
Update readme
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
This extension allows dynamically displaying Python variables in markdown cells.
|
||||
Description
|
||||
===========
|
||||
The **Python Markdown** extension allows displaying Python output in markdown cells.
|
||||
For example:
|
||||
If you set variable `a` in Python
|
||||
|
||||
@@ -30,33 +32,35 @@ Before rendering the markdown cell:
|
||||
After rendering the markdown cell:
|
||||

|
||||
|
||||
Python code is only executed when the notebook is trusted. So if your original Python code is still shown in rendered markdown output, please make sure your notebook is trusted.
|
||||
Python code is only executed when the notebook is trusted. So if your original Python code is still shown in
|
||||
rendered markdown output, please make sure your notebook is trusted.
|
||||
|
||||
**Caution:** There is no restriction in the expression you can embedd in `{{ }}`. Be careful as you might crash your browser if you return too large datasets.
|
||||
|
||||
Also, images in markdown will be removed due to the HTML sanitizer after a reload.
|
||||
**Caution:** There is no restriction in the expression you can embedd in `{{ }}`. Be careful as you might crash your
|
||||
browser if you return too large datasets.
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
Exporting
|
||||
=========
|
||||
|
||||
Install the master version of the IPython-notebook-extensions repository as explained on the main wiki page.
|
||||
In order to have `nbconvert` show the computed Python output when exporting to another format,
|
||||
use the `pymdpreprocessor.py` preprocessor. If you used the `python setup.py install` command to install the
|
||||
IPython-contrib extension package, this will already be installed.
|
||||
|
||||
Then load the extension from within the IPython notebook:
|
||||
|
||||
```javascript
|
||||
%%javascript
|
||||
IPython.load_extensions('usability/python-markdown/main');
|
||||
For manual setup, you need to copy this file to a location within the Python path (or extend `PYTHONPATH`).
|
||||
Additionally, you need to add these two lines to your `jupyter_nbconvert_config.py` configuration file:
|
||||
```Python
|
||||
c = get_config()
|
||||
c.Exporter.preprocessors = [ 'pymdpreprocessor.PyMarkdownPreprocessor' ]
|
||||
```
|
||||
|
||||
In order to have `nbconvert` show the preprocessed output, copy the `pymdpreprocessor.py` file to a location in your `PYTHONPATH`and add or extend the following line to your `ipython_nbconvert_config.py` configuration file:
|
||||
`c.Exporter.preprocessors = [ 'pymdpreprocessor.PyMarkdownPreprocessor' ]`
|
||||
|
||||
|
||||
Internals
|
||||
=========
|
||||
|
||||
The extension overrides the `textcell.MarkdownCell.prototype.render` function and searches for a Python expression enclosed in double curly braced `{{ <expr> }}`. It then executes the expression and replaces it with the result returned from Python, embedded in a `<span>` tag.
|
||||
Additionally, the result is saved in the metadata of the markdown cell, i.e. `cell.metadata.variables[varname]`. This stored value is displayed when reloading the notebook and used for the nbconvert preprocesser.
|
||||
The extension overrides the `textcell.MarkdownCell.prototype.render` function and searches for a Python expression enclosed in
|
||||
double curly braced `{{ <expr> }}`. It then executes the expression and replaces it with the result returned from Python, embedded
|
||||
in a `<span>` tag.
|
||||
Additionally, the result is saved in the metadata of the markdown cell, i.e. `cell.metadata.variables[varname]`.
|
||||
This stored value is displayed when reloading the notebook and used for the nbconvert preprocesser.
|
||||
|
||||
The preprocessor `pymdpreprocessor.PyMarkdownPreprocessor` allows `nbconvert` to display the computed variables when converting the notebook to an output file format.
|
||||
The preprocessor `pymdpreprocessor.PyMarkdownPreprocessor` allows `nbconvert` to display the computed variables
|
||||
when converting the notebook to an output file format.
|
||||
|
||||
Reference in New Issue
Block a user