From 5168546b9f28bba85de2995abf29b8ab9f678017 Mon Sep 17 00:00:00 2001 From: Bruno Vermeulen Date: Mon, 10 Dec 2018 20:42:07 +0100 Subject: [PATCH 1/4] Create del_ins_markdown_3_0_1.py --- del_ins_markdown_3_0_1.py | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 del_ins_markdown_3_0_1.py diff --git a/del_ins_markdown_3_0_1.py b/del_ins_markdown_3_0_1.py new file mode 100644 index 0000000..9c15503 --- /dev/null +++ b/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 ~~ (or ++), at least one character, and ~~ (or ++) 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'), + ' Date: Mon, 10 Dec 2018 20:51:37 +0100 Subject: [PATCH 2/4] Delete del_ins_markdown_3_0_1.py --- del_ins_markdown_3_0_1.py | 43 --------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 del_ins_markdown_3_0_1.py diff --git a/del_ins_markdown_3_0_1.py b/del_ins_markdown_3_0_1.py deleted file mode 100644 index 9c15503..0000000 --- a/del_ins_markdown_3_0_1.py +++ /dev/null @@ -1,43 +0,0 @@ -# -*- 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 ~~ (or ++), at least one character, and ~~ (or ++) 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'), - ' Date: Mon, 10 Dec 2018 20:52:43 +0100 Subject: [PATCH 3/4] Create mdx_del_ins_markdown_3_0_1.py --- mdx_del_ins_markdown_3_0_1.py | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 mdx_del_ins_markdown_3_0_1.py 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'), + ' Date: Mon, 10 Dec 2018 20:59:55 +0100 Subject: [PATCH 4/4] Update README.md --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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.