#{kdi}.ssm")
tell.green_hi_blue unless @opt.cmd =~/q/
system("cp #{kdi} /tmp/. && cd /tmp && tar xzvf /tmp/#{kdi} && cd -")
file=File.new("/tmp/maindoc.xml")
@output=File.new("#{kdi}.ssm",'w')
doc=Document.new(file)
root=doc.root
@el=[]
root.each do |x|
end
root.each_with_index do |content,idx|
if root.elements["item[#{idx}]/summary"]
id,ma,ch=nil,nil,[]
if root.elements["item[#{idx}]/id"]
id=root.elements["item[#{idx}]/id"].text.to_i
end
if root.elements["item[#{idx}]/parent"]
ma=root.elements["item[#{idx}]/parent"].text.to_s
end
if root.elements["item[#{idx}]/child"] #problem only get one child, even where several
root.get_elements("item[#{idx}]/child").each do |x|
ch << x.text
end
end
if root.elements["item[#{idx}]/summary"]
sum=root.elements["item[#{idx}]/summary"].text.to_s.strip
end
if root.elements["item[#{idx}]/text"]
txt=root.elements["item[#{idx}]/text"].text.to_s.strip
end
@el[id]={ :id=>id,:ma=>ma,:ch=>ch,:sum=>sum,:txt=>txt }
if ma=='-1'
@el[id][:lev]=':A'
@top=id
end
end
end
@doc=[]
@title=@el[@top][:sum]
puts @el[@top][:sum].inspect
@doc << @el[@top][:txt] #% careful: hack to make it possible to modify sisu headers
@doc << ':A~ ' + @el[@top][:sum]
@el[@top][:ch].each do |x|
@el[x.to_i][:lev]='1'
@doc << '1~ ' + @el[x.to_i][:sum]
@doc << @el[x.to_i][:txt]
@el[x.to_i][:ch].each do |y|
@el[y.to_i][:lev]='2'
@doc << '2~ ' + @el[y.to_i][:sum]
@doc << @el[y.to_i][:txt]
@el[y.to_i][:ch].each do |z|
@el[z.to_i][:lev]='3'
@doc << '3~ ' + @el[z.to_i][:sum]
@doc << @el[z.to_i][:txt]
@el[z.to_i][:ch].each do |za| #unsupported... consder
@el[za.to_i][:lev]='4'
@doc << '!_ ' + @el[za.to_i][:sum]
@doc << @el[za.to_i][:txt]
end
end
end
end
# regexs strip most kdissert markup, and provide minimal info for sisu markup -->
@doc.each do |c,idx|
c.gsub!(/<\/summary>/,'')
c.gsub!(/.+?\n|<\/body>|<\/html>|/m,'')
c.gsub!(/<\/p>/,"\n")
c.gsub!(/(.+?)<\/span>/,' *{ \1 }* ')
c.gsub!(/(.+?)<\/span>/,' _{ \1 }_ ')
c.gsub!(/(.+?)<\/span>/,' /{ \1 }/ ')
c.gsub!(//,'_* ')
c.gsub!(/<\S+?>/,'')
c.gsub!(/<br>/,'
')
c.gsub!(/<(:p[bn])>/,'<\1>')
c.gsub!(/<<([|]\S+[|]@[|].?[|])/,'<<\1')
c.gsub!(/</,'\<')
c.gsub!(/>/,'\>')
c.gsub!(/"/,'"')
c.gsub!(/ \s+/,' ')
@sisu_base << c.strip + "\n\n"
end
else puts ".kdi extension expected, filename not recognised: << #{kdi} >>"
end
@output << sisu_head << @sisu_base
end
else puts '.kdi file for conversion to sisu expected'
end
@opt.files.each do |f|
f.gsub!(/.kdi$/,'.kdi.ssm')
end
puts @opt.files.inspect
end
end
end
__END__