Skip to content
Snippets Groups Projects
Commit dd51825c authored by kez's avatar kez
Browse files

Add plugin for embedding markdown in HTML templates

parent 6bea6433
No related branches found
No related tags found
1 merge request!24Add plugin for embedding markdown in HTML templates
dist
build
*.pyc
*.pyo
*.egg-info
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# Lektor markdown tag
Embed markdown in a lektor template
## Installation
If you're using this, you're probably working on a [Tor project lektor site](https://gitlab.torproject.org/tpo/web) that uses [lego](https://gitlab.torproject.org/tpo/web/lego/). In that case, you don't need to do anything special after running
```sh
git submodule update --init --recursive
```
If you're *not* working on a TPO site, you can clone the [lego repo](https://gitlab.torproject.org/tpo/web/lego/) and copy the `packages/lektor-md-tag` directory to your lektor site's `packages`. Here's a small script to do that for you:
```sh
# run this in your lektor site directory
git clone --depth 1 https://gitlab.torproject.org/tpo/web/lego
mkdir -p packages
mv lego/packages/lektor-md-tag packages
rm -rf lego
```
## Usage
From within your Lektor HTML template:
```jinja
{{ md('**This is bold!**') }}
```
This jinja function *will* wrap paragraphs in a set of `<p></p>` tags; don't add use this tag inside an HTML paragraph. The above snippet renders like this:
```html
<p><strong>This is bold!</strong></p>
```
## License
[0BSD](https://opensource.org/licenses/0BSD). I cannot realistically be bothered to deal with copyright and licensing, have fun!
# -*- coding: utf-8 -*-
#Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
#
#THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
from lektor.markdown import markdown_to_html
from lektor.pluginsystem import Plugin
import markupsafe
class MarkdownTagPlugin(Plugin):
name = 'lektor markdown tag'
description = 'Embed markdown in a lektor template'
def on_setup_env(self, **extra):
def md(markdown_str: str):
return markupsafe.Markup(markdown_to_html(markdown_str)[0])
self.env.jinja_env.globals.update(md=md)
[bdist_wheel]
universal=1
import ast
import io
import re
from setuptools import setup, find_packages
with io.open('README.md', 'rt', encoding="utf8") as f:
readme = f.read()
_description_re = re.compile(r'description\s+=\s+(?P<description>.*)')
with open('lektor_markdown_tag.py', 'rb') as f:
description = str(ast.literal_eval(_description_re.search(
f.read().decode('utf-8')).group(1)))
setup(
author='',
author_email='',
description=description,
keywords='Lektor plugin',
license='0BSD',
long_description=readme,
long_description_content_type='text/markdown',
name='lektor-markdown-tag',
packages=find_packages(),
py_modules=['lektor_markdown_tag'],
# url='[link to your repository]',
version='0.1',
classifiers=[
'Framework :: Lektor',
'Environment :: Plugins',
],
entry_points={
'lektor.plugins': [
'markdown-tag = lektor_markdown_tag:MarkdownTagPlugin',
]
}
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment