rdoc 3.9.5 → 3.10.pre.1
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/.autotest +6 -3
- data/History.txt +63 -13
- data/LICENSE.rdoc +57 -0
- data/Manifest.txt +60 -6
- data/Rakefile +24 -12
- data/TODO.rdoc +30 -0
- data/bin/rdoc +0 -2
- data/lib/rdoc.rb +55 -2
- data/lib/rdoc/alias.rb +0 -2
- data/lib/rdoc/anon_class.rb +0 -2
- data/lib/rdoc/any_method.rb +0 -3
- data/lib/rdoc/attr.rb +0 -2
- data/lib/rdoc/class_module.rb +40 -7
- data/lib/rdoc/code_object.rb +1 -3
- data/lib/rdoc/code_objects.rb +3 -21
- data/lib/rdoc/comment.rb +225 -0
- data/lib/rdoc/constant.rb +0 -2
- data/lib/rdoc/context.rb +37 -120
- data/lib/rdoc/context/section.rb +114 -0
- data/lib/rdoc/cross_reference.rb +16 -7
- data/lib/rdoc/encoding.rb +0 -2
- data/lib/rdoc/gauntlet.rb +1 -1
- data/lib/rdoc/generator.rb +7 -2
- data/lib/rdoc/generator/darkfish.rb +126 -20
- data/lib/rdoc/generator/json_index.rb +240 -0
- data/lib/rdoc/generator/markup.rb +17 -54
- data/lib/rdoc/generator/ri.rb +0 -3
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +16 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +8 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +16 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +7 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +10 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +10 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +10 -0
- data/lib/rdoc/generator/template/darkfish/class.rhtml +161 -0
- data/lib/rdoc/generator/template/darkfish/fileinfo.rhtml +32 -0
- data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
- data/lib/rdoc/generator/template/darkfish/index.rhtml +16 -61
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +99 -64
- data/lib/rdoc/generator/template/darkfish/js/jquery.js +15 -29
- data/lib/rdoc/generator/template/darkfish/js/search.js +94 -0
- data/lib/rdoc/generator/template/darkfish/page.rhtml +16 -0
- data/lib/rdoc/generator/template/darkfish/rdoc.css +126 -286
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +50 -0
- data/lib/rdoc/generator/template/json_index/js/navigation.js +142 -0
- data/lib/rdoc/generator/template/json_index/js/searcher.js +228 -0
- data/lib/rdoc/ghost_method.rb +0 -2
- data/lib/rdoc/include.rb +0 -2
- data/lib/rdoc/markup.rb +204 -43
- data/lib/rdoc/markup/attr_changer.rb +25 -0
- data/lib/rdoc/markup/attr_span.rb +29 -0
- data/lib/rdoc/markup/attribute.rb +51 -0
- data/lib/rdoc/markup/document.rb +22 -1
- data/lib/rdoc/markup/formatter.rb +4 -11
- data/lib/rdoc/markup/formatter_test_case.rb +1 -2
- data/lib/rdoc/markup/heading.rb +44 -0
- data/lib/rdoc/markup/include.rb +42 -0
- data/lib/rdoc/markup/inline.rb +1 -144
- data/lib/rdoc/markup/list.rb +2 -1
- data/lib/rdoc/markup/parser.rb +6 -16
- data/lib/rdoc/markup/pre_process.rb +64 -10
- data/lib/rdoc/markup/raw.rb +1 -1
- data/lib/rdoc/markup/special.rb +40 -0
- data/lib/rdoc/markup/text_formatter_test_case.rb +0 -2
- data/lib/rdoc/markup/to_ansi.rb +0 -2
- data/lib/rdoc/markup/to_bs.rb +0 -2
- data/lib/rdoc/markup/to_html.rb +102 -34
- data/lib/rdoc/markup/to_html_crossref.rb +36 -5
- data/lib/rdoc/markup/to_html_snippet.rb +270 -0
- data/lib/rdoc/markup/to_label.rb +55 -0
- data/lib/rdoc/markup/to_rdoc.rb +0 -3
- data/lib/rdoc/markup/to_table_of_contents.rb +62 -0
- data/lib/rdoc/markup/to_test.rb +0 -3
- data/lib/rdoc/markup/to_tt_only.rb +0 -3
- data/lib/rdoc/markup/verbatim.rb +18 -0
- data/lib/rdoc/meta_method.rb +0 -2
- data/lib/rdoc/method_attr.rb +17 -1
- data/lib/rdoc/normal_class.rb +0 -2
- data/lib/rdoc/normal_module.rb +0 -2
- data/lib/rdoc/options.rb +18 -3
- data/lib/rdoc/parser.rb +74 -42
- data/lib/rdoc/parser/c.rb +79 -118
- data/lib/rdoc/parser/rd.rb +22 -0
- data/lib/rdoc/parser/ruby.rb +86 -54
- data/lib/rdoc/parser/simple.rb +21 -9
- data/lib/rdoc/parser/text.rb +11 -0
- data/lib/rdoc/rd.rb +95 -0
- data/lib/rdoc/rd/block_parser.ry +638 -0
- data/lib/rdoc/rd/inline.rb +71 -0
- data/lib/rdoc/rd/inline_parser.ry +575 -0
- data/lib/rdoc/rdoc.rb +8 -23
- data/lib/rdoc/require.rb +0 -2
- data/lib/rdoc/ri.rb +4 -2
- data/lib/rdoc/ri/driver.rb +2 -6
- data/lib/rdoc/ri/store.rb +0 -1
- data/lib/rdoc/ruby_lex.rb +43 -20
- data/lib/rdoc/ruby_token.rb +44 -2
- data/lib/rdoc/single_class.rb +0 -2
- data/lib/rdoc/stats.rb +0 -5
- data/lib/rdoc/task.rb +2 -6
- data/lib/rdoc/test_case.rb +59 -0
- data/lib/rdoc/text.rb +42 -30
- data/lib/rdoc/token_stream.rb +45 -0
- data/lib/rdoc/tom_doc.rb +232 -0
- data/lib/rdoc/top_level.rb +36 -4
- data/test/test_attribute_manager.rb +26 -29
- data/test/test_rdoc_any_method.rb +2 -26
- data/test/test_rdoc_attr.rb +4 -4
- data/test/test_rdoc_class_module.rb +95 -12
- data/test/test_rdoc_code_object.rb +10 -3
- data/test/test_rdoc_comment.rb +504 -0
- data/test/test_rdoc_context.rb +60 -11
- data/test/test_rdoc_context_section.rb +16 -17
- data/test/test_rdoc_cross_reference.rb +17 -2
- data/test/test_rdoc_encoding.rb +4 -7
- data/test/test_rdoc_generator_darkfish.rb +12 -11
- data/test/test_rdoc_generator_json_index.rb +255 -0
- data/test/test_rdoc_generator_markup.rb +56 -0
- data/test/test_rdoc_generator_ri.rb +8 -11
- data/test/test_rdoc_markup.rb +9 -5
- data/test/test_rdoc_markup_attribute_manager.rb +5 -8
- data/test/test_rdoc_markup_document.rb +34 -6
- data/test/test_rdoc_markup_formatter.rb +11 -13
- data/test/test_rdoc_markup_heading.rb +20 -0
- data/test/test_rdoc_markup_include.rb +19 -0
- data/test/test_rdoc_markup_indented_paragraph.rb +4 -5
- data/test/test_rdoc_markup_paragraph.rb +2 -5
- data/test/test_rdoc_markup_parser.rb +87 -7
- data/test/test_rdoc_markup_pre_process.rb +60 -9
- data/test/test_rdoc_markup_raw.rb +4 -6
- data/test/test_rdoc_markup_to_ansi.rb +1 -4
- data/test/test_rdoc_markup_to_bs.rb +1 -4
- data/test/test_rdoc_markup_to_html.rb +170 -31
- data/test/test_rdoc_markup_to_html_crossref.rb +89 -11
- data/test/test_rdoc_markup_to_html_snippet.rb +668 -0
- data/test/test_rdoc_markup_to_label.rb +50 -0
- data/test/test_rdoc_markup_to_rdoc.rb +1 -4
- data/test/test_rdoc_markup_to_table_of_contents.rb +90 -0
- data/test/test_rdoc_markup_to_tt_only.rb +1 -4
- data/test/test_rdoc_markup_verbatim.rb +16 -0
- data/test/test_rdoc_method_attr.rb +16 -1
- data/test/test_rdoc_options.rb +17 -7
- data/test/test_rdoc_parser.rb +75 -6
- data/test/test_rdoc_parser_c.rb +56 -104
- data/test/test_rdoc_parser_rd.rb +52 -0
- data/test/test_rdoc_parser_ruby.rb +264 -323
- data/test/test_rdoc_parser_simple.rb +33 -17
- data/test/test_rdoc_rd.rb +30 -0
- data/test/test_rdoc_rd_block_parser.rb +527 -0
- data/test/test_rdoc_rd_inline.rb +63 -0
- data/test/test_rdoc_rd_inline_parser.rb +173 -0
- data/test/test_rdoc_rdoc.rb +7 -9
- data/test/test_rdoc_ri_driver.rb +10 -15
- data/test/test_rdoc_ri_paths.rb +6 -6
- data/test/test_rdoc_ri_store.rb +6 -13
- data/test/test_rdoc_ruby_lex.rb +53 -5
- data/test/test_rdoc_rubygems_hook.rb +2 -1
- data/test/test_rdoc_stats.rb +83 -103
- data/test/test_rdoc_task.rb +5 -4
- data/test/test_rdoc_text.rb +156 -11
- data/test/test_rdoc_token_stream.rb +42 -0
- data/test/test_rdoc_tom_doc.rb +458 -0
- data/test/test_rdoc_top_level.rb +49 -2
- data/test/xref_test_case.rb +4 -8
- metadata +217 -111
- metadata.gz.sig +0 -0
- checksums.yaml +0 -7
- checksums.yaml.gz.sig +0 -0
- data/CVE-2013-0256.rdoc +0 -49
- data/LICENSE.txt +0 -57
- data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -321
- data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
- data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
- data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
data/lib/rdoc/markup/parser.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'strscan'
|
2
|
-
require 'rdoc/text'
|
3
2
|
|
4
3
|
##
|
5
4
|
# A recursive-descent parser for RDoc markup.
|
@@ -52,7 +51,9 @@ class RDoc::Markup::Parser
|
|
52
51
|
attr_reader :tokens
|
53
52
|
|
54
53
|
##
|
55
|
-
# Parses +str+ into a Document
|
54
|
+
# Parses +str+ into a Document.
|
55
|
+
#
|
56
|
+
# Use RDoc::Markup#parse instead of this method.
|
56
57
|
|
57
58
|
def self.parse str
|
58
59
|
parser = new
|
@@ -426,7 +427,7 @@ class RDoc::Markup::Parser
|
|
426
427
|
[:TEXT, s.matched.sub(/\r$/, ''), *token_pos(pos)]
|
427
428
|
end
|
428
429
|
# --- (at least 3) and nothing else on the line => :RULE
|
429
|
-
when s.scan(/(-{3,})
|
430
|
+
when s.scan(/(-{3,}) *\r?$/) then
|
430
431
|
[:RULE, s[1].length - 2, *token_pos(pos)]
|
431
432
|
# * or - followed by white space and text => :BULLET
|
432
433
|
when s.scan(/([*-]) +(\S)/) then
|
@@ -451,10 +452,10 @@ class RDoc::Markup::Parser
|
|
451
452
|
end
|
452
453
|
[list_type, list_label, *token_pos(pos)]
|
453
454
|
# [text] followed by spaces or end of line => :LABEL
|
454
|
-
when s.scan(/\[(.*?)\](
|
455
|
+
when s.scan(/\[(.*?)\]( +|\r?$)/) then
|
455
456
|
[:LABEL, s[1], *token_pos(pos)]
|
456
457
|
# text:: followed by spaces or end of line => :NOTE
|
457
|
-
when s.scan(/(.*?)::(
|
458
|
+
when s.scan(/(.*?)::( +|\r?$)/) then
|
458
459
|
[:NOTE, s[1], *token_pos(pos)]
|
459
460
|
# anything else: :TEXT
|
460
461
|
else s.scan(/.*/)
|
@@ -484,14 +485,3 @@ class RDoc::Markup::Parser
|
|
484
485
|
|
485
486
|
end
|
486
487
|
|
487
|
-
require 'rdoc/markup/blank_line'
|
488
|
-
require 'rdoc/markup/document'
|
489
|
-
require 'rdoc/markup/heading'
|
490
|
-
require 'rdoc/markup/list'
|
491
|
-
require 'rdoc/markup/list_item'
|
492
|
-
require 'rdoc/markup/raw'
|
493
|
-
require 'rdoc/markup/paragraph'
|
494
|
-
require 'rdoc/markup/indented_paragraph'
|
495
|
-
require 'rdoc/markup/rule'
|
496
|
-
require 'rdoc/markup/verbatim'
|
497
|
-
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'rdoc/markup'
|
2
|
-
require 'rdoc/encoding'
|
3
|
-
|
4
1
|
##
|
5
2
|
# Handle common directives that can occur in a block of text:
|
6
3
|
#
|
@@ -13,9 +10,27 @@ require 'rdoc/encoding'
|
|
13
10
|
|
14
11
|
class RDoc::Markup::PreProcess
|
15
12
|
|
13
|
+
##
|
14
|
+
# An RDoc::Options instance that will be filled in with overrides from
|
15
|
+
# directives
|
16
|
+
|
16
17
|
attr_accessor :options
|
17
18
|
|
18
|
-
|
19
|
+
##
|
20
|
+
# Adds a post-process handler for directives. The handler will be called
|
21
|
+
# with the result RDoc::Comment (or text String) and the code object for the
|
22
|
+
# comment (if any).
|
23
|
+
|
24
|
+
def self.post_process &block
|
25
|
+
@post_processors << block
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Registered post-processors
|
30
|
+
|
31
|
+
def self.post_processors
|
32
|
+
@post_processors
|
33
|
+
end
|
19
34
|
|
20
35
|
##
|
21
36
|
# Registers +directive+ as one handled by RDoc. If a block is given the
|
@@ -33,6 +48,16 @@ class RDoc::Markup::PreProcess
|
|
33
48
|
@registered
|
34
49
|
end
|
35
50
|
|
51
|
+
##
|
52
|
+
# Clears all registered directives and post-processors
|
53
|
+
|
54
|
+
def self.reset
|
55
|
+
@post_processors = []
|
56
|
+
@registered = {}
|
57
|
+
end
|
58
|
+
|
59
|
+
reset
|
60
|
+
|
36
61
|
##
|
37
62
|
# Creates a new pre-processor for +input_file_name+ that will look for
|
38
63
|
# included files in +include_path+
|
@@ -44,7 +69,7 @@ class RDoc::Markup::PreProcess
|
|
44
69
|
end
|
45
70
|
|
46
71
|
##
|
47
|
-
# Look for directives in
|
72
|
+
# Look for directives in the given +text+.
|
48
73
|
#
|
49
74
|
# Options that we don't handle are yielded. If the block returns false the
|
50
75
|
# directive is restored to the text. If the block returns nil or no block
|
@@ -54,27 +79,56 @@ class RDoc::Markup::PreProcess
|
|
54
79
|
# If no matching directive was registered the directive is restored to the
|
55
80
|
# text.
|
56
81
|
#
|
57
|
-
# If +code_object+ is given and the
|
58
|
-
# +code_object+. See
|
82
|
+
# If +code_object+ is given and the directive is unknown then the
|
83
|
+
# directive's parameter is set as metadata on the +code_object+. See
|
84
|
+
# RDoc::CodeObject#metadata for details.
|
59
85
|
|
60
86
|
def handle text, code_object = nil, &block
|
61
|
-
|
87
|
+
if RDoc::Comment === text then
|
88
|
+
comment = text
|
89
|
+
text = text.text
|
90
|
+
end
|
91
|
+
|
92
|
+
encoding = text.encoding if defined?(Encoding)
|
93
|
+
|
62
94
|
# regexp helper (square brackets for optional)
|
63
95
|
# $1 $2 $3 $4 $5
|
64
96
|
# [prefix][\]:directive:[spaces][param]newline
|
65
|
-
text.gsub!(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?\n/) do
|
97
|
+
text.gsub!(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?(\r?\n|$)/) do
|
66
98
|
# skip something like ':toto::'
|
67
99
|
next $& if $4.empty? and $5 and $5[0, 1] == ':'
|
68
100
|
|
69
101
|
# skip if escaped
|
70
102
|
next "#$1:#$3:#$4#$5\n" unless $2.empty?
|
71
103
|
|
104
|
+
# This is not in handle_directive because I didn't want to pass another
|
105
|
+
# argument into it
|
106
|
+
if comment and $3 == 'markup' then
|
107
|
+
next "#{$1.strip}\n" unless $5
|
108
|
+
comment.format = $5.downcase
|
109
|
+
next "#{$1.strip}\n"
|
110
|
+
end
|
111
|
+
|
72
112
|
handle_directive $1, $3, $5, code_object, encoding, &block
|
73
113
|
end
|
74
114
|
|
115
|
+
comment = text unless comment
|
116
|
+
|
117
|
+
self.class.post_processors.each do |handler|
|
118
|
+
handler.call comment, code_object
|
119
|
+
end
|
120
|
+
|
75
121
|
text
|
76
122
|
end
|
77
123
|
|
124
|
+
##
|
125
|
+
# Performs the actions described by +directive+ and its parameter +param+.
|
126
|
+
#
|
127
|
+
# +code_object+ is used for directives that operate on a class or module.
|
128
|
+
# +prefix+ is used to ensure the replacement for handled directives is
|
129
|
+
# correct. +encoding+ is used for the <tt>include</tt> directive.
|
130
|
+
#
|
131
|
+
# For a list of directives in RDoc see RDoc::Markup.
|
78
132
|
#--
|
79
133
|
# When 1.8.7 support is ditched prefix can be defaulted to ''
|
80
134
|
|
@@ -92,7 +146,7 @@ class RDoc::Markup::PreProcess
|
|
92
146
|
blankline
|
93
147
|
when 'category' then
|
94
148
|
if RDoc::Context === code_object then
|
95
|
-
section = code_object.add_section param
|
149
|
+
section = code_object.add_section param
|
96
150
|
code_object.temporary_section = section
|
97
151
|
end
|
98
152
|
|
data/lib/rdoc/markup/raw.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
##
|
2
|
+
# Hold details of a special sequence
|
3
|
+
|
4
|
+
class RDoc::Markup::Special
|
5
|
+
|
6
|
+
##
|
7
|
+
# Special type
|
8
|
+
|
9
|
+
attr_reader :type
|
10
|
+
|
11
|
+
##
|
12
|
+
# Special text
|
13
|
+
|
14
|
+
attr_accessor :text
|
15
|
+
|
16
|
+
##
|
17
|
+
# Creates a new special sequence of +type+ with +text+
|
18
|
+
|
19
|
+
def initialize(type, text)
|
20
|
+
@type, @text = type, text
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Specials are equal when the have the same text and type
|
25
|
+
|
26
|
+
def ==(o)
|
27
|
+
self.text == o.text && self.type == o.type
|
28
|
+
end
|
29
|
+
|
30
|
+
def inspect # :nodoc:
|
31
|
+
"#<RDoc::Markup::Special:0x%x @type=%p, name=%p @text=%p>" % [
|
32
|
+
object_id, @type, RDoc::Markup::Attribute.as_string(type), text.dump]
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s # :nodoc:
|
36
|
+
"Special: type=#{type}, name=#{RDoc::Markup::Attribute.as_string type}, text=#{text.dump}"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
data/lib/rdoc/markup/to_ansi.rb
CHANGED
data/lib/rdoc/markup/to_bs.rb
CHANGED
data/lib/rdoc/markup/to_html.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
require 'rdoc/markup/formatter'
|
2
|
-
require 'rdoc/markup/inline'
|
3
|
-
|
4
1
|
require 'cgi'
|
5
2
|
|
6
3
|
##
|
7
|
-
# Outputs RDoc markup as HTML
|
4
|
+
# Outputs RDoc markup as HTML.
|
8
5
|
|
9
6
|
class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
10
7
|
|
@@ -16,18 +13,24 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
16
13
|
# Maps RDoc::Markup::Parser::LIST_TOKENS types to HTML tags
|
17
14
|
|
18
15
|
LIST_TYPE_TO_HTML = {
|
19
|
-
:BULLET => ['<ul>',
|
20
|
-
:LABEL => ['<dl class="rdoc-list">',
|
21
|
-
:LALPHA => ['<ol style="
|
22
|
-
:NOTE => ['<
|
23
|
-
:NUMBER => ['<ol>',
|
24
|
-
:UALPHA => ['<ol style="
|
16
|
+
:BULLET => ['<ul>', '</ul>'],
|
17
|
+
:LABEL => ['<dl class="rdoc-list label-list">', '</dl>'],
|
18
|
+
:LALPHA => ['<ol style="list-style-type: lower-alpha">', '</ol>'],
|
19
|
+
:NOTE => ['<dl class="rdoc-list note-list">', '</dl>'],
|
20
|
+
:NUMBER => ['<ol>', '</ol>'],
|
21
|
+
:UALPHA => ['<ol style="list-style-type: upper-alpha">', '</ol>'],
|
25
22
|
}
|
26
23
|
|
27
24
|
attr_reader :res # :nodoc:
|
28
25
|
attr_reader :in_list_entry # :nodoc:
|
29
26
|
attr_reader :list # :nodoc:
|
30
27
|
|
28
|
+
##
|
29
|
+
# The RDoc::CodeObject HTML is being generated for. This is used to
|
30
|
+
# generate namespaced URI fragments
|
31
|
+
|
32
|
+
attr_accessor :code_object
|
33
|
+
|
31
34
|
##
|
32
35
|
# Path to this document for relative links
|
33
36
|
|
@@ -65,14 +68,18 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
65
68
|
def initialize markup = nil
|
66
69
|
super
|
67
70
|
|
68
|
-
@
|
71
|
+
@code_object = nil
|
72
|
+
@from_path = ''
|
69
73
|
@in_list_entry = nil
|
70
74
|
@list = nil
|
71
|
-
@
|
75
|
+
@th = nil
|
72
76
|
|
73
77
|
# external links
|
74
78
|
@markup.add_special(/((link:|https?:|mailto:|ftp:|www\.)\S+\w)/, :HYPERLINK)
|
75
79
|
|
80
|
+
# internal links
|
81
|
+
@markup.add_special(/rdoc-[a-z]+:\S+/, :RDOCLINK)
|
82
|
+
|
76
83
|
# and links of the form <text>[<url>]
|
77
84
|
@markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)
|
78
85
|
|
@@ -101,6 +108,39 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
101
108
|
gen_url url, url
|
102
109
|
end
|
103
110
|
|
111
|
+
##
|
112
|
+
# +special+ is an rdoc-schemed link that will be converted into a hyperlink.
|
113
|
+
#
|
114
|
+
# For the +rdoc-ref+ scheme the named reference will be returned without
|
115
|
+
# creating a link.
|
116
|
+
#
|
117
|
+
# For the +rdoc-label+ scheme the footnote and label prefixes are stripped
|
118
|
+
# when creating a link. All other contents will be linked verbatim.
|
119
|
+
|
120
|
+
def handle_special_RDOCLINK special
|
121
|
+
url = special.text
|
122
|
+
|
123
|
+
case url
|
124
|
+
when /\Ardoc-ref:/
|
125
|
+
$'
|
126
|
+
when /\Ardoc-label:/
|
127
|
+
text = $'
|
128
|
+
|
129
|
+
text = case text
|
130
|
+
when /\Alabel-/ then $'
|
131
|
+
when /\Afootmark-/ then "^#{$'}"
|
132
|
+
when /\Afoottext-/ then "*#{$'}"
|
133
|
+
else text
|
134
|
+
end
|
135
|
+
|
136
|
+
gen_url url, text
|
137
|
+
else
|
138
|
+
url =~ /\Ardoc-[a-z]+:/
|
139
|
+
|
140
|
+
$'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
104
144
|
##
|
105
145
|
# This +special+ is a link where the label is different from the URL
|
106
146
|
# <tt>label[url]</tt> or <tt>{long label}[url]</tt>
|
@@ -147,10 +187,24 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
147
187
|
##
|
148
188
|
# Adds +verbatim+ to the output
|
149
189
|
|
150
|
-
def accept_verbatim
|
151
|
-
|
152
|
-
|
153
|
-
@res <<
|
190
|
+
def accept_verbatim verbatim
|
191
|
+
text = verbatim.text.rstrip
|
192
|
+
|
193
|
+
@res << if verbatim.ruby? or parseable? text then
|
194
|
+
options = RDoc::RDoc.current.options if RDoc::RDoc.current
|
195
|
+
|
196
|
+
begin
|
197
|
+
tokens = RDoc::RubyLex.tokenize text, options
|
198
|
+
|
199
|
+
"\n<pre class=\"ruby\">" \
|
200
|
+
"#{RDoc::TokenStream.to_html tokens}" \
|
201
|
+
"</pre>\n"
|
202
|
+
rescue RDoc::RubyLex::Error
|
203
|
+
"\n<pre>#{CGI.escapeHTML text}</pre>\n"
|
204
|
+
end
|
205
|
+
else
|
206
|
+
"\n<pre>#{CGI.escapeHTML text}</pre>\n"
|
207
|
+
end
|
154
208
|
end
|
155
209
|
|
156
210
|
##
|
@@ -208,12 +262,19 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
208
262
|
end
|
209
263
|
|
210
264
|
##
|
211
|
-
# Adds +heading+ to the output
|
265
|
+
# Adds +heading+ to the output. The headings greater than 6 are trimmed to
|
266
|
+
# level 6.
|
267
|
+
|
268
|
+
def accept_heading heading
|
269
|
+
level = [6, heading.level].min
|
270
|
+
|
271
|
+
label = heading.label
|
272
|
+
label = [@code_object.aref, label].compact.join '-' if
|
273
|
+
@code_object and @code_object.respond_to? :aref
|
212
274
|
|
213
|
-
|
214
|
-
@res << "\n<h#{heading.level}>"
|
275
|
+
@res << "\n<h#{level} id=\"#{label}\">"
|
215
276
|
@res << to_html(heading.text)
|
216
|
-
@res << "</h#{
|
277
|
+
@res << "</h#{level}>\n"
|
217
278
|
end
|
218
279
|
|
219
280
|
##
|
@@ -233,11 +294,15 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
233
294
|
end
|
234
295
|
|
235
296
|
##
|
236
|
-
# Generate a link
|
297
|
+
# Generate a link to +url+ with content +text+. Handles the special cases
|
237
298
|
# for img: and link: described under handle_special_HYPERLINK
|
238
299
|
|
239
|
-
def gen_url
|
240
|
-
if url =~
|
300
|
+
def gen_url url, text
|
301
|
+
if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
|
302
|
+
type = "link"
|
303
|
+
path = "##{$1}"
|
304
|
+
id = " id=\"#{$2}\"" if $2
|
305
|
+
elsif url =~ /([A-Za-z]+):(.*)/ then
|
241
306
|
type = $1
|
242
307
|
path = $2
|
243
308
|
else
|
@@ -258,7 +323,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
258
323
|
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
|
259
324
|
"<img src=\"#{url}\" />"
|
260
325
|
else
|
261
|
-
"<a href=\"#{url}\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
|
326
|
+
"<a#{id} href=\"#{url}\">#{text.sub(%r{^#{type}:/*}, '')}</a>"
|
262
327
|
end
|
263
328
|
end
|
264
329
|
|
@@ -275,9 +340,9 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
275
340
|
# Maps attributes to HTML tags
|
276
341
|
|
277
342
|
def init_tags
|
278
|
-
add_tag :BOLD, "<
|
279
|
-
add_tag :TT, "<
|
280
|
-
add_tag :EM, "<em>",
|
343
|
+
add_tag :BOLD, "<strong>", "</strong>"
|
344
|
+
add_tag :TT, "<code>", "</code>"
|
345
|
+
add_tag :EM, "<em>", "</em>"
|
281
346
|
end
|
282
347
|
|
283
348
|
##
|
@@ -288,10 +353,8 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
288
353
|
case list_type
|
289
354
|
when :BULLET, :LALPHA, :NUMBER, :UALPHA then
|
290
355
|
"<li>"
|
291
|
-
when :LABEL then
|
292
|
-
"<dt>#{to_html list_item.label}
|
293
|
-
when :NOTE then
|
294
|
-
"<tr><td class=\"rdoc-term\"><p>#{to_html list_item.label}</p></td>\n<td>"
|
356
|
+
when :LABEL, :NOTE then
|
357
|
+
"<dt>#{to_html list_item.label}\n<dd>"
|
295
358
|
else
|
296
359
|
raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
|
297
360
|
end
|
@@ -304,15 +367,20 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
304
367
|
case list_type
|
305
368
|
when :BULLET, :LALPHA, :NUMBER, :UALPHA then
|
306
369
|
"</li>"
|
307
|
-
when :LABEL then
|
370
|
+
when :LABEL, :NOTE then
|
308
371
|
"</dd>"
|
309
|
-
when :NOTE then
|
310
|
-
"</td></tr>"
|
311
372
|
else
|
312
373
|
raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
|
313
374
|
end
|
314
375
|
end
|
315
376
|
|
377
|
+
##
|
378
|
+
# Returns true if Ripper is available it can create a sexp from +text+
|
379
|
+
|
380
|
+
def parseable? text
|
381
|
+
text =~ /\b(def|class|module|require)\b|=>|\{\s?\||do \|/
|
382
|
+
end
|
383
|
+
|
316
384
|
##
|
317
385
|
# Converts +item+ to HTML using RDoc::Text#to_html
|
318
386
|
|