From e5a189fc170b91d110b3a369c6ff3773f42411fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 13 Jun 2014 11:29:10 +0200 Subject: [PATCH] BUGFIX: broken images in edit history with markdown view --- lib/discourse_diff.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/discourse_diff.rb b/lib/discourse_diff.rb index ea5152ac2..aee063fd0 100644 --- a/lib/discourse_diff.rb +++ b/lib/discourse_diff.rb @@ -7,9 +7,13 @@ class DiscourseDiff def initialize(before, after) @before = before @after = after + before_html = tokenize_html_blocks(@before) + after_html = tokenize_html_blocks(@after) + before_markdown = tokenize_line(CGI::escapeHTML(@before)) + after_markdown = tokenize_line(CGI::escapeHTML(@after)) - @block_by_block_diff = ONPDiff.new(tokenize_html_blocks(@before), tokenize_html_blocks(@after)).diff - @line_by_line_diff = ONPDiff.new(tokenize_line(@before), tokenize_line(@after)).short_diff + @block_by_block_diff = ONPDiff.new(before_html, after_html).diff + @line_by_line_diff = ONPDiff.new(before_markdown, after_markdown).short_diff end def inline_html @@ -91,8 +95,8 @@ class DiscourseDiff table << "" op_code = @line_by_line_diff[i][1] if op_code == :common - table << "#{CGI::escapeHTML(@line_by_line_diff[i][0])}" - table << "#{CGI::escapeHTML(@line_by_line_diff[i][0])}" + table << "#{@line_by_line_diff[i][0]}" + table << "#{@line_by_line_diff[i][0]}" else if op_code == :delete opposite_op_code = :add @@ -116,11 +120,11 @@ class DiscourseDiff i += 1 else if op_code == :delete - table << "#{CGI::escapeHTML(@line_by_line_diff[i][0])}" + table << "#{@line_by_line_diff[i][0]}" table << "" else table << "" - table << "#{CGI::escapeHTML(@line_by_line_diff[i][0])}" + table << "#{@line_by_line_diff[i][0]}" end end end @@ -221,8 +225,8 @@ class DiscourseDiff when :common deleted << d[0] inserted << d[0] - when :delete then deleted << "#{CGI::escapeHTML(d[0])}" - when :add then inserted << "#{CGI::escapeHTML(d[0])}" + when :delete then deleted << "#{d[0]}" + when :add then inserted << "#{d[0]}" end end [deleted, inserted]