This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4154 from gratipay/marky-markdown
Wrap marky-markdown
- Loading branch information
Showing
3 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
from subprocess import Popen, PIPE | ||
|
||
from markupsafe import Markup | ||
import misaka as m # http://misaka.61924.nl/ | ||
|
||
|
||
def render(markdown): | ||
return Markup(m.html( | ||
markdown, | ||
extensions=m.EXT_AUTOLINK | m.EXT_STRIKETHROUGH | m.EXT_NO_INTRA_EMPHASIS, | ||
render_flags=m.HTML_SKIP_HTML | m.HTML_TOC | m.HTML_SMARTYPANTS | m.HTML_SAFELINK | ||
)) | ||
|
||
|
||
def marky(markdown): | ||
"""Process markdown the same way npm does. | ||
""" | ||
marky = Popen(("marky-markdown", "/dev/stdin"), stdin=PIPE, stdout=PIPE) | ||
return Markup(marky.communicate(markdown)[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from gratipay.testing import Harness | ||
from gratipay.utils import markdown | ||
|
||
from HTMLParser import HTMLParser | ||
|
||
class TestMarkdown(Harness): | ||
|
||
def test_marky_works(self): | ||
md = "**Hello World!**" | ||
actual = HTMLParser().unescape(markdown.marky(md)).strip() | ||
expected = '<p><strong>Hello World!</strong></p>' | ||
assert actual == expected |