1+ #! /usr/bin/env python
2+
3+
4+ '''
5+ Del/Ins Extension for Python-Markdown
6+ =====================================
7+ Wraps the inline content with ins/del tags.
8+ Usage
9+ -----
10+ >>> import markdown
11+ >>> src = """This is ++added content++ and this is ~~deleted content~~"""
12+ >>> html = markdown.markdown(src, ['del_ins'])
13+ >>> print(html)
14+ <p>This is <ins>added content</ins> and this is <del>deleted content</del>
15+ </p>
16+ Dependencies
17+ ------------
18+ * [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/)
19+ Copyright
20+ ---------
21+ 2011, 2012 [The active archives contributors](http://activearchives.org/)
22+ All rights reserved.
23+ This software is released under the modified BSD License.
24+ See LICENSE.md for details.
25+ '''
26+
27+
28+ import markdown
29+ from markdown .inlinepatterns import SimpleTagPattern
30+
31+
32+ DEL_RE = r"(\~\~)(.+?)(\~\~)"
33+ INS_RE = r"(\+\+)(.+?)(\+\+)"
34+
35+
36+ class DelInsExtension (markdown .extensions .Extension ):
37+ """Adds del_ins extension to Markdown class."""
38+
39+ def extendMarkdown (self , md , md_globals ):
40+ """Modifies inline patterns."""
41+ md .inlinePatterns .add ('del' , SimpleTagPattern (DEL_RE , 'del' ), '<not_strong' )
42+ md .inlinePatterns .add ('ins' , SimpleTagPattern (INS_RE , 'ins' ), '<not_strong' )
43+
44+
45+ def makeExtension (configs = {}):
46+ return DelInsExtension (configs = dict (configs ))
47+
48+
49+ if __name__ == "__main__" :
50+ import doctest
51+ doctest .testmod ()
0 commit comments