Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create del_ins_markdown_3_0_1.py #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a regression in usability to me. Dependency management with pip is a highly desirable feature.


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()])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to the loss of installability via pip this makes configurations more complicated.

>>> print(html)
<p>This is <ins>added content</ins> and this is <del>deleted content</del>
</p>
Expand All @@ -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.
Expand Down
43 changes: 43 additions & 0 deletions mdx_del_ins_markdown_3_0_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems you're copy-pasting this entire file instead of modifying it to be compatible with markdown 3.0. Why is that?

'''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:
<del>hello</del> (Strikethrough)
<ins>goodbye</ins> (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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a typo and I don't expect to be able to execute. Did you test it?

Suggested change
return Del_InsExtension(*args, **kwargs)
return DelInsExtension(*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'),
'<not_strong')

md.inlinePatterns.add('ins', SimpleTagPattern(INS_RE, 'ins'),
'<not_strong')