2,764
社区成员




# To change this template, choose Tools | Templates
# and open the template in the editor.
class TxtToHtml
def initialize(filepath,outputpath=nil)
out = nil
out = File.open(outputpath, "w") if outputpath
File.open(filepath) do |f|
f.each do |line|
pre_html_string = anlyse(line)
html_string = tohtml(pre_html_string)
out.puts html_string if out
puts html_string
end
end
end
protected
#解析,转html前的处理,需要自己处理啊
def anlyse(line)
ret = line
return ret
end
#转化成html,举个例子
def tohtml(line)
content_tag(:div,line)
end
private
def content_tag(name,str)
"<" + name.to_s + ">" + str + "</" + name.to_s + ">"
end
end
TxtToHtml.new($*[0],$*[1])