rdoc 2.5.11 → 3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rdoc might be problematic. Click here for more details.
- data.tar.gz.sig +0 -0
- data/.document +1 -0
- data/History.txt +95 -0
- data/Manifest.txt +13 -4
- data/README.txt +9 -3
- data/Rakefile +1 -1
- data/lib/rdoc.rb +15 -298
- data/lib/rdoc/alias.rb +65 -16
- data/lib/rdoc/any_method.rb +27 -150
- data/lib/rdoc/attr.rb +36 -115
- data/lib/rdoc/class_module.rb +236 -22
- data/lib/rdoc/code_object.rb +76 -31
- data/lib/rdoc/constant.rb +32 -4
- data/lib/rdoc/context.rb +494 -222
- data/lib/rdoc/encoding.rb +79 -0
- data/lib/rdoc/erbio.rb +37 -0
- data/lib/rdoc/gauntlet.rb +9 -5
- data/lib/rdoc/generator.rb +33 -1
- data/lib/rdoc/generator/darkfish.rb +284 -375
- data/lib/rdoc/generator/markup.rb +72 -36
- data/lib/rdoc/generator/ri.rb +4 -4
- data/lib/rdoc/generator/template/darkfish/classpage.rhtml +267 -274
- data/lib/rdoc/generator/template/darkfish/filepage.rhtml +91 -91
- data/lib/rdoc/generator/template/darkfish/index.rhtml +45 -45
- data/lib/rdoc/generator/template/darkfish/rdoc.css +298 -298
- data/lib/rdoc/include.rb +40 -1
- data/lib/rdoc/known_classes.rb +1 -0
- data/lib/rdoc/markup.rb +467 -2
- data/lib/rdoc/markup/attribute_manager.rb +24 -6
- data/lib/rdoc/markup/blank_line.rb +11 -3
- data/lib/rdoc/markup/document.rb +6 -0
- data/lib/rdoc/markup/formatter.rb +10 -0
- data/lib/rdoc/markup/formatter_test_case.rb +339 -3
- data/lib/rdoc/markup/heading.rb +3 -0
- data/lib/rdoc/markup/inline.rb +11 -1
- data/lib/rdoc/markup/list.rb +3 -0
- data/lib/rdoc/markup/list_item.rb +3 -0
- data/lib/rdoc/markup/paragraph.rb +3 -0
- data/lib/rdoc/markup/parser.rb +191 -237
- data/lib/rdoc/markup/{preprocess.rb → pre_process.rb} +50 -29
- data/lib/rdoc/markup/raw.rb +4 -0
- data/lib/rdoc/markup/rule.rb +3 -0
- data/lib/rdoc/markup/text_formatter_test_case.rb +116 -0
- data/lib/rdoc/markup/to_ansi.rb +14 -2
- data/lib/rdoc/markup/to_bs.rb +8 -2
- data/lib/rdoc/markup/to_html.rb +84 -91
- data/lib/rdoc/markup/to_html_crossref.rb +77 -26
- data/lib/rdoc/markup/to_rdoc.rb +94 -49
- data/lib/rdoc/markup/to_test.rb +9 -1
- data/lib/rdoc/markup/verbatim.rb +6 -3
- data/lib/rdoc/method_attr.rb +353 -0
- data/lib/rdoc/normal_class.rb +11 -2
- data/lib/rdoc/normal_module.rb +0 -5
- data/lib/rdoc/options.rb +373 -82
- data/lib/rdoc/parser.rb +59 -23
- data/lib/rdoc/parser/c.rb +224 -86
- data/lib/rdoc/parser/ruby.rb +219 -111
- data/lib/rdoc/parser/ruby_tools.rb +4 -1
- data/lib/rdoc/parser/simple.rb +9 -4
- data/lib/rdoc/rdoc.rb +68 -28
- data/lib/rdoc/require.rb +21 -0
- data/lib/rdoc/ri/driver.rb +20 -10
- data/lib/rdoc/ri/paths.rb +2 -2
- data/lib/rdoc/ri/store.rb +22 -5
- data/lib/rdoc/ruby_lex.rb +11 -12
- data/lib/rdoc/ruby_token.rb +2 -2
- data/lib/rdoc/single_class.rb +2 -1
- data/lib/rdoc/stats.rb +202 -162
- data/lib/rdoc/stats/normal.rb +51 -0
- data/lib/rdoc/stats/quiet.rb +59 -0
- data/lib/rdoc/stats/verbose.rb +45 -0
- data/lib/rdoc/text.rb +133 -4
- data/lib/rdoc/{tokenstream.rb → token_stream.rb} +0 -2
- data/lib/rdoc/top_level.rb +230 -39
- data/test/test_attribute_manager.rb +58 -7
- data/test/test_rdoc_alias.rb +13 -0
- data/test/test_rdoc_any_method.rb +43 -2
- data/test/test_rdoc_attr.rb +15 -8
- data/test/test_rdoc_class_module.rb +133 -0
- data/test/test_rdoc_code_object.rb +62 -5
- data/test/test_rdoc_context.rb +72 -26
- data/test/test_rdoc_encoding.rb +145 -0
- data/test/test_rdoc_generator_darkfish.rb +119 -0
- data/test/test_rdoc_generator_ri.rb +22 -2
- data/test/test_rdoc_include.rb +79 -0
- data/test/test_rdoc_markup_attribute_manager.rb +4 -4
- data/test/test_rdoc_markup_parser.rb +134 -95
- data/test/test_rdoc_markup_pre_process.rb +7 -2
- data/test/test_rdoc_markup_to_ansi.rb +43 -153
- data/test/test_rdoc_markup_to_bs.rb +42 -156
- data/test/test_rdoc_markup_to_html.rb +130 -58
- data/test/test_rdoc_markup_to_html_crossref.rb +10 -10
- data/test/test_rdoc_markup_to_rdoc.rb +40 -151
- data/test/test_rdoc_method_attr.rb +122 -0
- data/test/test_rdoc_normal_class.rb +1 -1
- data/test/test_rdoc_normal_module.rb +6 -1
- data/test/test_rdoc_options.rb +237 -12
- data/test/test_rdoc_parser.rb +3 -22
- data/test/test_rdoc_parser_c.rb +203 -2
- data/test/test_rdoc_parser_ruby.rb +403 -89
- data/test/test_rdoc_parser_simple.rb +25 -1
- data/test/test_rdoc_rdoc.rb +44 -32
- data/test/test_rdoc_ri_driver.rb +29 -24
- data/test/test_rdoc_ri_store.rb +46 -3
- data/test/test_rdoc_task.rb +1 -1
- data/test/test_rdoc_text.rb +102 -8
- data/test/test_rdoc_top_level.rb +13 -4
- data/test/xref_data.rb +8 -0
- data/test/xref_test_case.rb +6 -0
- metadata +29 -19
- metadata.gz.sig +0 -0
- data/lib/rdoc/parser/perl.rb +0 -165
- data/test/test_rdoc_parser_perl.rb +0 -73
@@ -1,12 +1,15 @@
|
|
1
1
|
require 'rdoc/markup'
|
2
|
+
require 'rdoc/encoding'
|
2
3
|
|
3
4
|
##
|
4
5
|
# Handle common directives that can occur in a block of text:
|
5
6
|
#
|
6
|
-
#
|
7
|
+
# \:include: filename
|
7
8
|
#
|
8
|
-
#
|
9
|
-
#
|
9
|
+
# Directives can be escaped by preceding them with a backslash.
|
10
|
+
#
|
11
|
+
# RDoc plugin authors can register additional directives to be handled by
|
12
|
+
# using RDoc::Markup::PreProcess::register
|
10
13
|
|
11
14
|
class RDoc::Markup::PreProcess
|
12
15
|
|
@@ -52,18 +55,25 @@ class RDoc::Markup::PreProcess
|
|
52
55
|
# +code_object+. See RDoc::CodeObject#metadata
|
53
56
|
|
54
57
|
def handle text, code_object = nil
|
55
|
-
|
56
|
-
|
58
|
+
# regexp helper (square brackets for optional)
|
59
|
+
# $1 $2 $3 $4 $5
|
60
|
+
# [prefix][\]:directive:[spaces][param]newline
|
61
|
+
text.gsub!(/^([ \t]*#?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?\n/) do
|
62
|
+
# skip something like ':toto::'
|
63
|
+
next $& if $4.empty? and $5 and $5[0, 1] == ':'
|
64
|
+
|
65
|
+
# skip if escaped
|
66
|
+
next "#$1:#$3:#$4#$5\n" unless $2.empty?
|
57
67
|
|
58
68
|
prefix = $1
|
59
|
-
directive = $
|
60
|
-
param = $
|
69
|
+
directive = $3.downcase
|
70
|
+
param = $5
|
61
71
|
|
62
72
|
case directive
|
63
73
|
when 'include' then
|
64
74
|
filename = param.split[0]
|
65
|
-
|
66
|
-
|
75
|
+
encoding = if defined?(Encoding) then text.encoding else nil end
|
76
|
+
include_file filename, prefix, encoding
|
67
77
|
else
|
68
78
|
result = yield directive, param if block_given?
|
69
79
|
|
@@ -88,27 +98,38 @@ class RDoc::Markup::PreProcess
|
|
88
98
|
end
|
89
99
|
|
90
100
|
##
|
91
|
-
#
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
else
|
101
|
+
# Handles the <tt>:include: _filename_</tt> directive.
|
102
|
+
#
|
103
|
+
# If the first line of the included file starts with '#', and contains
|
104
|
+
# an encoding information in the form 'coding:' or 'coding=', it is
|
105
|
+
# removed.
|
106
|
+
#
|
107
|
+
# If all lines in the included file start with a '#', this leading '#'
|
108
|
+
# is removed before inclusion. The included content is indented like
|
109
|
+
# the <tt>:include:</tt> directive.
|
110
|
+
#--
|
111
|
+
# so all content will be verbatim because of the likely space after '#'?
|
112
|
+
# TODO shift left the whole file content in that case
|
113
|
+
# TODO comment stop/start #-- and #++ in included file must be processed here
|
114
|
+
|
115
|
+
def include_file name, indent, encoding
|
116
|
+
full_name = find_include_file name
|
117
|
+
|
118
|
+
unless full_name then
|
110
119
|
warn "Couldn't find file to include '#{name}' from #{@input_file_name}"
|
111
|
-
''
|
120
|
+
return ''
|
121
|
+
end
|
122
|
+
|
123
|
+
content = RDoc::Encoding.read_file full_name, encoding
|
124
|
+
|
125
|
+
# strip magic comment
|
126
|
+
content = content.sub(/\A# .*coding[=:].*$/, '').lstrip
|
127
|
+
|
128
|
+
# strip leading '#'s, but only if all lines start with them
|
129
|
+
if content =~ /^[^#]/ then
|
130
|
+
content.gsub(/^/, indent)
|
131
|
+
else
|
132
|
+
content.gsub(/^#?/, indent)
|
112
133
|
end
|
113
134
|
end
|
114
135
|
|
data/lib/rdoc/markup/raw.rb
CHANGED
@@ -27,6 +27,9 @@ class RDoc::Markup::Raw
|
|
27
27
|
self.class == other.class and text == other.text
|
28
28
|
end
|
29
29
|
|
30
|
+
##
|
31
|
+
# Calls #accept_raw+ on +visitor+
|
32
|
+
|
30
33
|
def accept visitor
|
31
34
|
visitor.accept_raw self
|
32
35
|
end
|
@@ -63,3 +66,4 @@ class RDoc::Markup::Raw
|
|
63
66
|
end
|
64
67
|
|
65
68
|
end
|
69
|
+
|
data/lib/rdoc/markup/rule.rb
CHANGED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'rdoc/markup/formatter_test_case'
|
2
|
+
|
3
|
+
##
|
4
|
+
# Test case for creating new plain-text RDoc::Markup formatters. See also
|
5
|
+
# RDoc::Markup::FormatterTestCase
|
6
|
+
#
|
7
|
+
# See test_rdoc_markup_to_rdoc.rb for a complete example.
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
#
|
11
|
+
# class TestRDocMarkupToNewTextFormat < RDoc::Markup::TextFormatterTestCase
|
12
|
+
#
|
13
|
+
# add_visitor_tests
|
14
|
+
# add_text_tests
|
15
|
+
#
|
16
|
+
# def setup
|
17
|
+
# super
|
18
|
+
#
|
19
|
+
# @to = RDoc::Markup::ToNewTextFormat.new
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# def accept_blank_line
|
23
|
+
# assert_equal :junk, @to.res.join
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# # ...
|
27
|
+
#
|
28
|
+
# end
|
29
|
+
|
30
|
+
class RDoc::Markup::TextFormatterTestCase < RDoc::Markup::FormatterTestCase
|
31
|
+
|
32
|
+
##
|
33
|
+
# Adds test cases to the calling TestCase.
|
34
|
+
|
35
|
+
def self.add_text_tests
|
36
|
+
self.class_eval do
|
37
|
+
|
38
|
+
##
|
39
|
+
# Test case that calls <tt>@to.accept_heading</tt>
|
40
|
+
|
41
|
+
def test_accept_heading_indent
|
42
|
+
@to.start_accepting
|
43
|
+
@to.indent = 3
|
44
|
+
@to.accept_heading @RM::Heading.new(1, 'Hello')
|
45
|
+
|
46
|
+
accept_heading_indent
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Test case that calls <tt>@to.accept_rule</tt>
|
51
|
+
|
52
|
+
def test_accept_rule_indent
|
53
|
+
@to.start_accepting
|
54
|
+
@to.indent = 3
|
55
|
+
@to.accept_rule @RM::Rule.new(1)
|
56
|
+
|
57
|
+
accept_rule_indent
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Test case that calls <tt>@to.accept_verbatim</tt>
|
62
|
+
|
63
|
+
def test_accept_verbatim_indent
|
64
|
+
@to.start_accepting
|
65
|
+
@to.indent = 2
|
66
|
+
@to.accept_verbatim @RM::Verbatim.new("hi\n", " world\n")
|
67
|
+
|
68
|
+
accept_verbatim_indent
|
69
|
+
end
|
70
|
+
|
71
|
+
##
|
72
|
+
# Test case that calls <tt>@to.accept_verbatim</tt> with a big indent
|
73
|
+
|
74
|
+
def test_accept_verbatim_big_indent
|
75
|
+
@to.start_accepting
|
76
|
+
@to.indent = 2
|
77
|
+
@to.accept_verbatim @RM::Verbatim.new("hi\n", "world\n")
|
78
|
+
|
79
|
+
accept_verbatim_big_indent
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# Test case that calls <tt>@to.accept_paragraph</tt> with an indent
|
84
|
+
|
85
|
+
def test_accept_paragraph_indent
|
86
|
+
@to.start_accepting
|
87
|
+
@to.indent = 3
|
88
|
+
@to.accept_paragraph @RM::Paragraph.new(('words ' * 30).strip)
|
89
|
+
|
90
|
+
accept_paragraph_indent
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Test case that calls <tt>@to.accept_paragraph</tt> with a long line
|
95
|
+
|
96
|
+
def test_accept_paragraph_wrap
|
97
|
+
@to.start_accepting
|
98
|
+
@to.accept_paragraph @RM::Paragraph.new(('words ' * 30).strip)
|
99
|
+
|
100
|
+
accept_paragraph_wrap
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Test case that calls <tt>@to.attributes</tt> with an escaped
|
105
|
+
# cross-reference. If this test doesn't pass something may be very
|
106
|
+
# wrong.
|
107
|
+
|
108
|
+
def test_attributes
|
109
|
+
assert_equal 'Dog', @to.attributes("\\Dog")
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
data/lib/rdoc/markup/to_ansi.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
require 'rdoc/markup/
|
1
|
+
require 'rdoc/markup/to_rdoc'
|
2
2
|
|
3
3
|
##
|
4
4
|
# Outputs RDoc markup with vibrant ANSI color!
|
5
5
|
|
6
6
|
class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
|
7
7
|
|
8
|
+
##
|
9
|
+
# Creates a new ToAnsi visitor that is ready to output vibrant ANSI color!
|
10
|
+
|
8
11
|
def initialize
|
9
12
|
super
|
10
13
|
|
@@ -23,12 +26,15 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
|
|
23
26
|
add_tag :EM, "\e[4m", "\e[m"
|
24
27
|
end
|
25
28
|
|
29
|
+
##
|
30
|
+
# Overrides indent width to ensure output lines up correctly.
|
31
|
+
|
26
32
|
def accept_list_item_end list_item
|
27
33
|
width = case @list_type.last
|
28
34
|
when :BULLET then
|
29
35
|
2
|
30
36
|
when :NOTE, :LABEL then
|
31
|
-
@res << "\n"
|
37
|
+
@res << "\n" unless res.length == 1
|
32
38
|
2
|
33
39
|
else
|
34
40
|
bullet = @list_index.last.to_s
|
@@ -39,6 +45,9 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
|
|
39
45
|
@indent -= width
|
40
46
|
end
|
41
47
|
|
48
|
+
##
|
49
|
+
# Adds coloring to note and label list items
|
50
|
+
|
42
51
|
def accept_list_item_start list_item
|
43
52
|
bullet = case @list_type.last
|
44
53
|
when :BULLET then
|
@@ -62,6 +71,9 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
|
|
62
71
|
end
|
63
72
|
end
|
64
73
|
|
74
|
+
##
|
75
|
+
# Starts accepting with a reset screen
|
76
|
+
|
65
77
|
def start_accepting
|
66
78
|
super
|
67
79
|
|
data/lib/rdoc/markup/to_bs.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'rdoc/markup/
|
1
|
+
require 'rdoc/markup/to_rdoc'
|
2
2
|
|
3
3
|
##
|
4
4
|
# Outputs RDoc markup with hot backspace action! You will probably need a
|
@@ -8,6 +8,9 @@ require 'rdoc/markup/inline'
|
|
8
8
|
|
9
9
|
class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
|
10
10
|
|
11
|
+
##
|
12
|
+
# Returns a new ToBs that is ready for hot backspace action!
|
13
|
+
|
11
14
|
def initialize
|
12
15
|
super
|
13
16
|
|
@@ -22,8 +25,12 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
|
|
22
25
|
def init_tags
|
23
26
|
add_tag :BOLD, '+b', '-b'
|
24
27
|
add_tag :EM, '+_', '-_'
|
28
|
+
add_tag :TT, '' , '' # we need in_tt information maintained
|
25
29
|
end
|
26
30
|
|
31
|
+
##
|
32
|
+
# Makes heading text bold.
|
33
|
+
|
27
34
|
def accept_heading heading
|
28
35
|
use_prefix or @res << ' ' * @indent
|
29
36
|
@res << @headings[heading.level][0]
|
@@ -44,7 +51,6 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
|
|
44
51
|
when '+_' then @in_em = true
|
45
52
|
when '-_' then @in_em = false
|
46
53
|
end
|
47
|
-
|
48
54
|
''
|
49
55
|
end
|
50
56
|
|
data/lib/rdoc/markup/to_html.rb
CHANGED
@@ -8,6 +8,8 @@ require 'cgi'
|
|
8
8
|
|
9
9
|
class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
10
10
|
|
11
|
+
include RDoc::Text
|
12
|
+
|
11
13
|
##
|
12
14
|
# Maps RDoc::Markup::Parser::LIST_TOKENS types to HTML tags
|
13
15
|
|
@@ -15,7 +17,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
15
17
|
:BULLET => ['<ul>', '</ul>'],
|
16
18
|
:LABEL => ['<dl>', '</dl>'],
|
17
19
|
:LALPHA => ['<ol style="display: lower-alpha">', '</ol>'],
|
18
|
-
:NOTE => ['<table>', '</table>'],
|
20
|
+
:NOTE => ['<table class="rdoc-list">', '</table>'],
|
19
21
|
:NUMBER => ['<ol>', '</ol>'],
|
20
22
|
:UALPHA => ['<ol style="display: upper-alpha">', '</ol>'],
|
21
23
|
}
|
@@ -48,6 +50,9 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
48
50
|
File.join(*from)
|
49
51
|
end
|
50
52
|
|
53
|
+
##
|
54
|
+
# Creates a new formatter that will output HTML
|
55
|
+
|
51
56
|
def initialize
|
52
57
|
super
|
53
58
|
|
@@ -103,13 +108,15 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
103
108
|
end
|
104
109
|
end
|
105
110
|
|
111
|
+
# :section: Special handling
|
112
|
+
|
106
113
|
##
|
107
|
-
# And we're invoked with a potential external hyperlink mailto
|
108
|
-
# just gets inserted. http
|
114
|
+
# And we're invoked with a potential external hyperlink. <tt>mailto:</tt>
|
115
|
+
# just gets inserted. <tt>http:</tt> links are checked to see if they
|
109
116
|
# reference an image. If so, that image gets inserted using an
|
110
|
-
# <img> tag. Otherwise a conventional <a href> is used.
|
111
|
-
# support a special type of hyperlink, link
|
112
|
-
# to a local file whose path is relative to the --op directory.
|
117
|
+
# <tt><img></tt> tag. Otherwise a conventional <tt><a href></tt> is used.
|
118
|
+
# We also support a special type of hyperlink, <tt>link:</tt>, which is a
|
119
|
+
# reference to a local file whose path is relative to the --op directory.
|
113
120
|
|
114
121
|
def handle_special_HYPERLINK(special)
|
115
122
|
url = special.text
|
@@ -118,7 +125,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
118
125
|
|
119
126
|
##
|
120
127
|
# Here's a hypedlink where the label is different to the URL
|
121
|
-
#
|
128
|
+
# <label>[url] or {long label}[url]
|
122
129
|
|
123
130
|
def handle_special_TIDYLINK(special)
|
124
131
|
text = special.text
|
@@ -130,8 +137,10 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
130
137
|
gen_url url, label
|
131
138
|
end
|
132
139
|
|
140
|
+
# :section: Utilities
|
141
|
+
|
133
142
|
##
|
134
|
-
#
|
143
|
+
# Wraps +txt+ to +line_len+
|
135
144
|
|
136
145
|
def wrap(txt, line_len = 76)
|
137
146
|
res = []
|
@@ -159,173 +168,150 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
159
168
|
sp += 1 while sp < ep and txt[sp] == ?\s
|
160
169
|
end
|
161
170
|
|
162
|
-
res.join
|
171
|
+
res.join.strip
|
163
172
|
end
|
164
173
|
|
165
|
-
##
|
166
174
|
# :section: Visitor
|
167
175
|
|
176
|
+
##
|
177
|
+
# Prepares the visitor for HTML generation
|
178
|
+
|
168
179
|
def start_accepting
|
169
180
|
@res = []
|
170
181
|
@in_list_entry = []
|
171
182
|
@list = []
|
172
183
|
end
|
173
184
|
|
185
|
+
##
|
186
|
+
# Returns the generated output
|
187
|
+
|
174
188
|
def end_accepting
|
175
189
|
@res.join
|
176
190
|
end
|
177
191
|
|
192
|
+
##
|
193
|
+
# Adds +paragraph+ to the output
|
194
|
+
|
178
195
|
def accept_paragraph(paragraph)
|
179
|
-
@res <<
|
180
|
-
@res << wrap(
|
181
|
-
@res <<
|
196
|
+
@res << "\n<p>"
|
197
|
+
@res << wrap(to_html(paragraph.text))
|
198
|
+
@res << "</p>\n"
|
182
199
|
end
|
183
200
|
|
201
|
+
##
|
202
|
+
# Adds +verbatim+ to the output
|
203
|
+
|
184
204
|
def accept_verbatim(verbatim)
|
185
|
-
@res <<
|
186
|
-
@res << CGI.escapeHTML(verbatim.text)
|
187
|
-
@res <<
|
205
|
+
@res << "\n<pre>"
|
206
|
+
@res << CGI.escapeHTML(verbatim.text.rstrip)
|
207
|
+
@res << "</pre>\n"
|
188
208
|
end
|
189
209
|
|
210
|
+
##
|
211
|
+
# Adds +rule+ to the output
|
212
|
+
|
190
213
|
def accept_rule(rule)
|
191
214
|
size = rule.weight
|
192
215
|
size = 10 if size > 10
|
193
|
-
@res << "<hr style=\"height: #{size}px\"
|
216
|
+
@res << "<hr style=\"height: #{size}px\">\n"
|
194
217
|
end
|
195
218
|
|
219
|
+
##
|
220
|
+
# Prepares the visitor for consuming +list+
|
221
|
+
|
196
222
|
def accept_list_start(list)
|
197
223
|
@list << list.type
|
198
|
-
@res << html_list_name(list.type, true)
|
224
|
+
@res << html_list_name(list.type, true)
|
199
225
|
@in_list_entry.push false
|
200
226
|
end
|
201
227
|
|
228
|
+
##
|
229
|
+
# Finishes consumption of +list+
|
230
|
+
|
202
231
|
def accept_list_end(list)
|
203
232
|
@list.pop
|
204
233
|
if tag = @in_list_entry.pop
|
205
|
-
@res <<
|
234
|
+
@res << tag
|
206
235
|
end
|
207
236
|
@res << html_list_name(list.type, false) << "\n"
|
208
237
|
end
|
209
238
|
|
239
|
+
##
|
240
|
+
# Prepares the visitor for consuming +list_item+
|
241
|
+
|
210
242
|
def accept_list_item_start(list_item)
|
211
243
|
if tag = @in_list_entry.last
|
212
|
-
@res <<
|
244
|
+
@res << tag
|
213
245
|
end
|
214
246
|
|
215
247
|
@res << list_item_start(list_item, @list.last)
|
216
248
|
end
|
217
249
|
|
250
|
+
##
|
251
|
+
# Finishes consumption of +list_item+
|
252
|
+
|
218
253
|
def accept_list_item_end(list_item)
|
219
254
|
@in_list_entry[-1] = list_end_for(@list.last)
|
220
255
|
end
|
221
256
|
|
222
|
-
def accept_blank_line(blank_line)
|
223
|
-
# @res << annotate("<p />") << "\n"
|
224
|
-
end
|
225
|
-
|
226
|
-
def accept_heading(heading)
|
227
|
-
@res << convert_heading(heading.level, @am.flow(heading.text))
|
228
|
-
end
|
229
|
-
|
230
|
-
def accept_raw raw
|
231
|
-
@res << raw.parts.join("\n")
|
232
|
-
end
|
233
|
-
|
234
|
-
private
|
235
|
-
|
236
257
|
##
|
237
|
-
#
|
258
|
+
# Adds +blank_line+ to the output
|
238
259
|
|
239
|
-
def
|
240
|
-
|
260
|
+
def accept_blank_line(blank_line)
|
261
|
+
# @res << annotate("<p />") << "\n"
|
241
262
|
end
|
242
263
|
|
243
264
|
##
|
244
|
-
#
|
265
|
+
# Adds +heading+ to the output
|
245
266
|
|
246
|
-
def
|
247
|
-
|
267
|
+
def accept_heading(heading)
|
268
|
+
@res << "\n<h#{heading.level}>"
|
269
|
+
@res << to_html(heading.text)
|
270
|
+
@res << "</h#{heading.level}>\n"
|
248
271
|
end
|
249
272
|
|
250
273
|
##
|
251
|
-
#
|
252
|
-
# trademark symbols to HTML escaped Unicode.
|
253
|
-
|
254
|
-
def convert_string_fancy(item)
|
255
|
-
# convert ampersand before doing anything else
|
256
|
-
item.gsub(/&/, '&').
|
257
|
-
|
258
|
-
# convert -- to em-dash, (-- to en-dash)
|
259
|
-
gsub(/---?/, '—'). #gsub(/--/, '–').
|
260
|
-
|
261
|
-
# convert ... to elipsis (and make sure .... becomes .<elipsis>)
|
262
|
-
gsub(/\.\.\.\./, '.…').gsub(/\.\.\./, '…').
|
274
|
+
# Adds +raw+ to the output
|
263
275
|
|
264
|
-
|
265
|
-
|
266
|
-
gsub(%r{\'(?=\W|s\b)}, '’').
|
267
|
-
|
268
|
-
# convert single opening quote
|
269
|
-
gsub(/'/, '‘').
|
270
|
-
|
271
|
-
# convert double closing quote
|
272
|
-
gsub(%r{([^ \t\r\n\[\{\(])\"(?=\W)}, '\1”'). # }
|
273
|
-
|
274
|
-
# convert double opening quote
|
275
|
-
gsub(/"/, '“').
|
276
|
-
|
277
|
-
# convert copyright
|
278
|
-
gsub(/\(c\)/, '©').
|
279
|
-
|
280
|
-
# convert registered trademark
|
281
|
-
gsub(/\(r\)/, '®')
|
276
|
+
def accept_raw raw
|
277
|
+
@res << raw.parts.join("\n")
|
282
278
|
end
|
283
279
|
|
284
280
|
##
|
285
|
-
#
|
281
|
+
# CGI escapes +text+
|
286
282
|
|
287
|
-
def
|
288
|
-
|
289
|
-
convert_flow(flow),
|
290
|
-
annotate("</h#{level}>\n")].join
|
283
|
+
def convert_string(text)
|
284
|
+
CGI.escapeHTML text
|
291
285
|
end
|
292
286
|
|
293
287
|
##
|
294
|
-
#
|
288
|
+
# Determines the HTML list element for +list_type+ and +open_tag+
|
295
289
|
|
296
290
|
def html_list_name(list_type, open_tag)
|
297
291
|
tags = LIST_TYPE_TO_HTML[list_type]
|
298
292
|
raise RDoc::Error, "Invalid list type: #{list_type.inspect}" unless tags
|
299
|
-
|
293
|
+
tags[open_tag ? 0 : 1]
|
300
294
|
end
|
301
295
|
|
302
296
|
##
|
303
|
-
#
|
297
|
+
# Returns the HTML tag for +list_type+, possible using a label from
|
298
|
+
# +list_item+
|
304
299
|
|
305
300
|
def list_item_start(list_item, list_type)
|
306
301
|
case list_type
|
307
302
|
when :BULLET, :LALPHA, :NUMBER, :UALPHA then
|
308
|
-
|
309
|
-
|
303
|
+
"<li>"
|
310
304
|
when :LABEL then
|
311
|
-
|
312
|
-
convert_flow(@am.flow(list_item.label)) +
|
313
|
-
annotate("</dt>") +
|
314
|
-
annotate("<dd>")
|
315
|
-
|
305
|
+
"<dt>#{to_html list_item.label}</dt>\n<dd>"
|
316
306
|
when :NOTE then
|
317
|
-
|
318
|
-
annotate("<td valign=\"top\">") +
|
319
|
-
convert_flow(@am.flow(list_item.label)) +
|
320
|
-
annotate("</td>") +
|
321
|
-
annotate("<td>")
|
307
|
+
"<tr><td class=\"rdoc-term\"><p>#{to_html list_item.label}</p></td>\n<td>"
|
322
308
|
else
|
323
309
|
raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
|
324
310
|
end
|
325
311
|
end
|
326
312
|
|
327
313
|
##
|
328
|
-
#
|
314
|
+
# Returns the HTML end-tag for +list_type+
|
329
315
|
|
330
316
|
def list_end_for(list_type)
|
331
317
|
case list_type
|
@@ -340,5 +326,12 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
340
326
|
end
|
341
327
|
end
|
342
328
|
|
329
|
+
##
|
330
|
+
# Converts +item+ to HTML using RDoc::Text#to_html
|
331
|
+
|
332
|
+
def to_html item
|
333
|
+
super convert_flow @am.flow item
|
334
|
+
end
|
335
|
+
|
343
336
|
end
|
344
337
|
|