On Wed, 1 Oct 2008, _why wrote:

> Updated the built-in manual and added a table of contents.
> 
> <http://help.shoooes.net/>
> 
> I still need to finish the manual, give it an index, and expand the
> tutorial.  Do we need a FAQ?  Or is that just another link to loose
> people on?

Yes, have a faq. That way you don't have to update the manual so often
(unless you want to :-)).  The attached may be of some use in keeping
things simple.  I've not used it for a while so hopefully it hasn't
lost touch with modern Ruby.
> 
> _why
> 

        Hugh
#!/usr/local/bin/ruby
#  vim:set sw=2 et:
# A program to fixup the RMRS FAQ
# (derived from the code to process the DEAFBLND FAQ)
# By Hugh Sasse
# Originally dated about 1996.
#
# This processes a FAQ in the format described
# in FAQs: a Suggested Minimal Digest format
# http://www.cs.ruu.nl/wais/html/na-dir/faqs/minimal-digest-format.html
# and puts in links from the subjects to the
# questions, etc.
#
# Recently modified, in an attempt
# to handle HTML'ing of urls automatically
# including mailto addresses
# and to pick up the first line as the
# title of the faq.
# Converted to Ruby on 12-NOV-2004
#
# Note: This is written in Ruby http://www.ruby-lang.org/en/
#

def usage
    puts "usage: #{File.basename $0} [infile [outfile]]" 
    puts "       #{basename $0} [stem]"
    puts "In the second form the input file has extension"
    puts "'.txt' and the output has '.html' (stem.txt"
    puts "becomes stem.html). If no stem is given,"
    puts "then 'RMRS_FAQ' is tried."
    exit 0
end

stem = nil
case ARGV.size
when 0
   # This is of local interest only.
  stem = "RMRS_FAQ";
when 1
  stem = ARGV[0];
  if stem == '--help' or stem == '-h'
    usage
  end
when 2
  infile = ARGV[0];
  outfile = ARGV[1];
else
  usage
end

if stem
  infile = stem + ".txt";
  outfile = stem + ".html";
end

# Regexp to deal with mail addresses. (%r{...} creates a regexp object)
emailre = %r<(( 
   ([\w\%\-\_\/\=\:\.]+)  # words and some specials, including dot 
   |("[^\"]+\") # or quoted strings 
  )+\@          # followed by an at sign 
  (             # then 
  (([\w\-\_]+\.)        # a word or specials with one dot 
  ([\w\-\_\.]+))        # followed by more 
  |(\[(\d+\.){3}\d+\])  # or a dotted quad
))>ixo


open(infile, 'r') do |input| 
  open(outfile, 'w') do |output|

    output.print <<-'EOT'
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd";>
<html>
<head>
    EOT

    title_done = false;
    while line = input.gets
      unless title_done
        if line =~ /\S/
          output.print "<title>#{line}</title>\n"
          output.print "<style type=\"text/css\">\n"
          # output.print ".correct {background-color: #fffcfc}\n"
          output.print ".correct {background-color: yellow;}\n"
          output.print "</style>\n"
          output.print "</head>\n<body>\n<pre>\n"
          title_done = true;
        end
      end

      # Try to deal with escaped characters....
      line.gsub!(/&/,'&amp;')
      line.gsub!(/</,'&lt;')
      line.gsub!(/>/,'&gt;')

      # May as well try to fix copyright symbols
      # too at this stage, but beware lettered lists:
      line.gsub!(/(copyright\s*)\(c\)/i, '\1&copy;')
      line.gsub!(/\(c\)(\s*copyright)/i, '&copy;\1')

      # Attempt to deal with URLs
      line.gsub!(%r{(\w+\:\/\/((?!\&gt\;)[^\s<>"])+)}i,
        '<a href="\1">\1</a>')

      # Deal with markup for things that need to be fixed. (multiline match)
      line.gsub!(%r{\(\*}, '<span class="correct">\&')
      line.gsub!(%r{\*\)}, '\&</span>')

      # That ((?!\&gt\;)[^\s<>"])+ means:
      # Keep adding on [^\s<>"] characters, but
      # stop if the & is the start of &gt;

      # Attempt to deal with mail addresses.

      line.gsub!(emailre, %q{<a href="mailto:\1";>\1</A>})


      # Deal with the contents section:
      line.gsub!(%r{(         )((\d+\.*)+)}, '\1<a href="#\2">\2</A>')
      line.gsub!(%r{(Subject: )((\d+\.*)+)}, '\1<a name="\2">\2</A>')

      # Attempt to deal with other section references:
      line.gsub!(%r{(section |question |subject )((\d+\.*)+)}i, '\1<a 
href="#\2">\2</a>')
      output.print line ;
    end
    output.print "</PRE>\n</BODY>\n</HTML>\n";
  end
end

Reply via email to