import sources

This commit is contained in:
Jörg Deckert 2020-08-31 21:29:18 +02:00
parent 5fb7c41a00
commit 9269fb97ba
4 changed files with 60 additions and 0 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
dist
build
*.egg-info
*.pyc
*.pyo
*~
*#

View File

@ -0,0 +1,35 @@
import re
from lektor.pluginsystem import Plugin
from markupsafe import escape
_class_re = re.compile(r'\s+:([a-zA-Z0-9_-]+)')
def split_classes(text):
classes = []
def _handle_match(match):
classes.append(match.group(1))
return ''
text = _class_re.sub(_handle_match, text).replace('\\:', ':')
return text, classes
class MarkdownLinkClassesPlugin(Plugin):
name = 'Markdown Link Classes'
description = 'Adds the ability to add classes to links.'
def on_markdown_config(self, config, **extra):
class LinkClassesMixin(object):
def link(renderer, link, title, text):
text, classes = split_classes(text)
if link.startswith('javascript:'):
link = ''
attr = ['href="%s"' % escape(link)]
if title:
attr.append('title="%s"' % escape(title))
if classes:
attr.append('class="%s"' % ' '.join(
escape(x) for x in classes))
return '<a %s>%s</a>' % (' '.join(attr), text)
config.renderer_mixins.append(LinkClassesMixin)

2
setup.cfg Normal file
View File

@ -0,0 +1,2 @@
[bdist_wheel]
universal=1

16
setup.py Normal file
View File

@ -0,0 +1,16 @@
from setuptools import setup
setup(
name='lektor-markdown-link-classes',
version='0.1',
author='Armin Ronacher',
author_email='armin.ronacher@active-4.com',
license='MIT',
py_modules=['lektor_markdown_link_classes'],
url='http://github.com/lektor/lektor',
entry_points={
'lektor.plugins': [
'markdown-link-classes = lektor_markdown_link_classes:MarkdownLinkClassesPlugin',
]
}
)