diff --git a/.travis.yml b/.travis.yml index 76028c2533..f1a36e45b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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";' diff --git a/gratipay/utils/markdown.py b/gratipay/utils/markdown.py index a1826f93e6..6ff1a2e13d 100644 --- a/gratipay/utils/markdown.py +++ b/gratipay/utils/markdown.py @@ -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]) diff --git a/tests/py/test_markdown.py b/tests/py/test_markdown.py new file mode 100644 index 0000000000..7b140148cb --- /dev/null +++ b/tests/py/test_markdown.py @@ -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 = '

Hello World!

' + assert actual == expected