2008-01-08 05:18:41 -05:00
|
|
|
require 'rdoc/ri'
|
2008-01-18 19:06:19 -05:00
|
|
|
require 'rdoc/markup'
|
2008-01-08 05:18:41 -05:00
|
|
|
|
|
|
|
class RDoc::RI::Formatter
|
|
|
|
|
|
|
|
attr_reader :indent
|
|
|
|
|
2008-01-18 19:06:19 -05:00
|
|
|
FORMATTERS = { }
|
|
|
|
|
|
|
|
def self.for(name)
|
|
|
|
FORMATTERS[name.downcase]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.list
|
|
|
|
FORMATTERS.keys.sort.join ", "
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(output, width, indent)
|
|
|
|
@output = output
|
|
|
|
@width = width
|
|
|
|
@indent = indent
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def draw_line(label=nil)
|
|
|
|
len = @width
|
2008-01-18 19:06:19 -05:00
|
|
|
len -= (label.size + 1) if label
|
|
|
|
|
|
|
|
if len > 0 then
|
|
|
|
@output.print '-' * len
|
|
|
|
if label
|
|
|
|
@output.print ' '
|
|
|
|
bold_print label
|
|
|
|
end
|
|
|
|
|
|
|
|
@output.puts
|
|
|
|
else
|
|
|
|
@output.print '-' * @width
|
|
|
|
@output.puts
|
|
|
|
|
|
|
|
@output.puts label
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-01-18 19:06:19 -05:00
|
|
|
def wrap(txt, prefix=@indent, linelen=@width)
|
2008-01-08 05:18:41 -05:00
|
|
|
return unless txt && !txt.empty?
|
2008-01-18 19:06:19 -05:00
|
|
|
|
2008-01-08 05:18:41 -05:00
|
|
|
work = conv_markup(txt)
|
|
|
|
textLen = linelen - prefix.length
|
|
|
|
patt = Regexp.new("^(.{0,#{textLen}})[ \n]")
|
|
|
|
next_prefix = prefix.tr("^ ", " ")
|
|
|
|
|
|
|
|
res = []
|
|
|
|
|
|
|
|
while work.length > textLen
|
|
|
|
if work =~ patt
|
|
|
|
res << $1
|
|
|
|
work.slice!(0, $&.length)
|
|
|
|
else
|
|
|
|
res << work.slice!(0, textLen)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
res << work if work.length.nonzero?
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts(prefix + res.join("\n" + next_prefix))
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def blankline
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
2008-01-15 20:36:19 -05:00
|
|
|
##
|
|
|
|
# Called when we want to ensure a new 'wrap' starts on a newline. Only
|
|
|
|
# needed for HtmlFormatter, because the rest do their own line breaking.
|
2008-01-08 05:18:41 -05:00
|
|
|
|
|
|
|
def break_to_newline
|
|
|
|
end
|
|
|
|
|
|
|
|
def bold_print(txt)
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print txt
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def raw_print_line(txt)
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts txt
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
2008-01-15 20:36:19 -05:00
|
|
|
##
|
|
|
|
# Convert HTML entities back to ASCII
|
2008-01-08 05:18:41 -05:00
|
|
|
|
|
|
|
def conv_html(txt)
|
|
|
|
txt.
|
|
|
|
gsub(/>/, '>').
|
|
|
|
gsub(/</, '<').
|
|
|
|
gsub(/"/, '"').
|
|
|
|
gsub(/&/, '&')
|
|
|
|
end
|
|
|
|
|
2008-01-15 20:36:19 -05:00
|
|
|
##
|
|
|
|
# Convert markup into display form
|
|
|
|
|
2008-01-08 05:18:41 -05:00
|
|
|
def conv_markup(txt)
|
|
|
|
txt.
|
|
|
|
gsub(%r{<tt>(.*?)</tt>}) { "+#$1+" } .
|
2008-01-18 19:06:19 -05:00
|
|
|
gsub(%r{<code>(.*?)</code>}) { "+#$1+" } .
|
|
|
|
gsub(%r{<b>(.*?)</b>}) { "*#$1*" } .
|
|
|
|
gsub(%r{<em>(.*?)</em>}) { "_#$1_" }
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def display_list(list)
|
|
|
|
case list.type
|
2008-01-18 19:06:19 -05:00
|
|
|
when :BULLET
|
2008-01-08 05:18:41 -05:00
|
|
|
prefixer = proc { |ignored| @indent + "* " }
|
|
|
|
|
2008-01-18 19:06:19 -05:00
|
|
|
when :NUMBER, :UPPERALPHA, :LOWERALPHA then
|
2008-01-08 05:18:41 -05:00
|
|
|
|
|
|
|
start = case list.type
|
2008-01-18 19:06:19 -05:00
|
|
|
when :NUMBER then 1
|
|
|
|
when :UPPERALPHA then 'A'
|
|
|
|
when :LOWERALPHA then 'a'
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
prefixer = proc do |ignored|
|
|
|
|
res = @indent + "#{start}.".ljust(4)
|
|
|
|
start = start.succ
|
|
|
|
res
|
|
|
|
end
|
|
|
|
|
2008-01-18 19:06:19 -05:00
|
|
|
when :LABELED then
|
2008-01-08 05:18:41 -05:00
|
|
|
prefixer = proc do |li|
|
|
|
|
li.label
|
|
|
|
end
|
|
|
|
|
2008-01-18 19:06:19 -05:00
|
|
|
when :NOTE then
|
2008-01-08 05:18:41 -05:00
|
|
|
longest = 0
|
|
|
|
list.contents.each do |item|
|
2008-01-13 22:34:05 -05:00
|
|
|
if item.kind_of?(RDoc::Markup::Flow::LI) && item.label.length > longest
|
2008-01-08 05:18:41 -05:00
|
|
|
longest = item.label.length
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
prefixer = proc do |li|
|
|
|
|
@indent + li.label.ljust(longest+1)
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
2008-01-18 19:06:19 -05:00
|
|
|
raise ArgumentError, "unknown list type #{list.type}"
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
list.contents.each do |item|
|
2008-01-13 22:34:05 -05:00
|
|
|
if item.kind_of? RDoc::Markup::Flow::LI
|
2008-01-08 05:18:41 -05:00
|
|
|
prefix = prefixer.call(item)
|
|
|
|
display_flow_item(item, prefix)
|
|
|
|
else
|
|
|
|
display_flow_item(item)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_flow_item(item, prefix=@indent)
|
|
|
|
case item
|
2008-01-13 22:34:05 -05:00
|
|
|
when RDoc::Markup::Flow::P, RDoc::Markup::Flow::LI
|
2008-01-08 05:18:41 -05:00
|
|
|
wrap(conv_html(item.body), prefix)
|
|
|
|
blankline
|
|
|
|
|
2008-01-13 22:34:05 -05:00
|
|
|
when RDoc::Markup::Flow::LIST
|
2008-01-08 05:18:41 -05:00
|
|
|
display_list(item)
|
|
|
|
|
2008-01-13 22:34:05 -05:00
|
|
|
when RDoc::Markup::Flow::VERB
|
2008-01-08 05:18:41 -05:00
|
|
|
display_verbatim_flow_item(item, @indent)
|
|
|
|
|
2008-01-13 22:34:05 -05:00
|
|
|
when RDoc::Markup::Flow::H
|
2008-01-08 05:18:41 -05:00
|
|
|
display_heading(conv_html(item.text), item.level, @indent)
|
|
|
|
|
2008-01-13 22:34:05 -05:00
|
|
|
when RDoc::Markup::Flow::RULE
|
2008-01-08 05:18:41 -05:00
|
|
|
draw_line
|
|
|
|
|
|
|
|
else
|
|
|
|
fail "Unknown flow element: #{item.class}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_verbatim_flow_item(item, prefix=@indent)
|
|
|
|
item.body.split(/\n/).each do |line|
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print @indent, conv_html(line), "\n"
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
blankline
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_heading(text, level, indent)
|
|
|
|
text = strip_attributes(text)
|
|
|
|
case level
|
|
|
|
when 1
|
|
|
|
ul = "=" * text.length
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts
|
|
|
|
@output.puts text.upcase
|
|
|
|
@output.puts ul
|
2008-01-08 05:18:41 -05:00
|
|
|
# puts
|
|
|
|
|
|
|
|
when 2
|
|
|
|
ul = "-" * text.length
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts
|
|
|
|
@output.puts text
|
|
|
|
@output.puts ul
|
2008-01-08 05:18:41 -05:00
|
|
|
# puts
|
|
|
|
else
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print indent, text, "\n"
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def display_flow(flow)
|
|
|
|
flow.each do |f|
|
|
|
|
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
|
|
|
|
# underlining, while another using ANSI escape sequences.
|
|
|
|
|
|
|
|
class RDoc::RI::AttributeFormatter < RDoc::RI::Formatter
|
|
|
|
|
|
|
|
BOLD = 1
|
|
|
|
ITALIC = 2
|
|
|
|
CODE = 4
|
|
|
|
|
|
|
|
ATTR_MAP = {
|
|
|
|
"b" => BOLD,
|
|
|
|
"code" => CODE,
|
|
|
|
"em" => ITALIC,
|
|
|
|
"i" => ITALIC,
|
|
|
|
"tt" => CODE
|
|
|
|
}
|
|
|
|
|
|
|
|
# TODO: struct?
|
|
|
|
class AttrChar
|
|
|
|
attr_reader :char
|
|
|
|
attr_reader :attr
|
|
|
|
|
|
|
|
def initialize(char, attr)
|
|
|
|
@char = char
|
|
|
|
@attr = attr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class AttributeString
|
|
|
|
attr_reader :txt
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@txt = []
|
|
|
|
@optr = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def <<(char)
|
|
|
|
@txt << char
|
|
|
|
end
|
|
|
|
|
|
|
|
def empty?
|
|
|
|
@optr >= @txt.length
|
|
|
|
end
|
|
|
|
|
|
|
|
# accept non space, then all following spaces
|
|
|
|
def next_word
|
|
|
|
start = @optr
|
|
|
|
len = @txt.length
|
|
|
|
|
|
|
|
while @optr < len && @txt[@optr].char != " "
|
|
|
|
@optr += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
while @optr < len && @txt[@optr].char == " "
|
|
|
|
@optr += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
@txt[start...@optr]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2008-01-18 19:06:19 -05:00
|
|
|
# Overrides base class. Looks for <tt>...</tt> etc sequences and generates
|
|
|
|
# an array of AttrChars. This array is then used as the basis for the
|
|
|
|
# split.
|
2008-01-08 05:18:41 -05:00
|
|
|
|
2008-01-18 19:06:19 -05:00
|
|
|
def wrap(txt, prefix=@indent, linelen=@width)
|
2008-01-08 05:18:41 -05:00
|
|
|
return unless txt && !txt.empty?
|
|
|
|
|
|
|
|
txt = add_attributes_to(txt)
|
|
|
|
next_prefix = prefix.tr("^ ", " ")
|
|
|
|
linelen -= prefix.size
|
|
|
|
|
|
|
|
line = []
|
|
|
|
|
|
|
|
until txt.empty?
|
|
|
|
word = txt.next_word
|
|
|
|
if word.size + line.size > linelen
|
|
|
|
write_attribute_text(prefix, line)
|
|
|
|
prefix = next_prefix
|
|
|
|
line = []
|
|
|
|
end
|
|
|
|
line.concat(word)
|
|
|
|
end
|
|
|
|
|
|
|
|
write_attribute_text(prefix, line) if line.length > 0
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def write_attribute_text(prefix, line)
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print prefix
|
2008-01-08 05:18:41 -05:00
|
|
|
line.each do |achar|
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print achar.char
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def bold_print(txt)
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print txt
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def add_attributes_to(txt)
|
|
|
|
tokens = txt.split(%r{(</?(?:b|code|em|i|tt)>)})
|
|
|
|
text = AttributeString.new
|
|
|
|
attributes = 0
|
|
|
|
tokens.each do |tok|
|
|
|
|
case tok
|
|
|
|
when %r{^</(\w+)>$} then attributes &= ~(ATTR_MAP[$1]||0)
|
|
|
|
when %r{^<(\w+)>$} then attributes |= (ATTR_MAP[$1]||0)
|
|
|
|
else
|
|
|
|
tok.split(//).each {|ch| text << AttrChar.new(ch, attributes)}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
text
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# This formatter generates overstrike-style formatting, which works with
|
|
|
|
# pagers such as man and less.
|
|
|
|
|
|
|
|
class RDoc::RI::OverstrikeFormatter < RDoc::RI::AttributeFormatter
|
|
|
|
|
|
|
|
BS = "\C-h"
|
|
|
|
|
|
|
|
def write_attribute_text(prefix, line)
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print prefix
|
2008-01-08 05:18:41 -05:00
|
|
|
line.each do |achar|
|
|
|
|
attr = achar.attr
|
|
|
|
if (attr & (ITALIC+CODE)) != 0
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print "_", BS
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
if (attr & BOLD) != 0
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print achar.char, BS
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print achar.char
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2008-01-15 20:36:19 -05:00
|
|
|
# Draw a string in bold
|
2008-01-08 05:18:41 -05:00
|
|
|
|
|
|
|
def bold_print(text)
|
|
|
|
text.split(//).each do |ch|
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print ch, BS, ch
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# This formatter uses ANSI escape sequences to colorize stuff works with
|
|
|
|
# pagers such as man and less.
|
|
|
|
|
|
|
|
class RDoc::RI::AnsiFormatter < RDoc::RI::AttributeFormatter
|
|
|
|
|
|
|
|
def initialize(*args)
|
|
|
|
super
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print "\033[0m"
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def write_attribute_text(prefix, line)
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print prefix
|
2008-01-08 05:18:41 -05:00
|
|
|
curr_attr = 0
|
|
|
|
line.each do |achar|
|
|
|
|
attr = achar.attr
|
|
|
|
if achar.attr != curr_attr
|
|
|
|
update_attributes(achar.attr)
|
|
|
|
curr_attr = achar.attr
|
|
|
|
end
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print achar.char
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
update_attributes(0) unless curr_attr.zero?
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def bold_print(txt)
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print "\033[1m#{txt}\033[m"
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
HEADINGS = {
|
|
|
|
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]
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print indent
|
|
|
|
@output.print heading[0]
|
|
|
|
@output.print strip_attributes(text)
|
|
|
|
@output.puts heading[1]
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
ATTR_MAP = {
|
|
|
|
BOLD => "1",
|
|
|
|
ITALIC => "33",
|
|
|
|
CODE => "36"
|
|
|
|
}
|
|
|
|
|
|
|
|
def update_attributes(attr)
|
|
|
|
str = "\033["
|
|
|
|
for quality in [ BOLD, ITALIC, CODE]
|
|
|
|
unless (attr & quality).zero?
|
|
|
|
str << ATTR_MAP[quality]
|
|
|
|
end
|
|
|
|
end
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print str, "m"
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# This formatter uses HTML.
|
|
|
|
|
|
|
|
class RDoc::RI::HtmlFormatter < RDoc::RI::AttributeFormatter
|
|
|
|
|
|
|
|
def write_attribute_text(prefix, line)
|
|
|
|
curr_attr = 0
|
|
|
|
line.each do |achar|
|
|
|
|
attr = achar.attr
|
|
|
|
if achar.attr != curr_attr
|
|
|
|
update_attributes(curr_attr, achar.attr)
|
|
|
|
curr_attr = achar.attr
|
|
|
|
end
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print(escape(achar.char))
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
update_attributes(curr_attr, 0) unless curr_attr.zero?
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw_line(label=nil)
|
|
|
|
if label != nil
|
|
|
|
bold_print(label)
|
|
|
|
end
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts("<hr>")
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def bold_print(txt)
|
|
|
|
tag("b") { txt }
|
|
|
|
end
|
|
|
|
|
|
|
|
def blankline()
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts("<p>")
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def break_to_newline
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts("<br>")
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def display_heading(text, level, indent)
|
|
|
|
level = 4 if level > 4
|
|
|
|
tag("h#{level}") { text }
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def display_list(list)
|
|
|
|
case list.type
|
2008-01-18 19:06:19 -05:00
|
|
|
when :BULLET then
|
2008-01-08 05:18:41 -05:00
|
|
|
list_type = "ul"
|
|
|
|
prefixer = proc { |ignored| "<li>" }
|
|
|
|
|
2008-01-18 19:06:19 -05:00
|
|
|
when :NUMBER, :UPPERALPHA, :LOWERALPHA then
|
2008-01-08 05:18:41 -05:00
|
|
|
list_type = "ol"
|
|
|
|
prefixer = proc { |ignored| "<li>" }
|
|
|
|
|
2008-01-18 19:06:19 -05:00
|
|
|
when :LABELED then
|
2008-01-08 05:18:41 -05:00
|
|
|
list_type = "dl"
|
|
|
|
prefixer = proc do |li|
|
|
|
|
"<dt><b>" + escape(li.label) + "</b><dd>"
|
|
|
|
end
|
|
|
|
|
2008-01-18 19:06:19 -05:00
|
|
|
when :NOTE then
|
2008-01-08 05:18:41 -05:00
|
|
|
list_type = "table"
|
|
|
|
prefixer = proc do |li|
|
|
|
|
%{<tr valign="top"><td>#{li.label.gsub(/ /, ' ')}</td><td>}
|
|
|
|
end
|
|
|
|
else
|
|
|
|
fail "unknown list type"
|
|
|
|
end
|
|
|
|
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print "<#{list_type}>"
|
2008-01-08 05:18:41 -05:00
|
|
|
list.contents.each do |item|
|
2008-01-13 22:34:05 -05:00
|
|
|
if item.kind_of? RDoc::Markup::Flow::LI
|
2008-01-08 05:18:41 -05:00
|
|
|
prefix = prefixer.call(item)
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print prefix
|
2008-01-08 05:18:41 -05:00
|
|
|
display_flow_item(item, prefix)
|
|
|
|
else
|
|
|
|
display_flow_item(item)
|
|
|
|
end
|
|
|
|
end
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print "</#{list_type}>"
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def display_verbatim_flow_item(item, prefix=@indent)
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print("<pre>")
|
2008-01-08 05:18:41 -05:00
|
|
|
item.body.split(/\n/).each do |line|
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts conv_html(line)
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts("</pre>")
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
ATTR_MAP = {
|
|
|
|
BOLD => "b>",
|
|
|
|
ITALIC => "i>",
|
|
|
|
CODE => "tt>"
|
|
|
|
}
|
|
|
|
|
|
|
|
def update_attributes(current, wanted)
|
|
|
|
str = ""
|
|
|
|
# first turn off unwanted ones
|
|
|
|
off = current & ~wanted
|
|
|
|
for quality in [ BOLD, ITALIC, CODE]
|
|
|
|
if (off & quality) > 0
|
|
|
|
str << "</" + ATTR_MAP[quality]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# now turn on wanted
|
|
|
|
for quality in [ BOLD, ITALIC, CODE]
|
|
|
|
unless (wanted & quality).zero?
|
|
|
|
str << "<" << ATTR_MAP[quality]
|
|
|
|
end
|
|
|
|
end
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print str
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def tag(code)
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print("<#{code}>")
|
|
|
|
@output.print(yield)
|
|
|
|
@output.print("</#{code}>")
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def escape(str)
|
|
|
|
str.
|
|
|
|
gsub(/&/n, '&').
|
|
|
|
gsub(/\"/n, '"').
|
|
|
|
gsub(/>/n, '>').
|
|
|
|
gsub(/</n, '<')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# This formatter reduces extra lines for a simpler output. It improves way
|
|
|
|
# output looks for tools like IRC bots.
|
|
|
|
|
|
|
|
class RDoc::RI::SimpleFormatter < RDoc::RI::Formatter
|
|
|
|
|
|
|
|
##
|
|
|
|
# No extra blank lines
|
|
|
|
|
|
|
|
def blankline
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Display labels only, no lines
|
|
|
|
|
|
|
|
def draw_line(label=nil)
|
|
|
|
unless label.nil? then
|
|
|
|
bold_print(label)
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Place heading level indicators inline with heading.
|
|
|
|
|
|
|
|
def display_heading(text, level, indent)
|
|
|
|
text = strip_attributes(text)
|
|
|
|
case level
|
|
|
|
when 1
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts "= " + text.upcase
|
2008-01-08 05:18:41 -05:00
|
|
|
when 2
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.puts "-- " + text
|
2008-01-08 05:18:41 -05:00
|
|
|
else
|
2008-01-18 19:06:19 -05:00
|
|
|
@output.print indent, text, "\n"
|
2008-01-08 05:18:41 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2008-01-18 19:06:19 -05:00
|
|
|
RDoc::RI::Formatter::FORMATTERS['plain'] = RDoc::RI::Formatter
|
|
|
|
RDoc::RI::Formatter::FORMATTERS['simple'] = RDoc::RI::SimpleFormatter
|
|
|
|
RDoc::RI::Formatter::FORMATTERS['bs'] = RDoc::RI::OverstrikeFormatter
|
|
|
|
RDoc::RI::Formatter::FORMATTERS['ansi'] = RDoc::RI::AnsiFormatter
|
|
|
|
RDoc::RI::Formatter::FORMATTERS['html'] = RDoc::RI::HtmlFormatter
|