# Produces the documentation text from within KLayout def xml2html(t) # strip XML processing instructions and DTD t = t.sub(/^.*/m, "") t = t.sub(/<\/body>.*$/m, "") # insert title in front of navigator t = t.sub(/

KLayout Documentation (Qt #{$qt}): ") # replace .xml references in hrefs t = t.gsub(/href=\"(.*?)\.xml\"/) { "href=\"#{$1}.html\""; } t = t.gsub(/href=\"(.*?)\.xml#(.*?)\"/) { "href=\"#{$1}.html##{$2}\""; } # replace simplified XML tags with an opening/closing tag t = t.gsub(/<(\w+)([^<>]*?)\/>/) { "<#{$1}#{$2}>" } # replace some closing tags which are not allowed t = t.gsub(/<\/br>/, "").gsub(/<\/img>/, "") t end title = "KLayout " title += ($klayout_version || "$version") + " " title += "(" title += ($klayout_version_date || "$date") + " " title += ($klayout_version_rev || "$rev") title += ") " title += ($target_info && $target_info != "" ? "[#{$target_info}] " : "") HEADER=<<"END" KLayout Documentation #{title} END TAIL=<<"END" END hs = RBA::HelpSource.new hs.urls.each do |url| begin fn = ($target_doc + url).sub(/\.xml$/, ".html") t = hs.get(url) t = HEADER + xml2html(t) + TAIL tt = nil if File.exist?(fn) File.open(fn, "rb") { |f| tt = f.read } end if t != tt puts "Writing #{fn} .." File.open(fn, "wb") do |f| f.write(t) end else puts "Retained #{fn}." end rescue => ex puts "*** ERROR: #{ex.to_s}" end end