-
Notifications
You must be signed in to change notification settings - Fork 3
/
mdx_cite.py
57 lines (35 loc) · 1.28 KB
/
mdx_cite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! /usr/bin/env python
'''
Cite Extension for Python-Markdown
==================================
Wraps the inline content surrounded by three double quotes into <cite> tags.
Usage
-----
>>> import markdown
>>> src = '"""Who Is Killing the Great Chefs of Europe?""" is the last movie I watched.'
>>> html = markdown.markdown(src, ['cite'])
>>> print(html)
<p><cite>Who Is Killing the Great Chefs of Europe?</cite> is the last movie I watched.</p>
Dependencies
------------
* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/)
Copyright
---------
2011, 2012 [The active archives contributors](http://activearchives.org/)
All rights reserved.
This software is released under the modified BSD License.
See LICENSE.md for details.
'''
import markdown
from markdown.inlinepatterns import SimpleTagPattern
CITE_RE = r'(\"{3})(.+?)\2'
class CiteExtension(markdown.extensions.Extension):
"""Adds cite extension to Markdown class"""
def extendMarkdown(self, md, md_globals):
"""Modifies inline patterns"""
md.inlinePatterns.add('cite', SimpleTagPattern(CITE_RE, 'cite'), '<not_strong')
def makeExtension(configs={}):
return CiteExtension(configs=dict(configs))
if __name__ == "__main__":
import doctest
doctest.testmod()