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
This commit is contained in:
dave 2004-12-31 05:12:37 +00:00
parent 07ca1240f2
commit 0eaf4872a6
3 changed files with 37 additions and 9 deletions

View File

@ -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.

View File

@ -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

View File

@ -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