mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
Use Diffy as DiffEngine implementation
This commit is contained in:
parent
19860bd2c5
commit
204dcc43a4
5 changed files with 74 additions and 9 deletions
|
@ -1,21 +1,24 @@
|
|||
# This class is used to generate diffs, it will be consumed by the UI on
|
||||
# on the client the displays diffs.
|
||||
#
|
||||
# Ruby has the diff/lcs engine that can do some of the work, the devil
|
||||
# is in the details
|
||||
# There are potential performance issues associated with diffing large amounts of completely
|
||||
# different text, see answer here for optimization if needed
|
||||
# http://meta.stackoverflow.com/questions/127497/suggested-edit-diff-shows-different-results-depending-upon-mode
|
||||
|
||||
class DiffEngine
|
||||
|
||||
# generate an html friendly diff similar to the way Stack Exchange generate
|
||||
# html diffs
|
||||
# generate an html friendly diff similar to the way Stack Exchange generates
|
||||
# html diffs
|
||||
#
|
||||
# returns: html containing decorations indicating the changes
|
||||
def self.html_diff(html_before, html_after)
|
||||
Diffy::Diff.new(html_before, html_after).to_s(:html)
|
||||
end
|
||||
|
||||
# same as html diff, except that it operates on markdown
|
||||
#
|
||||
# returns html containing decorated areas where diff happened
|
||||
def self.markdown_diff(markdown_before, markdown_after)
|
||||
Diffy::Diff.new(markdown_before, markdown_after).to_s(:html)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue