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. This is really just built to be used with my other project pyssg, as I need it there but I figured it could be released as an extension.

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

>>> 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 option is set, then it will read environment variables, too. Variables in variables take preference.

Syntax for the variables should only include the characters: a-z, A-Z, _ and 0-9; this limitation is set like this by personal preference, as the "variable" could be any string, could even include spaces and special chars. Variables not found are just replaced by an empty string.

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

Options

Only supported options:

  • variables (default dict()):

    Dictionary containing key-value pairs for variable-values. Example

    variables={'test': 'value', 'key': 'value'}
    
  • enable_env (default False):

    Enables environment variable reading.

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.3.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymdvar-1.0.3-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file pymdvar-1.0.3.tar.gz.

File metadata

  • Download URL: pymdvar-1.0.3.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for pymdvar-1.0.3.tar.gz
Algorithm Hash digest
SHA256 1b0b0281a0e845a61d3bc4e47f0580f4813d47dcb5882c6d9e92be0d40067001
MD5 78c509805e038ba97feebea971d92719
BLAKE2b-256 e9ec34514841efffba81c043d7119d86e5301456558d2407a0622771401bea12

See more details on using hashes here.

File details

Details for the file pymdvar-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pymdvar-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for pymdvar-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4f783fb26f2a7d1e366f29f9d484ba65c1bbb640c9c36b36f56340d2bdd6205c
MD5 a1195525817d25b0b3738fbf372c3012
BLAKE2b-256 e3bb8aa05a1445e154ea2f4b3cdfe6dac2709722e6de2d2f93a56407d2381b56

See more details on using hashes here.

Supported by

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