-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
@@ -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. | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,43 @@ | ||||||
# -*- coding: utf-8 -*- | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
|
||||||
|
||||||
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') |
There was a problem hiding this comment.
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.