Skip to main content

Python-Markdown extension for key-value pair conversion

Project description

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:

Foo ${variable} bar

Becomes:

<p>Foo value bar</p>

Install

pymdvar can be installed via pip:

python -m pip install pymdvar

Usage

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

>>> 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:

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

Download files

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

Source Distribution

pymdvar-1.0.2.tar.gz (17.1 kB view hashes)

Uploaded Source

Built Distribution

pymdvar-1.0.2-py3-none-any.whl (16.0 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