Re: RDoc HTML links?

Hugh Sasse <[email protected]>
Newsgroups gmane.comp.lang.ruby.documentation
Message-ID <[email protected]>
On Tue, 25 Jul 2006, Dave Howell wrote:

> 
> On Jul 25, 2006, at 6:31, Hugh Sasse wrote:
> 
> > On Tue, 25 Jul 2006, Dimitri Aivaliotis wrote:
> > 
> 
> > > If you want to convert RD to RDoc, you might want to try Hugh Sasse's tool
> > > here:
> > > 
> 
> > I was thinking about writing one of those recently, and forgot I
> > already had! :-)
> 
> Groovy. That'll come in handy. :)
> 

I was thinking about the following patch today.  I haven't applied
it to the version on the web yet, but if it's worth doing I will.
I've not had chance to test it yet, so beware wet paint.

        Hugh

--- /tmp/T0XVayfw       Wed Jul 26 18:25:11 2006
+++ rdtordoc.rb Wed Jul 26 17:13:36 2006
@@ -27,9 +27,9 @@
     /\(\(\'(.*?)\'\)\)/ => '(Note: \1)'  # Verbatim text.
   }

-  # The constructor takes an input object that responds to readline,
-  # and an output object that responds to puts.  Use is made of
-  # chomp when reading to allow conversion between line-endings if
+  # The constructor takes an input object that responds to #readline,
+  # and an output object that responds to #puts.  Use is made of
+  # #chomp when reading to allow conversion between line-endings if
   # necessary.  These are not specified here, so it is up to the
   # user to set $/ and $\ correctly.  IO-like objects are used for
   # greatest flexibility,
@@ -40,6 +40,14 @@
     @output = out_io
   end

+  def filter(text)
+    line = text.dup
+    @@mapping.each do |key,value|
+      line.gsub!(key, value)
+    end
+    return line
+  end
+
   def process()
     while line = @input.gets
       case @state
@@ -47,14 +55,18 @@
         if line =~ /^=end/
           @state=OUTSIDE_COMMENT
         else
-          @@mapping.each do |key,value|
-            line.gsub!(key, value)
-          end
+          line = filter(line)
         end
       when OUTSIDE_COMMENT
         if line =~ /^=begin/
           line.gsub!(/^=begin/, '=begin rdoc')
           @state=INSIDE_COMMENT
+        elsif line =~ /^(\s*?#)(.*)/
+          # Don't bother to filter trailing comments after code:
+          # too many traps with # in quotes.
+          leader = $1
+          trailer = $2
+          line = leader + filter(trailer)
         end
       else
         raise RdToRdocError.new("Unknown state #{@state}")
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.