import sources
This commit is contained in:
parent
5fb7c41a00
commit
9269fb97ba
|
@ -0,0 +1,7 @@
|
|||
dist
|
||||
build
|
||||
*.egg-info
|
||||
*.pyc
|
||||
*.pyo
|
||||
*~
|
||||
*#
|
|
@ -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)
|
|
@ -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',
|
||||
]
|
||||
}
|
||||
)
|
Loading…
Reference in New Issue