diff --git a/sphinx/themes/basic/static/websupport.js b/sphinx/themes/basic/static/websupport.js index 94123c5340..3881a42bcc 100644 --- a/sphinx/themes/basic/static/websupport.js +++ b/sphinx/themes/basic/static/websupport.js @@ -98,6 +98,9 @@ deleteComment($(this).attr('id').substring(2)); return false; }); + $('a.comment-markup').live("click", function() { + toggleCommentMarkupBox($(this).attr('id').substring(2)); + }); } /** @@ -271,7 +274,7 @@ $.each(comments, function() { var div = createCommentDiv(this); ul.append($(document.createElement('li')).html(div)); - appendComments(this.children, div.find('ul.children')); + appendComments(this.children, div.find('ul.comment-children')); // To avoid stagnating data, don't store the comments children in data. this.children = null; div.data('comment', this); @@ -353,7 +356,7 @@ div .find('span.user-id:first') .text('[deleted]').end() - .find('p.comment-text:first') + .find('div.comment-text:first') .text('[deleted]').end() .find('#cm' + id + ', #dc' + id + ', #ac' + id + ', #rc' + id + ', #sp' + id + ', #hp' + id + ', #cr' + id + ', #rl' + id) @@ -398,9 +401,11 @@ textarea.slideUp('fast'); } - /** - * Handle when the user clicks on a sort by link. - */ + function toggleCommentMarkupBox(id) { + $('#mb' + id).toggle(); + } + + /** Handle when the user clicks on a sort by link. */ function handleReSort(link) { var classes = link.attr('class').split(/\s+/); for (var i=0; i\ loading comments... \ \ -

Add a comment:

\ +

Add a comment\ + (markup):

\ +
\ + Comment markup:
\
\ \

\ @@ -730,7 +738,7 @@ <%pretty_rating%>\ <%time.delta%>\

\ -

<%text%>

\ +
<#text#>
\

\ \ reply ▿\ @@ -745,7 +753,7 @@

\
 <#proposal_diff#>\
         
\ - \ + \ \
\ \ diff --git a/sphinx/websupport/__init__.py b/sphinx/websupport/__init__.py index 9f8d9e304c..9a476ad982 100644 --- a/sphinx/websupport/__init__.py +++ b/sphinx/websupport/__init__.py @@ -9,6 +9,7 @@ :license: BSD, see LICENSE for details. """ +import cgi import sys import cPickle as pickle import posixpath @@ -16,6 +17,8 @@ from os import path from jinja2 import Environment, FileSystemLoader +from docutils.core import publish_parts + from sphinx.application import Sphinx from sphinx.util.osutil import ensuredir from sphinx.util.jsonimpl import dumps as dump_json @@ -308,6 +311,7 @@ class WebSupport(object): :param username: the username of the user making the comment. :param time: the time the comment was created, defaults to now. """ + text = self._parse_comment_text(text) comment = self.storage.add_comment(text, displayed, username, time, proposal, node_id, parent_id, moderator) @@ -442,3 +446,13 @@ class WebSupport(object): var COMMENT_METADATA = %s; ''' % dump_json(data) + + def _parse_comment_text(self, text): + settings = {'file_insertion_enabled': False, + 'output_encoding': 'unicode'} + try: + ret = publish_parts(text, writer_name='html', + settings_overrides=settings)['fragment'] + except Exception: + ret = cgi.escape(text) + return ret