From: Wybo Dekker Date: 2006-10-17T19:36:40+09:00 Subject: Re: [PATCH] RDoc: preserve special chars in Was: Re: bug in rdoc? That worked fine, thank you very much! Jan Svitok wrote: > On 10/16/06, Wybo Dekker wrote: >> >> >> Jan Svitok wrote: >> > On 10/16/06, Morton Goldberg wrote: >> >> On Oct 16, 2006, at 7:10 AM, Wybo Dekker wrote: >> >> >> >> > -- The following example, is taken from the rdoc documentation. >> >> > For the long options, it converts -- into — (a long hyphen) >> >> > instead of two separate hyphens with some whitespace in between. >> >> > (see www.servalys.nl/ doc/index.html for the output) >> >> > >> >> > =begin rdoc >> >> > >> >> > --output name [, name]:: >> >> > specify the name of one or more output files. If multiple >> >> > files are present, the first is used as the index. >> >> > >> >> > --quiet::: do not output the names, sizes, byte counts, >> >> > index areas, or bit ratios of units as >> >> > they are processed. >> >> > >> >> > =end >> >> > >> >> > Is this a bug in rdoc? >> >> >> >> No, it's a feature. >> >> >> >> Back in the old days, when people typed on typewriters, which didn't >> >> have an em-dash (what you call a long hyphen) key, two hyphens were >> >> used to indicate an em-dash. Since the ASCII character set doesn't >> >> have em-dash, this convention is carried over to rdoc. >> >> >> >> Why does this bother you? >> > >> > Because it's not clearly visible that one must type two dashes there. >> > The solution would be to not convert special chars in blocks >> >> I agree! > > Attached is a patch that implements this (special chars are preserve > inside tt tags). I don't know much about RDoc internal, so please > check it. I added a simple unit test, as well. I couldn't manage CVS > to includeit with others, so it's attached separately. > > > ------------------------------------------------------------------------ > > ? rdoc-tt.patch > ? test/TestToHtml.rb > Index: simple_markup/to_html.rb > =================================================================== > RCS file: /src/ruby/lib/rdoc/markup/simple_markup/to_html.rb,v > retrieving revision 1.1 > diff -p -u -1 -r1.1 to_html.rb > --- simple_markup/to_html.rb 1 Dec 2003 07:12:48 -0000 1.1 > +++ simple_markup/to_html.rb 16 Oct 2006 22:00:51 -0000 > @@ -22,2 +22,6 @@ module SM > init_tags > + > + # @in_tt - tt nested levels count > + # @tt_bit - cache > + @in_tt, @tt_bit = 0, SM::Attribute.bitmap_for(:TT) > end > @@ -154,2 +158,3 @@ module SM > res << annotate(tag.on) > + @in_tt += 1 if tt?(tag) > end > @@ -164,2 +169,3 @@ module SM > if attr_mask & tag.bit != 0 > + @in_tt -= 1 if tt?(tag) > res << annotate(tag.off) > @@ -169,2 +175,12 @@ module SM > > + # are we currently inside tags? > + def in_tt? > + @in_tt > 0 > + end > + > + # is +tag+ a tag? > + def tt?(tag) > + tag.bit == @tt_bit > + end > + > def convert_flow(flow) > @@ -190,4 +206,12 @@ module SM > def convert_string(item) > - CGI.escapeHTML(item). > + # leave special chars intact inside tags > + in_tt? ? convert_string_simple(item) : convert_string_fancy(item) > + end > + > + def convert_string_simple(item) > + CGI.escapeHTML(item) > + end > > + def convert_string_fancy(item) > + convert_string_simple(item). > > Index: test/AllTests.rb > =================================================================== > RCS file: /src/ruby/lib/rdoc/markup/test/AllTests.rb,v > retrieving revision 1.1 > diff -p -u -1 -r1.1 AllTests.rb > --- test/AllTests.rb 1 Dec 2003 07:12:49 -0000 1.1 > +++ test/AllTests.rb 16 Oct 2006 22:00:51 -0000 > @@ -2 +2,2 @@ require 'TestParse.rb' > require 'TestInline.rb' > +require 'TestToHtml.rb' -- Wybo