diff --git a/README.md b/README.md index 9337e0b..b4bfefc 100644 --- a/README.md +++ b/README.md @@ -6,16 +6,17 @@ Wraps the inline content with `ins` and `del` tags. Installation ------------ - - pip install git+git://github.com/aleray/mdx_del_ins.git - + + copy mdx_del_ins_markdown_3_0_1.py as a module Usage ----- >>> import markdown + >>> from mdx_del_ins_markdown_3_0_1 import DelInsExtension + >>> src = """This is ++added content++ and this is ~~deleted content~~""" - >>> html = markdown.markdown(src, ['del_ins']) + >>> html = markdown.markdown(src, extensions=[DelInsExtension()]) >>> print(html)

This is added content and this is deleted content

@@ -24,13 +25,13 @@ Usage Dependencies ------------ -* [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/) +* [Markdown 3.0.1](http://www.freewisdom.org/projects/python-markdown/) Copyright --------- -2011, 2012 [The active archives contributors](http://activearchives.org/) +2011, 2012, 2018 [The active archives contributors](http://activearchives.org/) All rights reserved. This software is released under the modified BSD License. diff --git a/mdx_del_ins_markdown_3_0_1.py b/mdx_del_ins_markdown_3_0_1.py new file mode 100644 index 0000000..82cfb96 --- /dev/null +++ b/mdx_del_ins_markdown_3_0_1.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +'''Markdown Del_Ins Extension + Compatible with Markdown 3.0.1 + Extends the Python-Markdown library to support superscript text. + Given the text: + ~~hello~~ + ++goodbye++ + Will output: + hello (Strikethrough) + goodbye (underlined) + :copyright: Copyright 2018 Bruno Vermeulen + :license: MIT, see LICENSE for details. + :use: + from mxd_del_ins import DelInsExtension + markdown_text = markdown.markdown(text, extensions = [DelInsExtension()]) + +''' +from markdown import Extension +from markdown.inlinepatterns import SimpleTagPattern + +# match ^, at least one character that is not ^, and ^ again +DEL_RE = r"(\~\~)(.+?)(\~\~)" +INS_RE = r"(\+\+)(.+?)(\+\+)" + + +def makeExtension(*args, **kwargs): # noqa: N802 + '''Inform Markdown of the existence of the extension.''' + return Del_InsExtension(*args, **kwargs) + + +class DelInsExtension(Extension): + '''Extension: + text between ~~ characters will be deleted; + text between ++ characters will be underlined; + ''' + + def extendMarkdown(self, md, md_globals): # noqa: N802 + """Insert 'del' pattern before 'not_strong' pattern.""" + md.inlinePatterns.add('del',SimpleTagPattern(DEL_RE, 'del'), + '