Skip to main content

run python code blocks in markdown code

Project description

pandoc-run-python

This is a Pandoc filter! More specifically it is a filter that allows you to run Python code blocks in your markdown. It exists because I enjoy literate coding too much.

How to install

pip install pandoc-run-python

What does it do?

Let's say you have the following markdown file:

## What is fast, loud and crunchy?

```python
print("A rocket chip!")
```

When you use this as en example to explain what the output of this print statement would be, you'd probably don't want to type the expected output of this command manually. Ideally you want it to be actually evaluated and the output inserted into the markdown file. This way you would automatically end up with something like this:

## What is fast, loud and crunchy?

```python
print("A rocket chip!")
```

```
A rocket chip!
```

pandoc-run-python to the rescue!

Coincidentally, the above is exactly what the pandoc-run-python filter provides. How can you achieve this? You need to slightly alter your markdown to specify that a python codeblock needs to be evaluated. More specifically you need to add classes to the codeblock as we did below (I don't like the syntax neither, but this is the pandoc way to do it).

## What is fast, loud and crunchy?

``` {.python .run}
print("A rocket chip!")
```

If the previous example would be in a file call loud.md, using this pandoc filter you could execute the following command to generate the processed markdown.

pandoc loud.md -F pandoc-run-python -t markdown
## What is fast, loud and crunchy?

``` {.python .run}
print("A rocket chip!")
```

``` {.python-output}
A rocket chip!
```

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pandoc-run-python-0.1.7.tar.gz (2.5 kB view hashes)

Uploaded Source

Built Distribution

pandoc_run_python-0.1.7-py3-none-any.whl (2.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page