https://github.com/luevano/pymdvar
Python-Markdown extension for key-value pair conversion.
https://github.com/luevano/pymdvar
extension html markdown python-markdown website
Last synced: 3 days ago
JSON representation
Python-Markdown extension for key-value pair conversion.
- Host: GitHub
- URL: https://github.com/luevano/pymdvar
- Owner: luevano
- License: gpl-3.0
- Created: 2023-02-14T06:21:51.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-17T08:08:21.000Z (almost 3 years ago)
- Last Synced: 2025-10-31T02:23:48.278Z (3 months ago)
- Topics: extension, html, markdown, python-markdown, website
- Language: Python
- Homepage: https://luevano.xyz/
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
# 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](https://github.com/luevano/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:
```md
Foo ${variable} bar
```
Becomes:
```html
Foo value bar
```
## 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` options:
```py
>>> import markdown
>>> from pymdvar import VariableExtension
>>> markdown.markdown('foo *${test}* bar', extensions=[VariableExtension(variables={'test': 'value'})])
'
foo value bar
'
```
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:
```py
>>> import markdown
>>> markdown.markdown('foo *${test}* bar', extensions=['pymdvar'], extension_configs={'pymdvar': {'variables': {'test': 'value'}}})
'
foo value bar
'
```
## Options
Only supported options:
- `variables` (default `dict()`):
Dictionary containing key-value pairs for variable-values. Example
```py
variables={'test': 'value', 'key': 'value'}
```
- `enable_env` (default `False`):
Enables environment variable reading.