HTMLDiff problem

  • Thread starter Stefan Matthias Aust
  • Start date
S

Stefan Matthias Aust

I'd a problem with Instiki's usage of HTMLDiff. Assume you've these two
strings

X <b>Y</b> Z
X <i>Y</i> Z

Applying HTMLDiff.diff on those strings results in

X
<del class="diffmod"><b></del>
<ins class="diffmod"><i></ins>
Y
<del class="diffmod"></b></del>
<ins class="diffmod"></i></ins>
Z

And I'm pretty sure this isn't valid HTML. At least Mozilla 1.7RC3 can't
render a larger Instiki page with lot's of similar code correctly.

Is there anything I can do about?

I found a workaround by adding these lines to Builder#op_helper:

def op_helper(tagname, tagclass, to_add)
if to_add.size == 1 and to_add.first =~
/^<\/?(b|i|tt|em|strong|code)>$/
@content << to_add.first if tagname == "ins"
to_add = []
end
...

In case that the diff is just an opening or closing tag, drop the old
tag and insert the new tag outside the diff. Some other method will
take care of empty diff tags so they're no problem.


bye
 
S

Stefan Matthias Aust

In case anybody cares, I think I fixed the problem by filtering the
contents of "to_add" through this method. My first attempt was to
naive... Now Instiki generates nice diffs again :)

def self.balance_inline_tags(tags)
result = []
stack = []
tags.each do |t|
if t =~ /^<(\/)?(b|i|tt|em|strong|code|span)/
if $1 # endtag
if stack.last == $2
stack.pop
else
# unbalanced end tag, generate start tag
result.unshift "<#$2>"
end
else
stack.push $2
end
end
result << t
end
# unbalanced start tags, generate end tags
stack.reverse_each {|t| result << "</#{t}>"}
result
end


bye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top