#!/usr/bin/ruby -w require "rexml/document" require "rexml/text" html_doc = REXML::Document.new('') html_doc << REXML::XMLDecl.new html = html_doc.add_element("html") html_head = html.add_element("head") html_body = html.add_element("body") ARGV.each{|file| File.new(file).readlines.each { |line| line.strip! if line =~ /^[[:digit:]]+ / or line =~ /^Chapter / then html_body.add_element("h2").text = line elsif line =~ /^---+$/ then html_body.add_element("hr") elsif not line.empty?() then html_body.add_element("p").text = line end } } # f = File.new("/tmp/out.html", "w") html_doc.write($stdout, 0) # f.close() $stdout.puts # EOF #