misc/txt2html.rb in metasm-1.0.1 vs misc/txt2html.rb in metasm-1.0.2
- old
+ new
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
+# encoding: binary (rage)
# This file is part of Metasm, the Ruby assembly manipulation suite
# Copyright (C) 2006-2009 Yoann GUILLOT
#
# Licence is LGPL, see LICENCE in the top-level directory
@@ -46,11 +47,11 @@
next
end
if e.class.ancestors.include? Elem
@content << e
else
- @content << e.to_s.gsub(Regexp.new("(#{@@quotechars.keys.join('|')})")) { |x| @@quotechars[x] }
+ @content << e.to_s.gsub(Regexp.new("(#{@@quotechars.keys.join('|')})", 'm')) { |x| @@quotechars[x] }
end
}
self
end
alias << add
@@ -271,11 +272,11 @@
outf = outfilename(f)
puts "compiling #{outf}..." if $VERBOSE
@pathfix = outf.split('/')[0...-1].map { '../' }.join
- out = compile(File.read(f).gsub("\r", '') + "\n\n")
+ out = compile(File.open(f, 'rb') { |fd| fd.read }.gsub("\r", '') + "\n\n")
File.open(outf, 'wb') { |fd| fd.write out.to_s.gsub("\r", '').gsub("\n", "\r\n") }
end
def outfilename(f)
f.sub(/\.txt$/, '') + '.html'
@@ -366,26 +367,26 @@
flush[]
out.head << Html::Elem.new('title').add(state[:title]) if state[:title]
out
end
- # handle **bold_words** *italic* `fixed` <links>
+ # handle **bold_words** *italic* `fixed` <links> **bold__word__with__underscore**
def compile_string(str)
o = [str]
on = []
o.each { |s|
while s.kind_of? String and o1 = s.index('**') and o2 = s.index('**', o1+2) and not s[o1..o2].index(' ')
- on << s[0...o1] << Html::Elem.new('b').add(s[o1+2...o2].tr('_', ' '))
+ on << s[0...o1] << Html::Elem.new('b').add(s[o1+2...o2].tr('_', ' ').gsub(' ', '_'))
s = s[o2+2..-1]
end
on << s
}
o = on
on = []
o.each { |s|
while s.kind_of? String and o1 = s.index('*') and o2 = s.index('*', o1+1) and not s[o1..o2].index(' ')
- on << s[0...o1] << Html::Elem.new('i').add(s[o1+1...o2].tr('_', ' '))
+ on << s[0...o1] << Html::Elem.new('i').add(s[o1+1...o2].tr('_', ' ').gsub(' ', '_'))
s = s[o2+1..-1]
end
on << s
}
o = on
@@ -407,22 +408,23 @@
if File.exist? lnk
case lnk[/\.(\w+)$/, 1]
when 'txt'
tg = outfilename(lnk)
Txt2Html.new(lnk)
- on << Html::A.new(@pathfix + tg, File.basename(lnk, '.txt').tr('_', ' '))
+ on << Html::A.new(@pathfix + tg, File.basename(lnk, '.txt').tr('_', ' ').gsub(' ', '_'))
when 'jpg', 'png'
on << Html::Img.new(lnk)
end
else
+ on << Html::A.new(lnk, lnk)
if lnk =~ /\.txt$/
@@seen_nofile ||= []
if not @@seen_nofile.include? lnk
@@seen_nofile << lnk
puts "reference to missing #{lnk.inspect}"
end
+ on.last.hclass('brokenlink')
end
- on << Html::A.new(lnk, lnk)
end
end
on << s
}
o = on