diff --git a/isso/tests/test_comments.py b/isso/tests/test_comments.py index 70bd3a3..1e2bdf1 100644 --- a/isso/tests/test_comments.py +++ b/isso/tests/test_comments.py @@ -375,6 +375,14 @@ class TestComments(unittest.TestCase): # just for the record self.assertEqual(self.post('/id/1/dislike', content_type=js).status_code, 200) + def testPreview(self): + response = self.post('/preview', data=json.dumps({'text': 'This is **mark***down*'})) + self.assertEqual(response.status_code, 200) + + rv = loads(response.data) + self.assertEqual(rv["text"], '

This is markdown

') + + class TestModeratedComments(unittest.TestCase): diff --git a/isso/views/comments.py b/isso/views/comments.py index 0272fa3..c0b03c6 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -89,7 +89,8 @@ class API(object): ('moderate',('POST', '/id///')), ('like', ('POST', '/id//like')), ('dislike', ('POST', '/id//dislike')), - ('demo', ('GET', '/demo')) + ('demo', ('GET', '/demo')), + ('preview', ('POST', '/preview')) ] def __init__(self, isso, hasher): @@ -476,5 +477,13 @@ class API(object): return JSON(self.comments.count(*data), 200) + def preview(self, environment, request): + data = request.get_json() + + if "text" not in data or data["text"] is None: + raise BadRequest("no text given") + + return JSON({'text': self.isso.render(data["text"])}, 200) + def demo(self, env, req): return redirect(get_current_url(env) + '/index.html')