Commits

Georg Brandl  committed fb51138

Allow rst markup in the comment text.

  • Participants
  • Parent commits e4b86a1

Comments (0)

Files changed (2)

File sphinx/themes/basic/static/websupport.js

       deleteComment($(this).attr('id').substring(2));
       return false;
     });
+    $('a.comment-markup').live("click", function() {
+      toggleCommentMarkupBox($(this).attr('id').substring(2));
+    });
   }
 
   /**
     $.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);
         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)
     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<classes.length; i++) {
       <div class="comment-loading" id="cn<%id%>">\
         loading comments... <img src="<%loadingImage%>" alt="" /></div>\
       <ul id="cl<%id%>" class="comment-ul"></ul>\
-      <p class="add-a-comment">Add a comment:</p>\
+      <p class="add-a-comment">Add a comment\
+        (<a href="#" class="comment-markup" id="ab<%id%>">markup</a>):</p>\
+      <div class="comment-markup-box" id="mb<%id%>">\
+        Comment markup: </div>\
       <form method="post" id="cf<%id%>" class="comment-form" action="">\
         <textarea name="comment" cols="80"></textarea>\
         <p class="propose-button">\
           <span class="rating"><%pretty_rating%></span>\
           <span class="delta"><%time.delta%></span>\
         </p>\
-        <p class="comment-text comment"><%text%></p>\
+        <div class="comment-text comment"><#text#></div>\
         <p class="comment-opts comment">\
           <a href="#" class="reply hidden" id="rl<%id%>">reply &#9657;</a>\
           <a href="#" class="close-reply" id="cr<%id%>">reply &#9663;</a>\
         <pre class="proposal" id="pr<%id%>">\
 <#proposal_diff#>\
         </pre>\
-          <ul class="children" id="cl<%id%>"></ul>\
+          <ul class="comment-children" id="cl<%id%>"></ul>\
         </div>\
         <div class="clearleft"></div>\
       </div>\

File sphinx/websupport/__init__.py

     :license: BSD, see LICENSE for details.
 """
 
+import cgi
 import sys
 import cPickle as pickle
 import posixpath
 
 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
         :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)
         var COMMENT_METADATA = %s;
         </script>
         ''' % 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