From 5a4cacc47908b4f0bbe0030bf1732807f911c084 Mon Sep 17 00:00:00 2001 From: agusmakmun Date: Fri, 13 Jan 2017 08:11:35 +0700 Subject: [PATCH] support ~~strikethrough~~ and ++underscores++ --- README.rst | 1 + draceditor/__init__.py | 2 +- draceditor/extensions/del_ins.py | 51 ++++++++++++++++++++++ draceditor/settings.py | 1 + draceditor/static/js/draceditor.js | 2 +- draceditor/templates/draceditor/guide.html | 16 ++++++- upload.sh | 2 + 7 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 draceditor/extensions/del_ins.py diff --git a/README.rst b/README.rst index 37bdf0b7b..63d414e02 100644 --- a/README.rst +++ b/README.rst @@ -126,6 +126,7 @@ to get ``IMGUR_CLIENT_ID`` and ``IMGUR_API_KEY``. # Custom markdown extensions. 'draceditor.extensions.urlize', + 'draceditor.extensions.del_ins', # ~~strikethrough~~ and ++underscores++ 'draceditor.extensions.mention', # require for mention 'draceditor.extensions.emoji', # require for emoji ] diff --git a/draceditor/__init__.py b/draceditor/__init__.py index 2f37ac21d..e8524a37a 100644 --- a/draceditor/__init__.py +++ b/draceditor/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -__VERSION__ = '1.1.4' +__VERSION__ = '1.1.5' __AUTHOR__ = 'Agus Makmun (Summon Agus)' __AUTHOR_EMAIL__ = 'agus@python.web.id' diff --git a/draceditor/extensions/del_ins.py b/draceditor/extensions/del_ins.py new file mode 100644 index 000000000..467d83d5b --- /dev/null +++ b/draceditor/extensions/del_ins.py @@ -0,0 +1,51 @@ +#! /usr/bin/env python + + +''' +Del/Ins Extension for Python-Markdown +===================================== +Wraps the inline content with ins/del tags. +Usage +----- + >>> import markdown + >>> src = """This is ++added content++ and this is ~~deleted content~~""" + >>> html = markdown.markdown(src, ['del_ins']) + >>> print(html) +

This is added content and this is deleted content +

+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 + + +DEL_RE = r"(\~\~)(.+?)(\~\~)" +INS_RE = r"(\+\+)(.+?)(\+\+)" + + +class DelInsExtension(markdown.extensions.Extension): + """Adds del_ins extension to Markdown class.""" + + def extendMarkdown(self, md, md_globals): + """Modifies inline patterns.""" + md.inlinePatterns.add('del', SimpleTagPattern(DEL_RE, 'del'), 'Command+B Bold + + ++Underscores++ + — + — + — + Underscores + + + ~~Strikethrough~~ + — + — + — + Strikethrough + # Heading 1 Heading 1
========= @@ -52,7 +66,7 @@ ## Heading 2 - Heading 2
--------- + Heading 2
----------- Ctrl+Alt+2 Command+Option+2

Heading 2

diff --git a/upload.sh b/upload.sh index e7107b486..9acd065d6 100755 --- a/upload.sh +++ b/upload.sh @@ -4,6 +4,8 @@ # ./upload.sh pypi if [ "$1" == "pypi" ]; then python setup.py sdist upload -r pypi + cd ../organization/dracos-markdown-editor + git fetch upstream && git merge upstream/master && git push fi if [ "$1" == "git" ]; then