diff.rb ignores insides of <pre> and <code> blocks - this is better than mangling them
This commit is contained in:
parent
90fc099a78
commit
7de64bdecf
1 changed files with 29 additions and 8 deletions
37
lib/diff.rb
37
lib/diff.rb
|
@ -82,8 +82,13 @@ module Diff
|
|||
when :tag
|
||||
if end_of_tag? char
|
||||
cur += use_brackets ? ']' : '>'
|
||||
out.push cur
|
||||
cur, mode = '', :char
|
||||
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
|
||||
|
||||
|
@ -361,7 +382,7 @@ module HTMLDiff
|
|||
|
||||
def do_op(opcode)
|
||||
@opcode = opcode
|
||||
op = @opcode.first
|
||||
op = @opcode.first
|
||||
raise NameError, "Invalid opcode '#{op}'" unless VALID_METHODS.include? op
|
||||
send op
|
||||
end
|
||||
|
@ -437,14 +458,14 @@ 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)
|
||||
|
||||
out = Builder.new(a, b)
|
||||
sequence_matcher = Diff::SequenceMatcher.new(a, b)
|
||||
|
||||
sequence_matcher.get_opcodes.each {|opcode| out.do_op(opcode)}
|
||||
|
||||
out.result
|
||||
out.result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue