diff.rb ignores insides of <pre> and <code> blocks - this is better than mangling them

This commit is contained in:
Alexey Verkhovsky 2005-11-19 14:46:27 +00:00
parent 90fc099a78
commit 7de64bdecf

View file

@ -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 ? ']' : '>'
out.push cur case cur
cur, mode = '', :char when '<pre>' then mode = :pre
when '<code>' then mode = :code
else
out.push cur
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
@ -361,7 +382,7 @@ module HTMLDiff
def do_op(opcode) def do_op(opcode)
@opcode = opcode @opcode = opcode
op = @opcode.first op = @opcode.first
raise NameError, "Invalid opcode '#{op}'" unless VALID_METHODS.include? op raise NameError, "Invalid opcode '#{op}'" unless VALID_METHODS.include? op
send op send op
end end
@ -437,14 +458,14 @@ 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
end end