diff options
author | dave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-31 05:12:37 +0000 |
---|---|---|
committer | dave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-31 05:12:37 +0000 |
commit | 0eaf4872a6b30640dfc244d3dba70d467077a10b (patch) | |
tree | 7bdacba1c0ed39bb8d6eef1701155f056d246b0e | |
parent | 07ca1240f2d3b5891be05dd1ac8735f276490ce6 (diff) | |
download | ruby-0eaf4872a6b30640dfc244d3dba70d467077a10b.tar.gz |
Fix problem in ri formatting if heading contains markup
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7692 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/rdoc/markup/simple_markup/to_flow.rb | 2 | ||||
-rw-r--r-- | lib/rdoc/ri/ri_formatter.rb | 39 |
3 files changed, 37 insertions, 9 deletions
@@ -1,3 +1,8 @@ +Fri Dec 31 14:10:43 2004 Dave Thomas <dave@pragprog.com> + + * lib/rdoc/ri/ri_formatter.rb (RI::TextFormatter::display_flow_item): Fix problem + if heading contains formatting. + Fri Dec 31 00:08:02 2004 Tanaka Akira <akr@m17n.org> * configure.in (HAVE_RLIM_T): removed because not used. diff --git a/lib/rdoc/markup/simple_markup/to_flow.rb b/lib/rdoc/markup/simple_markup/to_flow.rb index 401703a72a..048e71abce 100644 --- a/lib/rdoc/markup/simple_markup/to_flow.rb +++ b/lib/rdoc/markup/simple_markup/to_flow.rb @@ -113,7 +113,7 @@ module SM end def accept_heading(am, fragment) - @res << Flow::H.new(fragment.head_level, am.flow(fragment.txt)) + @res << Flow::H.new(fragment.head_level, convert_flow(am.flow(fragment.txt))) end diff --git a/lib/rdoc/ri/ri_formatter.rb b/lib/rdoc/ri/ri_formatter.rb index 25bd3000f9..56a1fb4665 100644 --- a/lib/rdoc/ri/ri_formatter.rb +++ b/lib/rdoc/ri/ri_formatter.rb @@ -164,7 +164,7 @@ module RI display_verbatim_flow_item(item, @indent) when SM::Flow::H - display_heading(conv_html(item.text.join), item.level, @indent) + display_heading(conv_html(item.text), item.level, @indent) when SM::Flow::RULE draw_line @@ -186,6 +186,7 @@ module RI ###################################################################### def display_heading(text, level, indent) + text = strip_attributes(text) case level when 1 ul = "=" * text.length @@ -211,13 +212,30 @@ module RI display_flow_item(f) end end + + def strip_attributes(txt) + tokens = txt.split(%r{(</?(?:b|code|em|i|tt)>)}) + text = [] + attributes = 0 + tokens.each do |tok| + case tok + when %r{^</(\w+)>$}, %r{^<(\w+)>$} + ; + else + text << tok + end + end + text.join + end + + end ###################################################################### # Handle text with attributes. We're a base class: there are # different presentation classes (one, for example, uses overstrikes - # to handle bold and underlinig, while another using ANSI escape + # to handle bold and underlining, while another using ANSI escape # sequences class AttributeFormatter < TextFormatter @@ -247,6 +265,8 @@ module RI class AttributeString + attr_reader :txt + def initialize @txt = [] @optr = 0 @@ -345,7 +365,7 @@ module RI ################################################## # This formatter generates overstrike-style formatting, which - # works with pages such as man and less. + # works with pagers such as man and less. class OverstrikeFormatter < AttributeFormatter @@ -408,16 +428,18 @@ module RI end HEADINGS = { - 1 => "\033[1;32m%s\033[m", - 2 => "\033[4;32m%s\033[m", - 3 => "\033[32m%s\033[m" + 1 => [ "\033[1;32m", "\033[m" ] , + 2 => ["\033[4;32m", "\033[m" ], + 3 => ["\033[32m", "\033[m" ] } def display_heading(text, level, indent) level = 3 if level > 3 + heading = HEADINGS[level] print indent - printf(HEADINGS[level], text) - puts + print heading[0] + print strip_attributes(text) + puts heading[1] end private @@ -611,6 +633,7 @@ module RI # Place heading level indicators inline with heading. def display_heading(text, level, indent) + text = strip_attributes(text) case level when 1 puts "= " + text.upcase |