From 610003b80cb42c82493517c16b04f5d223c4a21c Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Wed, 7 Nov 2012 17:53:07 +0100 Subject: Add rst parsing for comments. Slightly crude for now, but I need to head out to the movies --- famille.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'famille.py') diff --git a/famille.py b/famille.py index 4a8cb73..6b128d6 100644 --- a/famille.py +++ b/famille.py @@ -5,6 +5,13 @@ from flask import Flask, request, session, g, redirect, url_for, \ abort, render_template, flash, _app_ctx_stack from functools import wraps import hashlib +from docutils import core +from docutils.writers.html4css1 import Writer + +def rstify_comment(string): + w = Writer() + result = core.publish_parts(string, writer=w)['fragment'] + return result # configuration app = Flask(__name__) @@ -68,7 +75,7 @@ def show_news(news_id): return render_template("news/show.html", news=news, comments=comments) elif request.method == 'POST': user_id = session['user_id'] - content = request.form['content'] + content = rstify(request.form['content']) g.db.execute("INSERT INTO comments ('user_id', 'content', 'news_id') " "VALUES (?, ?, ?)", (user_id, content, news_id)) g.db.commit() -- cgit v1.2.3-70-g09d2