1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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> Fri Dec 31 00:08:02 2004 Tanaka Akira <akr@m17n.org>
* configure.in (HAVE_RLIM_T): removed because not used. * configure.in (HAVE_RLIM_T): removed because not used.

View file

@ -113,7 +113,7 @@ module SM
end end
def accept_heading(am, fragment) 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 end

View file

@ -164,7 +164,7 @@ module RI
display_verbatim_flow_item(item, @indent) display_verbatim_flow_item(item, @indent)
when SM::Flow::H 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 when SM::Flow::RULE
draw_line draw_line
@ -186,6 +186,7 @@ module RI
###################################################################### ######################################################################
def display_heading(text, level, indent) def display_heading(text, level, indent)
text = strip_attributes(text)
case level case level
when 1 when 1
ul = "=" * text.length ul = "=" * text.length
@ -211,13 +212,30 @@ module RI
display_flow_item(f) display_flow_item(f)
end end
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 end
###################################################################### ######################################################################
# Handle text with attributes. We're a base class: there are # Handle text with attributes. We're a base class: there are
# different presentation classes (one, for example, uses overstrikes # 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 # sequences
class AttributeFormatter < TextFormatter class AttributeFormatter < TextFormatter
@ -247,6 +265,8 @@ module RI
class AttributeString class AttributeString
attr_reader :txt
def initialize def initialize
@txt = [] @txt = []
@optr = 0 @optr = 0
@ -345,7 +365,7 @@ module RI
################################################## ##################################################
# This formatter generates overstrike-style formatting, which # 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 class OverstrikeFormatter < AttributeFormatter
@ -408,16 +428,18 @@ module RI
end end
HEADINGS = { HEADINGS = {
1 => "\033[1;32m%s\033[m", 1 => [ "\033[1;32m", "\033[m" ] ,
2 => "\033[4;32m%s\033[m", 2 => ["\033[4;32m", "\033[m" ],
3 => "\033[32m%s\033[m" 3 => ["\033[32m", "\033[m" ]
} }
def display_heading(text, level, indent) def display_heading(text, level, indent)
level = 3 if level > 3 level = 3 if level > 3
heading = HEADINGS[level]
print indent print indent
printf(HEADINGS[level], text) print heading[0]
puts print strip_attributes(text)
puts heading[1]
end end
private private
@ -611,6 +633,7 @@ module RI
# Place heading level indicators inline with heading. # Place heading level indicators inline with heading.
def display_heading(text, level, indent) def display_heading(text, level, indent)
text = strip_attributes(text)
case level case level
when 1 when 1
puts "= " + text.upcase puts "= " + text.upcase