diff.rb ignores insides of <pre> and <code> blocks - this is better than mangling them
This commit is contained in:
parent
90fc099a78
commit
7de64bdecf
27
lib/diff.rb
27
lib/diff.rb
|
@ -82,8 +82,13 @@ module Diff
|
|||
when :tag
|
||||
if end_of_tag? char
|
||||
cur += use_brackets ? ']' : '>'
|
||||
case cur
|
||||
when '<pre>' then mode = :pre
|
||||
when '<code>' then mode = :code
|
||||
else
|
||||
out.push cur
|
||||
cur, mode = '', :char
|
||||
end
|
||||
else
|
||||
cur += char
|
||||
end
|
||||
|
@ -98,6 +103,22 @@ module Diff
|
|||
else
|
||||
cur += char
|
||||
end
|
||||
when :pre
|
||||
if end_of_tag?(char) and cur =~ %r!</pre$!
|
||||
cur += '>'
|
||||
out.push cur
|
||||
cur, mode = '', :char
|
||||
else
|
||||
cur += char
|
||||
end
|
||||
when :code
|
||||
if end_of_tag?(char) and cur =~ %r!</code$!
|
||||
cur += '>'
|
||||
out.push cur
|
||||
cur, mode = '', :char
|
||||
else
|
||||
cur += char
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -437,13 +458,13 @@ module HTMLDiff
|
|||
include Diff::Utilities
|
||||
|
||||
def diff(a, b)
|
||||
a, b = html2list(explode(a)), html2list(explode(b))
|
||||
a = html2list(explode(a))
|
||||
b = html2list(explode(b))
|
||||
|
||||
out = Builder.new(a, b)
|
||||
|
||||
sequence_matcher = Diff::SequenceMatcher.new(a, b)
|
||||
|
||||
sequence_matcher.get_opcodes.each {|opcode| out.do_op(opcode)}
|
||||
|
||||
out.result
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue