# pandoc-purl
<figure>
<img src="https://img.shields.io/pypi/v/pandoc-purl" alt="PyPI" />
<figcaption aria-hidden="true">PyPI</figcaption>
</figure>
*pandoc-purl* is [Pandoc](https://pandoc.org) filter for literate
programming and dynamic document generation in Python. It is similar in
spirit to [Knitr](https://yihui.org/knitr/) or
[Pweave](https://mpastell.com/pweave/).
*pandoc-purl* can be installed through *pip*
(e.g. `python3 -m pip install pandoc-purl`), and used like other Pandoc
filters, e.g. `pandoc --filter pandoc-purl document.md -o document.tex`.
## Code chunks
*pandoc-purl* will process code blocks tagged with the `python` class or
inline code tagged with the `p` or `python` classes.
**Note** This *README.md* file has been generated from the
*README.in.md* using *pandoc-purl*.
### Code blocks
Code blocks marked with the `python` class will behave as if executed in
an interactive Python shell: they execute their content, display the
content and, in a following paragraph, display any printed value as well
as the value of the last expression (see below for options controlling
this behavior).
<table style="width:83%;">
<colgroup>
<col style="width: 43%" />
<col style="width: 40%" />
</colgroup>
<thead>
<tr class="header">
<th>Input</th>
<th>Rendered</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><pre><code>```python
print("Hello pandoc-purl")
42
```</code></pre></td>
<td><div class="sourceCode" id="cb2"><pre
class="sourceCode python"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(<span class="st">"Hello pandoc-purl"</span>)</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="dv">42</span></span></code></pre></div>
<pre><code>Hello pandoc-purl
42</code></pre></td>
</tr>
</tbody>
</table>
If the last statement is not an expression, the code is still executed
and displayed, but no result is printed
<table style="width:83%;">
<colgroup>
<col style="width: 43%" />
<col style="width: 40%" />
</colgroup>
<thead>
<tr class="header">
<th>Input</th>
<th>Rendered</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><pre><code>```python
a = 3.14
```</code></pre></td>
<td><div class="sourceCode" id="cb2"><pre
class="sourceCode python"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>a <span class="op">=</span> <span class="fl">3.14</span></span></code></pre></div></td>
</tr>
</tbody>
</table>
### Inline code
Inline code marked with the `p` or `python` classes should contain only
a single expression, and will display the value of that expression in
the text.
<table style="width:83%;">
<colgroup>
<col style="width: 43%" />
<col style="width: 40%" />
</colgroup>
<thead>
<tr class="header">
<th>Input</th>
<th>Rendered</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><pre><code>The answer is `6*7`{.p}</code></pre></td>
<td>The answer is 42</td>
</tr>
</tbody>
</table>
## Chunk options
Options can be passed to code chunks using the `key=value` syntax. The
following options are available:
- `eval`: whether to run the code chunk (`true` or `false`, defaults to
`true`)
<table>
<colgroup>
<col style="width: 50%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr class="header">
<th>Input</th>
<th>Rendered</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><pre><code>The answer is `6*7`{.p}</code></pre></td>
<td>The answer is 42</td>
</tr>
<tr class="even">
<td><pre><code>The answer is `6*7`{.p eval=false}</code></pre></td>
<td>The answer is <code
class="sourceCode pascal"><span class="dv">6</span>*<span class="dv">7</span></code></td>
</tr>
</tbody>
</table>
- `echo`: whether to show the code (code blocks only, `true` or `false`,
defaults to `true`)
<table style="width:83%;">
<colgroup>
<col style="width: 43%" />
<col style="width: 40%" />
</colgroup>
<thead>
<tr class="header">
<th>Input</th>
<th>Rendered</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><pre><code>```python
print("Hello pandoc-purl")
```</code></pre></td>
<td><div class="sourceCode" id="cb2"><pre
class="sourceCode python"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(<span class="st">"Hello pandoc-purl"</span>)</span></code></pre></div>
<pre><code>Hello pandoc-purl
</code></pre></td>
</tr>
<tr class="even">
<td><pre><code>```{.python echo=false}
print("Hello pandoc-purl")
```</code></pre></td>
<td><pre><code>Hello pandoc-purl
</code></pre></td>
</tr>
</tbody>
</table>
- `results`: how to show the result of the last expression
- `asis`: show the result as a pre-formatted code block or inline
(default)
- `markup`: process the result through Pandoc before showing it
- `hide`: hide the result
<table>
<colgroup>
<col style="width: 50%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr class="header">
<th>Input</th>
<th>Rendered</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><pre><code>I'm `"**bold**"`{.p}</code></pre></td>
<td>I’m **bold**</td>
</tr>
<tr class="even">
<td><pre><code>I'm `"**bold**"`{.p results=markup}</code></pre></td>
<td>I’m <strong>bold</strong></td>
</tr>
</tbody>
</table>
## Changing the defaults
The default chunk options can also be changed globally by modifying
`chunk_defaults` in the `pandoc_purl` module:
```{.python echo=false}
import pandoc_purl
pandoc_purl.chunk_defaults["echo"] = False
```
Raw data
{
"_id": null,
"home_page": "https://github.com/lamyj/pandoc-purl",
"name": "pandoc-purl",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "pandoc,markdown,pandoc-filter,literate programming,dynamic document,reproducible research",
"author": "Julien Lamy",
"author_email": "lamy@unistra.fr",
"download_url": "https://files.pythonhosted.org/packages/86/f8/97e219ad417dc6ddd241ffd55e39c47f84e8610a1170818ed2fd5ffa6d42/pandoc-purl-1.0.0.tar.gz",
"platform": null,
"description": "# pandoc-purl\n\n<figure>\n<img src=\"https://img.shields.io/pypi/v/pandoc-purl\" alt=\"PyPI\" />\n<figcaption aria-hidden=\"true\">PyPI</figcaption>\n</figure>\n\n*pandoc-purl* is [Pandoc](https://pandoc.org) filter for literate\nprogramming and dynamic document generation in Python. It is similar in\nspirit to [Knitr](https://yihui.org/knitr/) or\n[Pweave](https://mpastell.com/pweave/).\n\n*pandoc-purl* can be installed through *pip*\n(e.g.\u00a0`python3 -m pip install pandoc-purl`), and used like other Pandoc\nfilters, e.g.\u00a0`pandoc --filter pandoc-purl document.md -o document.tex`.\n\n## Code chunks\n\n*pandoc-purl* will process code blocks tagged with the `python` class or\ninline code tagged with the `p` or `python` classes.\n\n**Note** This *README.md* file has been generated from the\n*README.in.md* using *pandoc-purl*.\n\n### Code blocks\n\nCode blocks marked with the `python` class will behave as if executed in\nan interactive Python shell: they execute their content, display the\ncontent and, in a following paragraph, display any printed value as well\nas the value of the last expression (see below for options controlling\nthis behavior).\n\n<table style=\"width:83%;\">\n<colgroup>\n<col style=\"width: 43%\" />\n<col style=\"width: 40%\" />\n</colgroup>\n<thead>\n<tr class=\"header\">\n<th>Input</th>\n<th>Rendered</th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"odd\">\n<td><pre><code>```python\nprint("Hello pandoc-purl")\n42\n```</code></pre></td>\n<td><div class=\"sourceCode\" id=\"cb2\"><pre\nclass=\"sourceCode python\"><code class=\"sourceCode python\"><span id=\"cb2-1\"><a href=\"#cb2-1\" aria-hidden=\"true\" tabindex=\"-1\"></a><span class=\"bu\">print</span>(<span class=\"st\">"Hello pandoc-purl"</span>)</span>\n<span id=\"cb2-2\"><a href=\"#cb2-2\" aria-hidden=\"true\" tabindex=\"-1\"></a><span class=\"dv\">42</span></span></code></pre></div>\n<pre><code>Hello pandoc-purl\n42</code></pre></td>\n</tr>\n</tbody>\n</table>\n\nIf the last statement is not an expression, the code is still executed\nand displayed, but no result is printed\n\n<table style=\"width:83%;\">\n<colgroup>\n<col style=\"width: 43%\" />\n<col style=\"width: 40%\" />\n</colgroup>\n<thead>\n<tr class=\"header\">\n<th>Input</th>\n<th>Rendered</th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"odd\">\n<td><pre><code>```python\na = 3.14\n```</code></pre></td>\n<td><div class=\"sourceCode\" id=\"cb2\"><pre\nclass=\"sourceCode python\"><code class=\"sourceCode python\"><span id=\"cb2-1\"><a href=\"#cb2-1\" aria-hidden=\"true\" tabindex=\"-1\"></a>a <span class=\"op\">=</span> <span class=\"fl\">3.14</span></span></code></pre></div></td>\n</tr>\n</tbody>\n</table>\n\n### Inline code\n\nInline code marked with the `p` or `python` classes should contain only\na single expression, and will display the value of that expression in\nthe text.\n\n<table style=\"width:83%;\">\n<colgroup>\n<col style=\"width: 43%\" />\n<col style=\"width: 40%\" />\n</colgroup>\n<thead>\n<tr class=\"header\">\n<th>Input</th>\n<th>Rendered</th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"odd\">\n<td><pre><code>The answer is `6*7`{.p}</code></pre></td>\n<td>The answer is 42</td>\n</tr>\n</tbody>\n</table>\n\n## Chunk options\n\nOptions can be passed to code chunks using the `key=value` syntax. The\nfollowing options are available:\n\n- `eval`: whether to run the code chunk (`true` or `false`, defaults to\n `true`)\n\n <table>\n <colgroup>\n <col style=\"width: 50%\" />\n <col style=\"width: 50%\" />\n </colgroup>\n <thead>\n <tr class=\"header\">\n <th>Input</th>\n <th>Rendered</th>\n </tr>\n </thead>\n <tbody>\n <tr class=\"odd\">\n <td><pre><code>The answer is `6*7`{.p}</code></pre></td>\n <td>The answer is 42</td>\n </tr>\n <tr class=\"even\">\n <td><pre><code>The answer is `6*7`{.p eval=false}</code></pre></td>\n <td>The answer is <code\n class=\"sourceCode pascal\"><span class=\"dv\">6</span>*<span class=\"dv\">7</span></code></td>\n </tr>\n </tbody>\n </table>\n\n- `echo`: whether to show the code (code blocks only, `true` or `false`,\n defaults to `true`)\n\n <table style=\"width:83%;\">\n <colgroup>\n <col style=\"width: 43%\" />\n <col style=\"width: 40%\" />\n </colgroup>\n <thead>\n <tr class=\"header\">\n <th>Input</th>\n <th>Rendered</th>\n </tr>\n </thead>\n <tbody>\n <tr class=\"odd\">\n <td><pre><code>```python\n print("Hello pandoc-purl")\n ```</code></pre></td>\n <td><div class=\"sourceCode\" id=\"cb2\"><pre\n class=\"sourceCode python\"><code class=\"sourceCode python\"><span id=\"cb2-1\"><a href=\"#cb2-1\" aria-hidden=\"true\" tabindex=\"-1\"></a><span class=\"bu\">print</span>(<span class=\"st\">"Hello pandoc-purl"</span>)</span></code></pre></div>\n <pre><code>Hello pandoc-purl\n </code></pre></td>\n </tr>\n <tr class=\"even\">\n <td><pre><code>```{.python echo=false}\n print("Hello pandoc-purl")\n ```</code></pre></td>\n <td><pre><code>Hello pandoc-purl\n </code></pre></td>\n </tr>\n </tbody>\n </table>\n\n- `results`: how to show the result of the last expression\n\n - `asis`: show the result as a pre-formatted code block or inline\n (default)\n - `markup`: process the result through Pandoc before showing it\n - `hide`: hide the result\n\n <table>\n <colgroup>\n <col style=\"width: 50%\" />\n <col style=\"width: 50%\" />\n </colgroup>\n <thead>\n <tr class=\"header\">\n <th>Input</th>\n <th>Rendered</th>\n </tr>\n </thead>\n <tbody>\n <tr class=\"odd\">\n <td><pre><code>I'm `"**bold**"`{.p}</code></pre></td>\n <td>I\u2019m **bold**</td>\n </tr>\n <tr class=\"even\">\n <td><pre><code>I'm `"**bold**"`{.p results=markup}</code></pre></td>\n <td>I\u2019m <strong>bold</strong></td>\n </tr>\n </tbody>\n </table>\n\n## Changing the defaults\n\nThe default chunk options can also be changed globally by modifying\n`chunk_defaults` in the `pandoc_purl` module:\n\n ```{.python echo=false}\n import pandoc_purl\n pandoc_purl.chunk_defaults[\"echo\"] = False\n ```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Dynamic document generation for Pandoc in Python",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/lamyj/pandoc-purl"
},
"split_keywords": [
"pandoc",
"markdown",
"pandoc-filter",
"literate programming",
"dynamic document",
"reproducible research"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "305099fec545688eec4cfc23d28e1cd7bb6f8e98923f105b656f7859e0e4e92c",
"md5": "ea9236c56f2b1c4a069a44c1a20be63e",
"sha256": "fd96a68d1070bddef79d75d3c51332baf3bc3e48eb5aa540f53ac358c791fa7b"
},
"downloads": -1,
"filename": "pandoc_purl-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ea9236c56f2b1c4a069a44c1a20be63e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 6061,
"upload_time": "2023-09-25T05:58:14",
"upload_time_iso_8601": "2023-09-25T05:58:14.358083Z",
"url": "https://files.pythonhosted.org/packages/30/50/99fec545688eec4cfc23d28e1cd7bb6f8e98923f105b656f7859e0e4e92c/pandoc_purl-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "86f897e219ad417dc6ddd241ffd55e39c47f84e8610a1170818ed2fd5ffa6d42",
"md5": "a85b0d38b726f5178ea681c3aa9cc378",
"sha256": "01e6cbc59d16710e5460398cb1bf80d3cecbe2ae70f11b821f8b89237f56b895"
},
"downloads": -1,
"filename": "pandoc-purl-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "a85b0d38b726f5178ea681c3aa9cc378",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 6598,
"upload_time": "2023-09-25T05:58:16",
"upload_time_iso_8601": "2023-09-25T05:58:16.102842Z",
"url": "https://files.pythonhosted.org/packages/86/f8/97e219ad417dc6ddd241ffd55e39c47f84e8610a1170818ed2fd5ffa6d42/pandoc-purl-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-25 05:58:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lamyj",
"github_project": "pandoc-purl",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pandoc-purl"
}