From e43f8153791967591279de29c5520fd0454ab8b6 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Fri, 21 Oct 2016 20:08:11 -0400 Subject: [PATCH 1/6] Stub out marky-markdown --- gratipay/utils/markdown.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gratipay/utils/markdown.py b/gratipay/utils/markdown.py index a1826f93e6..7dd217d59a 100644 --- a/gratipay/utils/markdown.py +++ b/gratipay/utils/markdown.py @@ -1,9 +1,18 @@ +import subprocess + 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. + """ + return subprocess.call() From 5188c2ad4cd1e76877e5293cf5859fc0b981200e Mon Sep 17 00:00:00 2001 From: aandis Date: Sat, 22 Oct 2016 16:48:56 +0530 Subject: [PATCH 2/6] Render markdown with marky. --- gratipay/utils/markdown.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gratipay/utils/markdown.py b/gratipay/utils/markdown.py index 7dd217d59a..50c2e9ccd5 100644 --- a/gratipay/utils/markdown.py +++ b/gratipay/utils/markdown.py @@ -1,4 +1,4 @@ -import subprocess +from subprocess import Popen, PIPE from markupsafe import Markup import misaka as m # http://misaka.61924.nl/ @@ -15,4 +15,6 @@ def render(markdown): def marky(markdown): """Process markdown the same way npm does. """ - return subprocess.call() + echo = Popen(("echo", markdown), stdout=PIPE) + marky = Popen(("marky-markdown", "/dev/stdin"), stdin=echo.stdout, stdout=PIPE) + return marky.communicate()[0] From 386a63080b0427dfa6e66c2e1b1ba30eaf0f9e2e Mon Sep 17 00:00:00 2001 From: aandis Date: Sat, 22 Oct 2016 17:13:24 +0530 Subject: [PATCH 3/6] Wrap html with markup. --- gratipay/utils/markdown.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gratipay/utils/markdown.py b/gratipay/utils/markdown.py index 50c2e9ccd5..f47f23aa2d 100644 --- a/gratipay/utils/markdown.py +++ b/gratipay/utils/markdown.py @@ -17,4 +17,4 @@ def marky(markdown): """ echo = Popen(("echo", markdown), stdout=PIPE) marky = Popen(("marky-markdown", "/dev/stdin"), stdin=echo.stdout, stdout=PIPE) - return marky.communicate()[0] + return Markup(marky.communicate()[0]) From c71a43dae259299952cec082d33f003ecaeb9eab Mon Sep 17 00:00:00 2001 From: aandis Date: Sat, 22 Oct 2016 20:23:55 +0530 Subject: [PATCH 4/6] Add marky test. --- tests/py/test_markdown.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/py/test_markdown.py 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 From 6c3d2313e95b59f868e7f463055c9b1b4adf4d66 Mon Sep 17 00:00:00 2001 From: aandis Date: Sat, 22 Oct 2016 20:31:55 +0530 Subject: [PATCH 5/6] Ask travis to install marky. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) 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";' From ecdc8e0205f80ea9b123be0f5673b2e5a2a1dc90 Mon Sep 17 00:00:00 2001 From: aandis Date: Sat, 22 Oct 2016 20:58:25 +0530 Subject: [PATCH 6/6] Use stdin pipe with communicate instead of echo. --- gratipay/utils/markdown.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gratipay/utils/markdown.py b/gratipay/utils/markdown.py index f47f23aa2d..6ff1a2e13d 100644 --- a/gratipay/utils/markdown.py +++ b/gratipay/utils/markdown.py @@ -15,6 +15,5 @@ def render(markdown): def marky(markdown): """Process markdown the same way npm does. """ - echo = Popen(("echo", markdown), stdout=PIPE) - marky = Popen(("marky-markdown", "/dev/stdin"), stdin=echo.stdout, stdout=PIPE) - return Markup(marky.communicate()[0]) + marky = Popen(("marky-markdown", "/dev/stdin"), stdin=PIPE, stdout=PIPE) + return Markup(marky.communicate(markdown)[0])