2005-01-24 19:52:04 +01:00
|
|
|
# heavily based off difflib.py - see that file for documentation
|
|
|
|
# ported from Python by Bill Atkins
|
|
|
|
|
|
|
|
# This does not support all features offered by difflib; it
|
|
|
|
# implements only the subset of features necessary
|
|
|
|
# to support a Ruby version of HTML Differ. You're welcome to finish this off.
|
|
|
|
|
|
|
|
# By default, String#each iterates by line. This isn't really appropriate
|
|
|
|
# for diff, so often a string will be split by // to get an array of one-
|
|
|
|
# character strings.
|
|
|
|
|
|
|
|
# Some methods in Diff are untested and are not guaranteed to work. The
|
|
|
|
# methods in HTMLDiff and any methods it calls should work quite well.
|
|
|
|
|
|
|
|
# changes by DenisMertz
|
|
|
|
# * main change:
|
|
|
|
# ** get the tag soup away
|
|
|
|
# the tag soup problem was first reported with <p> tags, but it appeared also with
|
|
|
|
# <li>, <ul> etc... tags
|
|
|
|
# this version should mostly fix these problems
|
|
|
|
# ** added a Builder class to manage the creation of the final htmldiff
|
|
|
|
# * minor changes:
|
|
|
|
# ** use symbols instead of string to represent opcodes
|
|
|
|
# ** small fix to html2list
|
|
|
|
#
|
|
|
|
|
|
|
|
module Enumerable
|
|
|
|
def reduce(init)
|
|
|
|
result = init
|
|
|
|
each { |item| result = yield(result, item) }
|
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
class Object
|
|
|
|
def nil_or_empty?
|
|
|
|
nil? or empty?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-01-24 19:52:04 +01:00
|
|
|
module Diff
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
module Utilities
|
|
|
|
def explode(sequence)
|
|
|
|
sequence.is_a?(String) ? sequence.split(//) : sequence
|
|
|
|
end
|
|
|
|
|
|
|
|
def newline?(char)
|
|
|
|
%W(\n \r).include? char
|
|
|
|
end
|
|
|
|
|
|
|
|
def tab?(char)
|
|
|
|
"\t" == char
|
|
|
|
end
|
|
|
|
|
|
|
|
# XXX Could be more robust but unrecognized tags cause an infinite loop so
|
|
|
|
# better to be permissive
|
|
|
|
def open_tag?(char)
|
|
|
|
char =~ /\A<[^>]+>/
|
|
|
|
end
|
|
|
|
|
|
|
|
# See comment for open_tag?
|
|
|
|
def close_tag?(char)
|
|
|
|
char =~ %r!\A</[^>]+>!
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_of_tag?(char)
|
|
|
|
char == '>'
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_of_tag?(char)
|
|
|
|
char == '<'
|
|
|
|
end
|
|
|
|
|
|
|
|
def html2list(x, use_brackets = false)
|
|
|
|
mode = :char
|
|
|
|
cur = ''
|
|
|
|
out = []
|
|
|
|
|
|
|
|
explode(x).each do |char|
|
|
|
|
case mode
|
|
|
|
when :tag
|
|
|
|
if end_of_tag? char
|
|
|
|
cur += use_brackets ? ']' : '>'
|
|
|
|
out.push cur
|
|
|
|
cur, mode = '', :char
|
|
|
|
else
|
|
|
|
cur += char
|
|
|
|
end
|
|
|
|
when :char
|
|
|
|
if start_of_tag? char
|
|
|
|
out.push cur
|
|
|
|
cur = use_brackets ? '[' : '<'
|
|
|
|
mode = :tag
|
|
|
|
elsif /\s/.match char
|
|
|
|
out.push cur + char
|
|
|
|
cur = ''
|
|
|
|
else
|
|
|
|
cur += char
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
out.push(cur)
|
|
|
|
out.delete ''
|
|
|
|
out.map {|elt| newline?(elt) ? elt : elt.chomp}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-01-24 19:52:04 +01:00
|
|
|
class SequenceMatcher
|
2005-11-14 11:13:18 +01:00
|
|
|
include Utilities
|
|
|
|
|
|
|
|
def initialize(a = [''], b = [''], isjunk = nil, byline = false)
|
|
|
|
a, b = explode(a), explode(b) unless byline
|
|
|
|
@isjunk = isjunk || Proc.new {}
|
|
|
|
set_sequences a, b
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
def set_sequences(a, b)
|
|
|
|
set_sequence_a a
|
|
|
|
set_sequence_b b
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
def set_sequence_a(a)
|
2005-01-24 19:52:04 +01:00
|
|
|
@a = a
|
|
|
|
@matching_blocks = @opcodes = nil
|
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
def set_sequence_b(b)
|
2005-01-24 19:52:04 +01:00
|
|
|
@b = b
|
|
|
|
@matching_blocks = @opcodes = nil
|
|
|
|
chain_b
|
|
|
|
end
|
|
|
|
|
|
|
|
def chain_b
|
|
|
|
@fullbcount = nil
|
2005-11-14 11:13:18 +01:00
|
|
|
@b2j = {}
|
|
|
|
pophash = {}
|
2005-01-24 19:52:04 +01:00
|
|
|
junkdict = {}
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
@b.each_with_index do |elt, idx|
|
2005-01-24 19:52:04 +01:00
|
|
|
if @b2j.has_key? elt
|
|
|
|
indices = @b2j[elt]
|
|
|
|
if @b.length >= 200 and indices.length * 100 > @b.length
|
|
|
|
pophash[elt] = 1
|
|
|
|
indices.clear
|
|
|
|
else
|
2005-11-14 11:13:18 +01:00
|
|
|
indices.push idx
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
else
|
2005-11-14 11:13:18 +01:00
|
|
|
@b2j[elt] = [idx]
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
pophash.each_key { |elt| @b2j.delete elt }
|
|
|
|
|
|
|
|
unless @isjunk.nil?
|
|
|
|
[pophash, @b2j].each do |d|
|
|
|
|
d.each_key do |elt|
|
|
|
|
if @isjunk.call(elt)
|
|
|
|
junkdict[elt] = 1
|
|
|
|
d.delete elt
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
@isbjunk = junkdict.method(:has_key?)
|
2005-01-24 19:52:04 +01:00
|
|
|
@isbpopular = junkdict.method(:has_key?)
|
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
def find_longest_match(a_low, a_high, b_low, b_high)
|
|
|
|
besti, bestj, bestsize = a_low, b_low, 0
|
2005-01-24 19:52:04 +01:00
|
|
|
|
|
|
|
j2len = {}
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
(a_low..a_high).step do |i|
|
2005-01-24 19:52:04 +01:00
|
|
|
newj2len = {}
|
|
|
|
(@b2j[@a[i]] || []).each do |j|
|
2005-11-14 11:13:18 +01:00
|
|
|
next if j < b_low
|
|
|
|
break if j >= b_high
|
2005-01-24 19:52:04 +01:00
|
|
|
|
|
|
|
k = newj2len[j] = (j2len[j - 1] || 0) + 1
|
|
|
|
if k > bestsize
|
|
|
|
besti, bestj, bestsize = i - k + 1, j - k + 1, k
|
|
|
|
end
|
|
|
|
end
|
|
|
|
j2len = newj2len
|
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
while besti > a_low and bestj > b_low and not @isbjunk.call(@b[bestj - 1]) and @a[besti - 1] == @b[bestj - 1]
|
|
|
|
besti, bestj, bestsize = besti - 1, bestj - 1, bestsize + 1
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
while besti + bestsize < a_high and bestj + bestsize < b_high and
|
|
|
|
not @isbjunk.call(@b[bestj + bestsize]) and
|
|
|
|
@a[besti + bestsize] == @b[bestj + bestsize]
|
2005-01-24 19:52:04 +01:00
|
|
|
bestsize += 1
|
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
while besti > a_low and bestj > b_low and @isbjunk.call(@b[bestj - 1]) and @a[besti - 1] == @b[bestj - 1]
|
|
|
|
besti, bestj, bestsize = besti - 1, bestj - 1, bestsize + 1
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
while besti + bestsize < a_high and bestj + bestsize < b_high and @isbjunk.call(@b[bestj+bestsize]) and
|
2005-01-24 19:52:04 +01:00
|
|
|
@a[besti+bestsize] == @b[bestj+bestsize]
|
|
|
|
bestsize += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
[besti, bestj, bestsize]
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_matching_blocks
|
2005-11-14 11:13:18 +01:00
|
|
|
return @matching_blocks unless @matching_blocks.nil_or_empty?
|
2005-01-24 19:52:04 +01:00
|
|
|
|
|
|
|
@matching_blocks = []
|
2005-11-14 11:13:18 +01:00
|
|
|
size_of_a, size_of_b = @a.size, @b.size
|
|
|
|
match_block_helper(0, size_of_a, 0, size_of_b, @matching_blocks)
|
|
|
|
@matching_blocks.push [size_of_a, size_of_b, 0]
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
def match_block_helper(a_low, a_high, b_low, b_high, answer)
|
|
|
|
i, j, k = x = find_longest_match(a_low, a_high, b_low, b_high)
|
|
|
|
unless k.zero?
|
|
|
|
match_block_helper(a_low, i, b_low, j, answer) if a_low < i and b_low < j
|
2005-01-24 19:52:04 +01:00
|
|
|
answer.push x
|
2005-11-14 11:13:18 +01:00
|
|
|
if i + k < a_high and j + k < b_high
|
|
|
|
match_block_helper(i + k, a_high, j + k, b_high, answer)
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_opcodes
|
2005-11-14 11:13:18 +01:00
|
|
|
return @opcodes unless @opcodes.nil_or_empty?
|
2005-01-24 19:52:04 +01:00
|
|
|
|
|
|
|
i = j = 0
|
|
|
|
@opcodes = answer = []
|
|
|
|
get_matching_blocks.each do |ai, bj, size|
|
|
|
|
tag = if i < ai and j < bj
|
|
|
|
:replace
|
|
|
|
elsif i < ai
|
|
|
|
:delete
|
|
|
|
elsif j < bj
|
|
|
|
:insert
|
|
|
|
end
|
|
|
|
|
|
|
|
answer.push [tag, i, ai, j, bj] if tag
|
|
|
|
i, j = ai + size, bj + size
|
|
|
|
answer.push [:equal, ai, i, bj, j] unless size.zero?
|
|
|
|
end
|
2005-11-14 11:13:18 +01:00
|
|
|
answer
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# XXX: untested
|
2005-11-14 11:13:18 +01:00
|
|
|
def get_grouped_opcodes(n = 3)
|
2005-01-24 19:52:04 +01:00
|
|
|
codes = get_opcodes
|
2005-11-14 11:13:18 +01:00
|
|
|
if codes.first.first == :equal
|
|
|
|
tag, i1, i2, j1, j2 = codes.first
|
2005-01-24 19:52:04 +01:00
|
|
|
codes[0] = tag, [i1, i2 - n].max, i2, [j1, j2-n].max, j2
|
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
if codes.last.first == :equal
|
|
|
|
tag, i1, i2, j1, j2 = codes.last
|
2005-01-24 19:52:04 +01:00
|
|
|
codes[-1] = tag, i1, min(i2, i1+n), j1, min(j2, j1+n)
|
|
|
|
end
|
2005-11-14 11:13:18 +01:00
|
|
|
|
2005-01-24 19:52:04 +01:00
|
|
|
nn = n + n
|
|
|
|
group = []
|
|
|
|
codes.each do |tag, i1, i2, j1, j2|
|
2005-11-14 11:13:18 +01:00
|
|
|
if tag == :equal and i2 - i1 > nn
|
2005-01-24 19:52:04 +01:00
|
|
|
group.push [tag, i1, [i2, i1 + n].min, j1, [j2, j1 + n].min]
|
|
|
|
yield group
|
|
|
|
group = []
|
|
|
|
i1, j1 = [i1, i2-n].max, [j1, j2-n].max
|
|
|
|
group.push [tag, i1, i2, j1 ,j2]
|
|
|
|
end
|
|
|
|
end
|
2005-11-14 11:13:18 +01:00
|
|
|
yield group if group and group.size != 1 and group.first.first == :equal
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def ratio
|
|
|
|
matches = get_matching_blocks.reduce(0) do |sum, triple|
|
2005-11-14 11:13:18 +01:00
|
|
|
sum + triple.last
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
2005-11-14 11:13:18 +01:00
|
|
|
Diff.calculate_ratio(matches, @a.size + @b.size)
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def quick_ratio
|
2005-11-14 11:13:18 +01:00
|
|
|
if @fullbcount.nil_or_empty?
|
2005-01-24 19:52:04 +01:00
|
|
|
@fullbcount = {}
|
|
|
|
@b.each do |elt|
|
|
|
|
@fullbcount[elt] = (@fullbcount[elt] || 0) + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
avail = {}
|
2005-01-24 19:52:04 +01:00
|
|
|
matches = 0
|
|
|
|
@a.each do |elt|
|
2005-11-14 11:13:18 +01:00
|
|
|
numb = avail.has_key?(elt) ? avail[elt] : (@fullbcount[elt] || 0)
|
2005-01-24 19:52:04 +01:00
|
|
|
avail[elt] = numb - 1
|
2005-11-14 11:13:18 +01:00
|
|
|
matches += 1 if numb > 0
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
2005-11-14 11:13:18 +01:00
|
|
|
Diff.calculate_ratio matches, @a.size + @b.size
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def real_quick_ratio
|
2005-11-14 11:13:18 +01:00
|
|
|
size_of_a, size_of_b = @a.size, @b.size
|
|
|
|
Diff.calculate_ratio([size_of_a, size_of_b].min, size_of_a + size_of_b)
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
protected :chain_b, :match_block_helper
|
|
|
|
end # end class SequenceMatcher
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
class << self
|
|
|
|
def calculate_ratio(matches, length)
|
|
|
|
return 1.0 if length.zero?
|
|
|
|
2.0 * matches / length
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
# XXX: untested
|
|
|
|
def get_close_matches(word, possibilities, n = 3, cutoff = 0.6)
|
|
|
|
raise "n must be > 0: #{n}" unless n > 0
|
|
|
|
raise "cutoff must be in (0.0..1.0): #{cutoff}" unless cutoff.between 0.0..1.0
|
|
|
|
|
|
|
|
result = []
|
|
|
|
sequence_matcher = Diff::SequenceMatcher.new
|
|
|
|
sequence_matcher.set_sequence_b word
|
|
|
|
possibilities.each do |possibility|
|
|
|
|
sequence_matcher.set_sequence_a possibility
|
|
|
|
if sequence_matcher.real_quick_ratio >= cutoff and
|
|
|
|
sequence_matcher.quick_ratio >= cutoff and
|
|
|
|
sequence_matcher.ratio >= cutoff
|
|
|
|
result.push [sequence_matcher.ratio, possibility]
|
|
|
|
end
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
2005-11-14 11:13:18 +01:00
|
|
|
|
|
|
|
unless result.nil_or_empty?
|
|
|
|
result.sort
|
|
|
|
result.reverse!
|
|
|
|
result = result[-n..-1]
|
|
|
|
end
|
|
|
|
result.map {|score, x| x }
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
def count_leading(line, ch)
|
|
|
|
count, size = 0, line.size
|
|
|
|
count += 1 while count < size and line[count].chr == ch
|
|
|
|
count
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module HTMLDiff
|
|
|
|
include Diff
|
|
|
|
class Builder
|
|
|
|
VALID_METHODS = [:replace, :insert, :delete, :equal]
|
|
|
|
def initialize(a, b)
|
2005-11-14 11:13:18 +01:00
|
|
|
@a, @b = a, b
|
2005-01-24 19:52:04 +01:00
|
|
|
@content = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_op(opcode)
|
|
|
|
@opcode = opcode
|
2005-11-14 11:13:18 +01:00
|
|
|
op = @opcode.first
|
|
|
|
raise NameError, "Invalid opcode '#{op}'" unless VALID_METHODS.include? op
|
|
|
|
send op
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def result
|
2005-11-14 11:13:18 +01:00
|
|
|
@content.join
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
# These methods have to be called via do_op(opcode) so that @opcode is set properly
|
2005-01-24 19:52:04 +01:00
|
|
|
private
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
def replace
|
|
|
|
delete('diffmod')
|
|
|
|
insert('diffmod')
|
|
|
|
end
|
|
|
|
|
|
|
|
def insert(tagclass = 'diffins')
|
|
|
|
op_helper('ins', tagclass, @b[@opcode[3]...@opcode[4]])
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete(tagclass = 'diffdel')
|
|
|
|
op_helper('del', tagclass, @a[@opcode[1]...@opcode[2]])
|
|
|
|
end
|
|
|
|
|
|
|
|
def equal
|
|
|
|
@content += @b[@opcode[3]...@opcode[4]]
|
|
|
|
end
|
2005-01-24 19:52:04 +01:00
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
# Using this as op_helper would be equivalent to the first version of diff.rb by Bill Atkins
|
|
|
|
def op_helper_simple(tagname, tagclass, to_add)
|
|
|
|
@content << %(<#{tagname} class="#{tagclass}">) << to_add << %(</#{tagname}>)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Tries to put <p> tags or newline chars before the opening diff tags (<ins> or <del>)
|
|
|
|
# or after the ending diff tags.
|
|
|
|
# As a result the diff tags should be the "most inside" possible.
|
|
|
|
def op_helper(tagname, tagclass, to_add)
|
|
|
|
predicate_methods = [:tab?, :newline?, :close_tag?, :open_tag?]
|
|
|
|
content_to_skip = Proc.new do |item|
|
|
|
|
predicate_methods.any? {|predicate| HTMLDiff.send(predicate, item)}
|
|
|
|
end
|
2005-01-24 19:52:04 +01:00
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
unless to_add.any? {|element| content_to_skip.call element}
|
|
|
|
@content << wrap_text(to_add, tagname, tagclass)
|
|
|
|
else
|
|
|
|
loop do
|
|
|
|
@content << to_add and break if to_add.all? {|element| content_to_skip.call element}
|
|
|
|
# We are outside of a diff tag
|
|
|
|
@content << to_add.shift while content_to_skip.call to_add.first
|
|
|
|
@content << %(<#{tagname} class="#{tagclass}">)
|
|
|
|
# We are inside a diff tag
|
|
|
|
@content << to_add.shift until content_to_skip.call to_add.first
|
|
|
|
@content << %(</#{tagname}>)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
#remove_empty_diff(tagname, tagclass)
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
def wrap_text(text, tagname, tagclass)
|
|
|
|
%(<#{tagname} class="#{tagclass}">#{text}</#{tagname}>)
|
|
|
|
end
|
2005-01-24 19:52:04 +01:00
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
def remove_empty_diff(tagname, tagclass)
|
|
|
|
@content = @content[0...-2] if last_elements_empty_diff?(@content, tagname, tagclass)
|
|
|
|
end
|
2005-01-24 19:52:04 +01:00
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
def last_elements_empty_diff?(content, tagname, tagclass)
|
|
|
|
content[-2] == %(<#{tagname} class="#{tagclass}">) and content.last == %(</#{tagname}>)
|
|
|
|
end
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
2005-11-14 11:13:18 +01:00
|
|
|
|
|
|
|
class << self
|
|
|
|
include Diff::Utilities
|
2005-01-24 19:52:04 +01:00
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
def diff(a, b)
|
|
|
|
a, b = html2list(explode(a)), html2list(explode(b))
|
2005-01-24 19:52:04 +01:00
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
out = Builder.new(a, b)
|
|
|
|
sequence_matcher = Diff::SequenceMatcher.new(a, b)
|
2005-01-24 19:52:04 +01:00
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
sequence_matcher.get_opcodes.each {|opcode| out.do_op(opcode)}
|
2005-01-24 19:52:04 +01:00
|
|
|
|
2005-11-14 11:13:18 +01:00
|
|
|
out.result
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
2005-11-14 11:13:18 +01:00
|
|
|
end
|
2005-01-24 19:52:04 +01:00
|
|
|
end
|
2005-11-14 11:13:18 +01:00
|
|
|
|
|
|
|
if __FILE__ == $0
|
|
|
|
if ARGV.size == 2
|
|
|
|
puts HTMLDiff.diff(IO.read(ARGV.pop), IO.read(ARGV.pop))
|
|
|
|
else
|
|
|
|
puts "Usage: html_diff file1 file2"
|
|
|
|
end
|
|
|
|
end
|