summaryrefslogtreecommitdiff
path: root/README.md
blob: dcc978b53e92bfba5dc089b285278e20a9283abc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# pymdvar - Python-Markdown Variable extension

Simple extension meant to be used to convert variables to their corresponding values. Works with environment variables too.

It uses the `${variable}` syntax. For example, given `variable=value`, the following text:

```md
Foo ${variable} bar
```

Becomes:

```html
<p>Foo value bar</p>
```

## Install

`pymdvar` can be installed via `pip`:

```sh
python -m pip install pymdvar
```

## Usage

The basic usage requires a dictionary with the variables to be passed to the `VariableExtension`:

```py
>>> import markdown
>>> from pymdvar import VariableExtension
>>> markdown.markdown('foo *${test}* bar', extensions=[VariableExtension(variables={'test': 'value'})])
'<p>foo <em>value</em> bar</p>'
```

if `enable_env=True` is passed, then it will read environment variables, too. Variables in `variables` take preference.

Only `a-z`, `A-Z`, `_` and `0-9` characters are accepted.

Passing the extension as a string is supported:

```py
>>> import markdown
>>> markdown.markdown('foo *${test}* bar', extensions=['pymdvar'], extension_configs={'pymdvar': {'variables': {'test': 'value'}}})
'<p>foo <em>value</em> bar</p>'
```