1. Rufus Pollock
  2. moin-2.0-dev

Commits

Julian Brost  committed 181ae3f

Marked the rendered page content and the output of diff_html as Markup.

The HTML tags in the diff_html function are needed as they mark the changed parts.

  • Participants
  • Parent commits 9d20a4f
  • Branches default

Comments (0)

Files changed (3)

File MoinMoin/apps/frontend/views.py

View file
 from flatland import Form, String, Integer, Boolean, Enum
 from flatland.validation import Validator, Present, IsEmail, ValueBetween, URLValidator, Converted
 
+from jinja2 import Markup
+
 import pytz
 from babel import Locale
 
                               mimetype=item.mimetype,
                               first_rev_no=first_rev,
                               last_rev_no=last_rev,
-                              data_rendered=item._render_data(),
+                              data_rendered=Markup(item._render_data()),
                               show_navigation=(rev>=0),
                              )
     return Response(content, status)

File MoinMoin/items/__init__.py

View file
 
 from flask import request, url_for, send_file, Response, abort, escape
 from werkzeug import is_resource_modified
+from jinja2 import Markup
 
 from MoinMoin import _, N_
 from MoinMoin.themes import render_template
         new_text = self.data_storage_to_internal(newrev.read())
         storage_item = flaskg.storage.get_item(self.name)
         revs = storage_item.list_revisions()
-        return render_template('diff_text.html',
-                               item_name=self.name,
-                               oldrev=oldrev,
-                               newrev=newrev,
-                               min_revno=revs[0],
-                               max_revno=revs[-1],
-                               diffs=diff(old_text, new_text),
-                              )
+        diffs = [(d[0], Markup(d[1]), d[2], Markup(d[3])) for d in diff(old_text, new_text)]
+        return Markup(render_template('diff_text.html',
+                                      item_name=self.name,
+                                      oldrev=oldrev,
+                                      newrev=newrev,
+                                      min_revno=revs[0],
+                                      max_revno=revs[-1],
+                                      diffs=diffs,
+                                     ))
 
     def _render_data_diff_text(self, oldrev, newrev):
         from MoinMoin.util import diff_text

File MoinMoin/util/diff_html.py

View file
         if charobj.ratio() < 0.5:
             # Insufficient similarity.
             if leftpane:
-                leftresult = """<span>%s</span>""" % indent(escape(leftpane)) #HHH
+                leftresult = """<span>%s</span>""" % indent(escape(leftpane))
             else:
                 leftresult = ''
 
             if rightpane:
-                rightresult = """<span>%s</span>""" % indent(escape(rightpane)) #HHH
+                rightresult = """<span>%s</span>""" % indent(escape(rightpane))
             else:
                 rightresult = ''
         else:
             rightresult = ''
             for thismatch in charmatch:
                 if thismatch[0] - charlast[0] != 0:
-                    leftresult += """<span>%s</span>""" % indent( #HHH
+                    leftresult += """<span>%s</span>""" % indent(
                         escape(leftpane[charlast[0]:thismatch[0]]))
                 if thismatch[1] - charlast[1] != 0:
-                    rightresult += """<span>%s</span>""" % indent( #HHH
+                    rightresult += """<span>%s</span>""" % indent(
                         escape(rightpane[charlast[1]:thismatch[1]]))
                 leftresult += escape(leftpane[thismatch[0]:thismatch[0] + thismatch[2]])
                 rightresult += escape(rightpane[thismatch[1]:thismatch[1] + thismatch[2]])
                 charlast = (thismatch[0] + thismatch[2], thismatch[1] + thismatch[2])
 
-        leftpane = '<br>'.join([indent(x) for x in leftresult.splitlines()]) #HHH
-        rightpane = '<br>'.join([indent(x) for x in rightresult.splitlines()]) #HHH
+        leftpane = '<br>'.join([indent(x) for x in leftresult.splitlines()])
+        rightpane = '<br>'.join([indent(x) for x in rightresult.splitlines()])
         result.append((llineno, leftpane, rlineno, rightpane))
 
         lastmatch = (match[0] + match[2], match[1] + match[2])