Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Merge pull request #4154 from gratipay/marky-markdown
Browse files Browse the repository at this point in the history
Wrap marky-markdown
  • Loading branch information
chadwhitacre authored Oct 22, 2016
2 parents 86a0e30 + ecdc8e0 commit 0453620
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ install:
- if [ "${TRAVIS_BRANCH}" = "master" -a "${TRAVIS_PULL_REQUEST}" = "false" ]; then rm -rf env; fi
- touch requirements.txt package.json
- make env
- npm install -g marky-markdown
before_script:
- echo "DATABASE_URL=dbname=gratipay" | tee -a tests/local.env local.env
- psql -U postgres -c 'CREATE DATABASE "gratipay";'
Expand Down
10 changes: 10 additions & 0 deletions gratipay/utils/markdown.py
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])
12 changes: 12 additions & 0 deletions tests/py/test_markdown.py
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

0 comments on commit 0453620

Please sign in to comment.