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
|
when :tag
|
||||||
if end_of_tag? char
|
if end_of_tag? char
|
||||||
cur += use_brackets ? ']' : '>'
|
cur += use_brackets ? ']' : '>'
|
||||||
|
case cur
|
||||||
|
when '<pre>' then mode = :pre
|
||||||
|
when '<code>' then mode = :code
|
||||||
|
else
|
||||||
out.push cur
|
out.push cur
|
||||||
cur, mode = '', :char
|
cur, mode = '', :char
|
||||||
|
end
|
||||||
else
|
else
|
||||||
cur += char
|
cur += char
|
||||||
end
|
end
|
||||||
|
@ -98,6 +103,22 @@ module Diff
|
||||||
else
|
else
|
||||||
cur += char
|
cur += char
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -437,13 +458,13 @@ module HTMLDiff
|
||||||
include Diff::Utilities
|
include Diff::Utilities
|
||||||
|
|
||||||
def diff(a, b)
|
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)
|
out = Builder.new(a, b)
|
||||||
|
|
||||||
sequence_matcher = Diff::SequenceMatcher.new(a, b)
|
sequence_matcher = Diff::SequenceMatcher.new(a, b)
|
||||||
|
|
||||||
sequence_matcher.get_opcodes.each {|opcode| out.do_op(opcode)}
|
sequence_matcher.get_opcodes.each {|opcode| out.do_op(opcode)}
|
||||||
|
|
||||||
out.result
|
out.result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue