In [1]:
%reload_ext yamlmagic
from literacy import Literate
library = Literate()

In [2]:
%%yaml ref
jupyter:
jinja2:



In [3]:
%%literate intro

# `Literacy`

`Literacy` assists in creating static and interactive data-driven documents with Jupyter notebooks. 

```%%bash
pip install git+https://github.com/tonyfast/literacy --upgrade
```

## Initialize ``literate`` magic

Initialize the ``literate`` magic in a code cell in the Jupyter notebook.

```python
library = Literate()
```

The Literate ``library`` contains a [``jinja2``]({{ref['jinja']}}) templating environment
that is used for all of the ``%%literate`` cells.  The templating environment allows ``jinja2``
to access variables in your current notebook.


Out[3]:

Literacy

Literacy assists in creating static and interactive data-driven documents with Jupyter notebooks.


pip install git+https://github.com/tonyfast/literacy --upgrade

Initialize literate magic

Initialize the literate magic in a code cell in the Jupyter notebook.


library = Literate()

The Literate library contains a jinja2 templating environment that is used for all of the %%literate cells. The templating environment allows jinja2 to access variables in your current notebook.


In [4]:
%%literate usage

# Using `literate` magic

Literate magics start with ``%%literate``.  The body of the cell is markdown.  Markdown code fences 
are executed as code if the ``library`` corresponding to the language.  

```python
default_filters = [k.lstrip('execute_') for k in library.env.filters.keys() if k.startswith('execute_')]
num_filters = len(default_filters)
```

### Default filters

The {{num_filters}} default filters are:

<ul>
{% for f in default_filters %}
<li>{{f}}</li>
{% endfor %}
</ul>


Out[4]:

Using literate magic

Literate magics start with %%literate. The body of the cell is markdown. Markdown code fences are executed as code if the library corresponding to the language.


default_filters = [k.lstrip('execute_') for k in library.env.filters.keys() if k.startswith('execute_')]
num_filters = len(default_filters)

Default filters

The 2 default filters are:

  • javascript
  • python

In [5]:
import pyperclip
pyperclip.copy(intro.data + '\n' + usage.data)

In [ ]: