Code Monkey home page Code Monkey logo

filter_pandoc_run_py's Introduction

filter_pandoc_run_py

Build Status Coverage Status PyPI version PyPI format License Python version Development Status

filter_pandoc_run_py is a pandoc filter for execute python codes written in CodeBlocks or inline Code. It receives the print statement output and place it to the markdown converted file. Also, it save any created pyplot figure to a folder and include it as an image. Code has to be trusted

Usage

To apply the filter, use the following option with pandoc:

pandoc INPUT_FILE -F filter_pandoc_run_py --to OUTPUT_FORMAT -o OUTPUT_FILE

Example:

pandoc ./tests/test.md -F filter_pandoc_run_py -t gfm -o test_converted.md
  • You can convert it to any pandoc supported format;
  • When converted to a markdown format it can change some part of the text to conform with the default style (e.g. changing setext-style headers to ATX headers).

Installation

filter_pandoc_run_py requires [python] (tested in version > 3.0)

Install filter_pandoc_run_py as root using the bash command

git clone URL
cd dir
pip install .

Or get it from PYPI:

pip install filter_pandoc_run_py

How to Use It

Create a regular markdown code but appending a class .run to it.

For CodeBlock

Output print statement as a BlockQuote or paragraph. You can hide the generation code.

Syntax: {.python .run format=[blockquote (default), text] hide_code=[False (default), True] }

The following syntax is also support for enabling standard IDE code highlight:

```python
#filter: {.run format=[blockquote (default), text] hide_code=[False (default), True] }
.... code ....
```

"Pretty print" enable: output of print statement is converted and is rendered

For Code

Output print statement as inline text.

The syntax is:

`print(code)`{.run}

"Pretty print" enable: output of print statement is converted and is rendered

Example

From a markdown file such as:

```{.python .run}
d = 1e3
m = 2 * d
print('The total mass is {:.2f} $m^3$'.format(m))
```

pandoc FILE --to markdown -F filter_pandoc_run_py.py -o OUTFILE.md

> Output:
>
> > The total mass is 2000.00 $m^3$

Generating pyplot images embedded in markdown file:

```{.python .run caption="Figure Number One" label="my_fig"}
import matplotlib
matplotlib.use('PDF')
from matplotlib import pyplot as plt
plt.plot([1, 2], [3, 4], 'dr-')
```

More examples

  • Check files ./tests/test.md and ./tests/test_common_mark.md

Getting Help

If you have any difficulties with filter_pandoc_run_py, please feel welcome to file an issue on github so that we can help.

filter_pandoc_run_py's People

Contributors

caiofcm avatar moshemalawach avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.