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

Wrap marky-markdown #4154

Merged
merged 6 commits into from
Oct 22, 2016
Merged
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
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