gitlab-rdoc 6.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.rdoc +220 -0
- data/CVE-2013-0256.rdoc +49 -0
- data/ExampleMarkdown.md +37 -0
- data/ExampleRDoc.rdoc +208 -0
- data/Gemfile +12 -0
- data/History.rdoc +1666 -0
- data/LEGAL.rdoc +50 -0
- data/LICENSE.rdoc +57 -0
- data/README.rdoc +133 -0
- data/RI.rdoc +57 -0
- data/Rakefile +101 -0
- data/TODO.rdoc +59 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/exe/rdoc +44 -0
- data/exe/ri +12 -0
- data/lib/rdoc/alias.rb +112 -0
- data/lib/rdoc/anon_class.rb +11 -0
- data/lib/rdoc/any_method.rb +361 -0
- data/lib/rdoc/attr.rb +176 -0
- data/lib/rdoc/class_module.rb +802 -0
- data/lib/rdoc/code_object.rb +421 -0
- data/lib/rdoc/code_objects.rb +6 -0
- data/lib/rdoc/comment.rb +250 -0
- data/lib/rdoc/constant.rb +187 -0
- data/lib/rdoc/context/section.rb +232 -0
- data/lib/rdoc/context.rb +1266 -0
- data/lib/rdoc/cross_reference.rb +202 -0
- data/lib/rdoc/encoding.rb +136 -0
- data/lib/rdoc/erb_partial.rb +19 -0
- data/lib/rdoc/erbio.rb +42 -0
- data/lib/rdoc/extend.rb +10 -0
- data/lib/rdoc/generator/darkfish.rb +790 -0
- data/lib/rdoc/generator/json_index.rb +300 -0
- data/lib/rdoc/generator/markup.rb +160 -0
- data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
- data/lib/rdoc/generator/pot/po.rb +84 -0
- data/lib/rdoc/generator/pot/po_entry.rb +141 -0
- data/lib/rdoc/generator/pot.rb +98 -0
- data/lib/rdoc/generator/ri.rb +31 -0
- data/lib/rdoc/generator/template/darkfish/.document +0 -0
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
- data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
- data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
- data/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
- data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
- data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -0
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +84 -0
- data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
- data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
- data/lib/rdoc/generator/template/json_index/.document +1 -0
- data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
- data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
- data/lib/rdoc/generator.rb +51 -0
- data/lib/rdoc/ghost_method.rb +7 -0
- data/lib/rdoc/i18n/locale.rb +102 -0
- data/lib/rdoc/i18n/text.rb +126 -0
- data/lib/rdoc/i18n.rb +10 -0
- data/lib/rdoc/include.rb +10 -0
- data/lib/rdoc/known_classes.rb +73 -0
- data/lib/rdoc/markdown/entities.rb +2132 -0
- data/lib/rdoc/markdown/literals.kpeg +23 -0
- data/lib/rdoc/markdown/literals.rb +417 -0
- data/lib/rdoc/markdown.kpeg +1237 -0
- data/lib/rdoc/markdown.rb +16685 -0
- data/lib/rdoc/markup/attr_changer.rb +23 -0
- data/lib/rdoc/markup/attr_span.rb +36 -0
- data/lib/rdoc/markup/attribute_manager.rb +409 -0
- data/lib/rdoc/markup/attributes.rb +71 -0
- data/lib/rdoc/markup/blank_line.rb +28 -0
- data/lib/rdoc/markup/block_quote.rb +15 -0
- data/lib/rdoc/markup/document.rb +165 -0
- data/lib/rdoc/markup/formatter.rb +266 -0
- data/lib/rdoc/markup/hard_break.rb +32 -0
- data/lib/rdoc/markup/heading.rb +79 -0
- data/lib/rdoc/markup/include.rb +43 -0
- data/lib/rdoc/markup/indented_paragraph.rb +48 -0
- data/lib/rdoc/markup/list.rb +102 -0
- data/lib/rdoc/markup/list_item.rb +100 -0
- data/lib/rdoc/markup/paragraph.rb +29 -0
- data/lib/rdoc/markup/parser.rb +575 -0
- data/lib/rdoc/markup/pre_process.rb +296 -0
- data/lib/rdoc/markup/raw.rb +70 -0
- data/lib/rdoc/markup/regexp_handling.rb +41 -0
- data/lib/rdoc/markup/rule.rb +21 -0
- data/lib/rdoc/markup/table.rb +47 -0
- data/lib/rdoc/markup/to_ansi.rb +94 -0
- data/lib/rdoc/markup/to_bs.rb +77 -0
- data/lib/rdoc/markup/to_html.rb +444 -0
- data/lib/rdoc/markup/to_html_crossref.rb +176 -0
- data/lib/rdoc/markup/to_html_snippet.rb +285 -0
- data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
- data/lib/rdoc/markup/to_label.rb +75 -0
- data/lib/rdoc/markup/to_markdown.rb +192 -0
- data/lib/rdoc/markup/to_rdoc.rb +362 -0
- data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
- data/lib/rdoc/markup/to_test.rb +70 -0
- data/lib/rdoc/markup/to_tt_only.rb +121 -0
- data/lib/rdoc/markup/verbatim.rb +84 -0
- data/lib/rdoc/markup.rb +867 -0
- data/lib/rdoc/meta_method.rb +7 -0
- data/lib/rdoc/method_attr.rb +419 -0
- data/lib/rdoc/mixin.rb +121 -0
- data/lib/rdoc/normal_class.rb +93 -0
- data/lib/rdoc/normal_module.rb +74 -0
- data/lib/rdoc/options.rb +1285 -0
- data/lib/rdoc/parser/c.rb +1225 -0
- data/lib/rdoc/parser/changelog.rb +335 -0
- data/lib/rdoc/parser/markdown.rb +24 -0
- data/lib/rdoc/parser/rd.rb +23 -0
- data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
- data/lib/rdoc/parser/ruby.rb +2327 -0
- data/lib/rdoc/parser/ruby_tools.rb +167 -0
- data/lib/rdoc/parser/simple.rb +61 -0
- data/lib/rdoc/parser/text.rb +12 -0
- data/lib/rdoc/parser.rb +277 -0
- data/lib/rdoc/rd/block_parser.rb +1056 -0
- data/lib/rdoc/rd/block_parser.ry +639 -0
- data/lib/rdoc/rd/inline.rb +72 -0
- data/lib/rdoc/rd/inline_parser.rb +1208 -0
- data/lib/rdoc/rd/inline_parser.ry +593 -0
- data/lib/rdoc/rd.rb +100 -0
- data/lib/rdoc/rdoc.rb +579 -0
- data/lib/rdoc/require.rb +52 -0
- data/lib/rdoc/ri/driver.rb +1572 -0
- data/lib/rdoc/ri/formatter.rb +6 -0
- data/lib/rdoc/ri/paths.rb +171 -0
- data/lib/rdoc/ri/store.rb +7 -0
- data/lib/rdoc/ri/task.rb +71 -0
- data/lib/rdoc/ri.rb +21 -0
- data/lib/rdoc/rubygems_hook.rb +246 -0
- data/lib/rdoc/servlet.rb +451 -0
- data/lib/rdoc/single_class.rb +26 -0
- data/lib/rdoc/stats/normal.rb +58 -0
- data/lib/rdoc/stats/quiet.rb +60 -0
- data/lib/rdoc/stats/verbose.rb +46 -0
- data/lib/rdoc/stats.rb +462 -0
- data/lib/rdoc/store.rb +979 -0
- data/lib/rdoc/task.rb +329 -0
- data/lib/rdoc/text.rb +304 -0
- data/lib/rdoc/token_stream.rb +119 -0
- data/lib/rdoc/tom_doc.rb +263 -0
- data/lib/rdoc/top_level.rb +289 -0
- data/lib/rdoc/version.rb +8 -0
- data/lib/rdoc.rb +201 -0
- data/man/ri.1 +247 -0
- data/rdoc.gemspec +249 -0
- metadata +279 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
##
|
3
|
+
# Extracts just the RDoc::Markup::Heading elements from a
|
4
|
+
# RDoc::Markup::Document to help build a table of contents
|
5
|
+
|
6
|
+
class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
|
7
|
+
|
8
|
+
@to_toc = nil
|
9
|
+
|
10
|
+
##
|
11
|
+
# Singleton for table-of-contents generation
|
12
|
+
|
13
|
+
def self.to_toc
|
14
|
+
@to_toc ||= new
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# Output accumulator
|
19
|
+
|
20
|
+
attr_reader :res
|
21
|
+
|
22
|
+
##
|
23
|
+
# Omits headings with a level less than the given level.
|
24
|
+
|
25
|
+
attr_accessor :omit_headings_below
|
26
|
+
|
27
|
+
def initialize # :nodoc:
|
28
|
+
super nil
|
29
|
+
|
30
|
+
@omit_headings_below = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Adds +document+ to the output, using its heading cutoff if present
|
35
|
+
|
36
|
+
def accept_document document
|
37
|
+
@omit_headings_below = document.omit_headings_below
|
38
|
+
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# Adds +heading+ to the table of contents
|
44
|
+
|
45
|
+
def accept_heading heading
|
46
|
+
@res << heading unless suppressed? heading
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Returns the table of contents
|
51
|
+
|
52
|
+
def end_accepting
|
53
|
+
@res
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Prepares the visitor for text generation
|
58
|
+
|
59
|
+
def start_accepting
|
60
|
+
@omit_headings_below = nil
|
61
|
+
@res = []
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Returns true if +heading+ is below the display threshold
|
66
|
+
|
67
|
+
def suppressed? heading
|
68
|
+
return false unless @omit_headings_below
|
69
|
+
|
70
|
+
heading.level > @omit_headings_below
|
71
|
+
end
|
72
|
+
|
73
|
+
# :stopdoc:
|
74
|
+
alias accept_block_quote ignore
|
75
|
+
alias accept_raw ignore
|
76
|
+
alias accept_rule ignore
|
77
|
+
alias accept_blank_line ignore
|
78
|
+
alias accept_paragraph ignore
|
79
|
+
alias accept_verbatim ignore
|
80
|
+
alias accept_list_end ignore
|
81
|
+
alias accept_list_item_start ignore
|
82
|
+
alias accept_list_item_end ignore
|
83
|
+
alias accept_list_end_bullet ignore
|
84
|
+
alias accept_list_start ignore
|
85
|
+
alias accept_table ignore
|
86
|
+
# :startdoc:
|
87
|
+
|
88
|
+
end
|
89
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
##
|
3
|
+
# This Markup outputter is used for testing purposes.
|
4
|
+
|
5
|
+
class RDoc::Markup::ToTest < RDoc::Markup::Formatter
|
6
|
+
|
7
|
+
# :stopdoc:
|
8
|
+
|
9
|
+
##
|
10
|
+
# :section: Visitor
|
11
|
+
|
12
|
+
def start_accepting
|
13
|
+
@res = []
|
14
|
+
@list = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def end_accepting
|
18
|
+
@res
|
19
|
+
end
|
20
|
+
|
21
|
+
def accept_paragraph(paragraph)
|
22
|
+
@res << convert_flow(@am.flow(paragraph.text))
|
23
|
+
end
|
24
|
+
|
25
|
+
def accept_raw raw
|
26
|
+
@res << raw.parts.join
|
27
|
+
end
|
28
|
+
|
29
|
+
def accept_verbatim(verbatim)
|
30
|
+
@res << verbatim.text.gsub(/^(\S)/, ' \1')
|
31
|
+
end
|
32
|
+
|
33
|
+
def accept_list_start(list)
|
34
|
+
@list << case list.type
|
35
|
+
when :BULLET then
|
36
|
+
'*'
|
37
|
+
when :NUMBER then
|
38
|
+
'1'
|
39
|
+
else
|
40
|
+
list.type
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def accept_list_end(list)
|
45
|
+
@list.pop
|
46
|
+
end
|
47
|
+
|
48
|
+
def accept_list_item_start(list_item)
|
49
|
+
@res << "#{' ' * (@list.size - 1)}#{@list.last}: "
|
50
|
+
end
|
51
|
+
|
52
|
+
def accept_list_item_end(list_item)
|
53
|
+
end
|
54
|
+
|
55
|
+
def accept_blank_line(blank_line)
|
56
|
+
@res << "\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
def accept_heading(heading)
|
60
|
+
@res << "#{'=' * heading.level} #{heading.text}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def accept_rule(rule)
|
64
|
+
@res << '-' * rule.weight
|
65
|
+
end
|
66
|
+
|
67
|
+
# :startdoc:
|
68
|
+
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
##
|
3
|
+
# Extracts sections of text enclosed in plus, tt or code. Used to discover
|
4
|
+
# undocumented parameters.
|
5
|
+
|
6
|
+
class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
|
7
|
+
|
8
|
+
##
|
9
|
+
# Stack of list types
|
10
|
+
|
11
|
+
attr_reader :list_type
|
12
|
+
|
13
|
+
##
|
14
|
+
# Output accumulator
|
15
|
+
|
16
|
+
attr_reader :res
|
17
|
+
|
18
|
+
##
|
19
|
+
# Creates a new tt-only formatter.
|
20
|
+
|
21
|
+
def initialize markup = nil
|
22
|
+
super nil, markup
|
23
|
+
|
24
|
+
add_tag :TT, nil, nil
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Adds tts from +block_quote+ to the output
|
29
|
+
|
30
|
+
def accept_block_quote block_quote
|
31
|
+
tt_sections block_quote.text
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Pops the list type for +list+ from #list_type
|
36
|
+
|
37
|
+
def accept_list_end list
|
38
|
+
@list_type.pop
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Pushes the list type for +list+ onto #list_type
|
43
|
+
|
44
|
+
def accept_list_start list
|
45
|
+
@list_type << list.type
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Prepares the visitor for consuming +list_item+
|
50
|
+
|
51
|
+
def accept_list_item_start list_item
|
52
|
+
case @list_type.last
|
53
|
+
when :NOTE, :LABEL then
|
54
|
+
Array(list_item.label).map do |label|
|
55
|
+
tt_sections label
|
56
|
+
end.flatten
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Adds +paragraph+ to the output
|
62
|
+
|
63
|
+
def accept_paragraph paragraph
|
64
|
+
tt_sections(paragraph.text)
|
65
|
+
end
|
66
|
+
|
67
|
+
##
|
68
|
+
# Does nothing to +markup_item+ because it doesn't have any user-built
|
69
|
+
# content
|
70
|
+
|
71
|
+
def do_nothing markup_item
|
72
|
+
end
|
73
|
+
|
74
|
+
alias accept_blank_line do_nothing # :nodoc:
|
75
|
+
alias accept_heading do_nothing # :nodoc:
|
76
|
+
alias accept_list_item_end do_nothing # :nodoc:
|
77
|
+
alias accept_raw do_nothing # :nodoc:
|
78
|
+
alias accept_rule do_nothing # :nodoc:
|
79
|
+
alias accept_verbatim do_nothing # :nodoc:
|
80
|
+
|
81
|
+
##
|
82
|
+
# Extracts tt sections from +text+
|
83
|
+
|
84
|
+
def tt_sections text
|
85
|
+
flow = @am.flow text.dup
|
86
|
+
|
87
|
+
flow.each do |item|
|
88
|
+
case item
|
89
|
+
when String then
|
90
|
+
@res << item if in_tt?
|
91
|
+
when RDoc::Markup::AttrChanger then
|
92
|
+
off_tags res, item
|
93
|
+
on_tags res, item
|
94
|
+
when RDoc::Markup::RegexpHandling then
|
95
|
+
@res << convert_regexp_handling(item) if in_tt? # TODO can this happen?
|
96
|
+
else
|
97
|
+
raise "Unknown flow element: #{item.inspect}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
res
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Returns an Array of items that were wrapped in plus, tt or code.
|
106
|
+
|
107
|
+
def end_accepting
|
108
|
+
@res.compact
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Prepares the visitor for gathering tt sections
|
113
|
+
|
114
|
+
def start_accepting
|
115
|
+
@res = []
|
116
|
+
|
117
|
+
@list_type = []
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
##
|
3
|
+
# A section of verbatim text
|
4
|
+
|
5
|
+
class RDoc::Markup::Verbatim < RDoc::Markup::Raw
|
6
|
+
|
7
|
+
##
|
8
|
+
# Format of this verbatim section
|
9
|
+
|
10
|
+
attr_accessor :format
|
11
|
+
|
12
|
+
def initialize *parts # :nodoc:
|
13
|
+
super
|
14
|
+
|
15
|
+
@format = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def == other # :nodoc:
|
19
|
+
super and @format == other.format
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Calls #accept_verbatim on +visitor+
|
24
|
+
|
25
|
+
def accept visitor
|
26
|
+
visitor.accept_verbatim self
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Collapses 3+ newlines into two newlines
|
31
|
+
|
32
|
+
def normalize
|
33
|
+
parts = []
|
34
|
+
|
35
|
+
newlines = 0
|
36
|
+
|
37
|
+
@parts.each do |part|
|
38
|
+
case part
|
39
|
+
when /^\s*\n/ then
|
40
|
+
newlines += 1
|
41
|
+
parts << part if newlines == 1
|
42
|
+
else
|
43
|
+
newlines = 0
|
44
|
+
parts << part
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
parts.pop if parts.last =~ /\A\r?\n\z/
|
49
|
+
|
50
|
+
@parts = parts
|
51
|
+
end
|
52
|
+
|
53
|
+
def pretty_print q # :nodoc:
|
54
|
+
self.class.name =~ /.*::(\w{1,4})/i
|
55
|
+
|
56
|
+
q.group 2, "[#{$1.downcase}: ", ']' do
|
57
|
+
if @format then
|
58
|
+
q.text "format: #{@format}"
|
59
|
+
q.breakable
|
60
|
+
end
|
61
|
+
|
62
|
+
q.seplist @parts do |part|
|
63
|
+
q.pp part
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Is this verbatim section Ruby code?
|
70
|
+
|
71
|
+
def ruby?
|
72
|
+
@format ||= nil # TODO for older ri data, switch the tree to marshal_dump
|
73
|
+
@format == :ruby
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# The text of the section
|
78
|
+
|
79
|
+
def text
|
80
|
+
@parts.join
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
data/lib/rdoc/markup.rb
ADDED
@@ -0,0 +1,867 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
##
|
3
|
+
# RDoc::Markup parses plain text documents and attempts to decompose them into
|
4
|
+
# their constituent parts. Some of these parts are high-level: paragraphs,
|
5
|
+
# chunks of verbatim text, list entries and the like. Other parts happen at
|
6
|
+
# the character level: a piece of bold text, a word in code font. This markup
|
7
|
+
# is similar in spirit to that used on WikiWiki webs, where folks create web
|
8
|
+
# pages using a simple set of formatting rules.
|
9
|
+
#
|
10
|
+
# RDoc::Markup and other markup formats do no output formatting, this is
|
11
|
+
# handled by the RDoc::Markup::Formatter subclasses.
|
12
|
+
#
|
13
|
+
# = Supported Formats
|
14
|
+
#
|
15
|
+
# Besides the RDoc::Markup format, the following formats are built in to RDoc:
|
16
|
+
#
|
17
|
+
# markdown::
|
18
|
+
# The markdown format as described by
|
19
|
+
# http://daringfireball.net/projects/markdown/. See RDoc::Markdown for
|
20
|
+
# details on the parser and supported extensions.
|
21
|
+
# rd::
|
22
|
+
# The rdtool format. See RDoc::RD for details on the parser and format.
|
23
|
+
# tomdoc::
|
24
|
+
# The TomDoc format as described by http://tomdoc.org/. See RDoc::TomDoc
|
25
|
+
# for details on the parser and supported extensions.
|
26
|
+
#
|
27
|
+
# You can choose a markup format using the following methods:
|
28
|
+
#
|
29
|
+
# per project::
|
30
|
+
# If you build your documentation with rake use RDoc::Task#markup.
|
31
|
+
#
|
32
|
+
# If you build your documentation by hand run:
|
33
|
+
#
|
34
|
+
# rdoc --markup your_favorite_format --write-options
|
35
|
+
#
|
36
|
+
# and commit <tt>.rdoc_options</tt> and ship it with your packaged gem.
|
37
|
+
# per file::
|
38
|
+
# At the top of the file use the <tt>:markup:</tt> directive to set the
|
39
|
+
# default format for the rest of the file.
|
40
|
+
# per comment::
|
41
|
+
# Use the <tt>:markup:</tt> directive at the top of a comment you want
|
42
|
+
# to write in a different format.
|
43
|
+
#
|
44
|
+
# = RDoc::Markup
|
45
|
+
#
|
46
|
+
# RDoc::Markup is extensible at runtime: you can add \new markup elements to
|
47
|
+
# be recognized in the documents that RDoc::Markup parses.
|
48
|
+
#
|
49
|
+
# RDoc::Markup is intended to be the basis for a family of tools which share
|
50
|
+
# the common requirement that simple, plain-text should be rendered in a
|
51
|
+
# variety of different output formats and media. It is envisaged that
|
52
|
+
# RDoc::Markup could be the basis for formatting RDoc style comment blocks,
|
53
|
+
# Wiki entries, and online FAQs.
|
54
|
+
#
|
55
|
+
# == Synopsis
|
56
|
+
#
|
57
|
+
# This code converts +input_string+ to HTML. The conversion takes place in
|
58
|
+
# the +convert+ method, so you can use the same RDoc::Markup converter to
|
59
|
+
# convert multiple input strings.
|
60
|
+
#
|
61
|
+
# require 'rdoc'
|
62
|
+
#
|
63
|
+
# h = RDoc::Markup::ToHtml.new(RDoc::Options.new)
|
64
|
+
#
|
65
|
+
# puts h.convert(input_string)
|
66
|
+
#
|
67
|
+
# You can extend the RDoc::Markup parser to recognize new markup
|
68
|
+
# sequences, and to add regexp handling. Here we make WikiWords significant to
|
69
|
+
# the parser, and also make the sequences {word} and \<no>text...</no> signify
|
70
|
+
# strike-through text. We then subclass the HTML output class to deal
|
71
|
+
# with these:
|
72
|
+
#
|
73
|
+
# require 'rdoc'
|
74
|
+
#
|
75
|
+
# class WikiHtml < RDoc::Markup::ToHtml
|
76
|
+
# def handle_regexp_WIKIWORD(target)
|
77
|
+
# "<font color=red>" + target.text + "</font>"
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# markup = RDoc::Markup.new
|
82
|
+
# markup.add_word_pair("{", "}", :STRIKE)
|
83
|
+
# markup.add_html("no", :STRIKE)
|
84
|
+
#
|
85
|
+
# markup.add_regexp_handling(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)
|
86
|
+
#
|
87
|
+
# wh = WikiHtml.new RDoc::Options.new, markup
|
88
|
+
# wh.add_tag(:STRIKE, "<strike>", "</strike>")
|
89
|
+
#
|
90
|
+
# puts "<body>#{wh.convert ARGF.read}</body>"
|
91
|
+
#
|
92
|
+
# == Encoding
|
93
|
+
#
|
94
|
+
# Where Encoding support is available, RDoc will automatically convert all
|
95
|
+
# documents to the same output encoding. The output encoding can be set via
|
96
|
+
# RDoc::Options#encoding and defaults to Encoding.default_external.
|
97
|
+
#
|
98
|
+
# = \RDoc Markup Reference
|
99
|
+
#
|
100
|
+
# == Block Markup
|
101
|
+
#
|
102
|
+
# === Paragraphs and Verbatim
|
103
|
+
#
|
104
|
+
# The markup engine looks for a document's natural left margin. This is
|
105
|
+
# used as the initial margin for the document.
|
106
|
+
#
|
107
|
+
# Consecutive lines starting at this margin are considered to be a
|
108
|
+
# paragraph. Empty lines separate paragraphs.
|
109
|
+
#
|
110
|
+
# Any line that starts to the right of the current margin is treated
|
111
|
+
# as verbatim text. This is useful for code listings:
|
112
|
+
#
|
113
|
+
# 3.times { puts "Ruby" }
|
114
|
+
#
|
115
|
+
# In verbatim text, two or more blank lines are collapsed into one,
|
116
|
+
# and trailing blank lines are removed:
|
117
|
+
#
|
118
|
+
# This is the first line
|
119
|
+
#
|
120
|
+
#
|
121
|
+
# This is the second non-blank line,
|
122
|
+
# after 2 blank lines in the source markup.
|
123
|
+
#
|
124
|
+
#
|
125
|
+
# There were two trailing blank lines right above this paragraph, that
|
126
|
+
# have been removed. In addition, the verbatim text has been shifted
|
127
|
+
# left, so the amount of indentation of verbatim text is unimportant.
|
128
|
+
#
|
129
|
+
# For HTML output RDoc makes a small effort to determine if a verbatim section
|
130
|
+
# contains Ruby source code. If so, the verbatim block will be marked up as
|
131
|
+
# HTML. Triggers include "def", "class", "module", "require", the "hash
|
132
|
+
# rocket"# (=>) or a block call with a parameter.
|
133
|
+
#
|
134
|
+
# === Headers
|
135
|
+
#
|
136
|
+
# A line starting with an equal sign (=) is treated as a
|
137
|
+
# heading. Level one headings have one equals sign, level two headings
|
138
|
+
# have two, and so on until level six, which is the maximum
|
139
|
+
# (seven hyphens or more result in a level six heading).
|
140
|
+
#
|
141
|
+
# For example, the above header was obtained with:
|
142
|
+
#
|
143
|
+
# === Headers
|
144
|
+
#
|
145
|
+
# In HTML output headers have an id matching their name. The above example's
|
146
|
+
# HTML is:
|
147
|
+
#
|
148
|
+
# <h3 id="label-Headers">Headers</h3>
|
149
|
+
#
|
150
|
+
# If a heading is inside a method body the id will be prefixed with the
|
151
|
+
# method's id. If the above header where in the documentation for a method
|
152
|
+
# such as:
|
153
|
+
#
|
154
|
+
# ##
|
155
|
+
# # This method does fun things
|
156
|
+
# #
|
157
|
+
# # = Example
|
158
|
+
# #
|
159
|
+
# # Example of fun things goes here ...
|
160
|
+
#
|
161
|
+
# def do_fun_things
|
162
|
+
# end
|
163
|
+
#
|
164
|
+
# The header's id would be:
|
165
|
+
#
|
166
|
+
# <h1 id="method-i-do_fun_things-label-Example">Example</h1>
|
167
|
+
#
|
168
|
+
# The label can be linked-to using <tt>SomeClass@Headers</tt>. See
|
169
|
+
# {Links}[RDoc::Markup@Links] for further details.
|
170
|
+
#
|
171
|
+
# === Rules
|
172
|
+
#
|
173
|
+
# A line starting with three or more hyphens (at the current indent)
|
174
|
+
# generates a horizontal rule.
|
175
|
+
#
|
176
|
+
# ---
|
177
|
+
#
|
178
|
+
# produces:
|
179
|
+
#
|
180
|
+
# ---
|
181
|
+
#
|
182
|
+
# === Simple Lists
|
183
|
+
#
|
184
|
+
# If a paragraph starts with a "*", "-", "<digit>." or "<letter>.",
|
185
|
+
# then it is taken to be the start of a list. The margin is increased to be
|
186
|
+
# the first non-space following the list start flag. Subsequent lines
|
187
|
+
# should be indented to this new margin until the list ends. For example:
|
188
|
+
#
|
189
|
+
# * this is a list with three paragraphs in
|
190
|
+
# the first item. This is the first paragraph.
|
191
|
+
#
|
192
|
+
# And this is the second paragraph.
|
193
|
+
#
|
194
|
+
# 1. This is an indented, numbered list.
|
195
|
+
# 2. This is the second item in that list
|
196
|
+
#
|
197
|
+
# This is the third conventional paragraph in the
|
198
|
+
# first list item.
|
199
|
+
#
|
200
|
+
# * This is the second item in the original list
|
201
|
+
#
|
202
|
+
# produces:
|
203
|
+
#
|
204
|
+
# * this is a list with three paragraphs in
|
205
|
+
# the first item. This is the first paragraph.
|
206
|
+
#
|
207
|
+
# And this is the second paragraph.
|
208
|
+
#
|
209
|
+
# 1. This is an indented, numbered list.
|
210
|
+
# 2. This is the second item in that list
|
211
|
+
#
|
212
|
+
# This is the third conventional paragraph in the
|
213
|
+
# first list item.
|
214
|
+
#
|
215
|
+
# * This is the second item in the original list
|
216
|
+
#
|
217
|
+
# === Labeled Lists
|
218
|
+
#
|
219
|
+
# You can also construct labeled lists, sometimes called description
|
220
|
+
# or definition lists. Do this by putting the label in square brackets
|
221
|
+
# and indenting the list body:
|
222
|
+
#
|
223
|
+
# [cat] a small furry mammal
|
224
|
+
# that seems to sleep a lot
|
225
|
+
#
|
226
|
+
# [ant] a little insect that is known
|
227
|
+
# to enjoy picnics
|
228
|
+
#
|
229
|
+
# produces:
|
230
|
+
#
|
231
|
+
# [cat] a small furry mammal
|
232
|
+
# that seems to sleep a lot
|
233
|
+
#
|
234
|
+
# [ant] a little insect that is known
|
235
|
+
# to enjoy picnics
|
236
|
+
#
|
237
|
+
# If you want the list bodies to line up to the left of the labels,
|
238
|
+
# use two colons:
|
239
|
+
#
|
240
|
+
# cat:: a small furry mammal
|
241
|
+
# that seems to sleep a lot
|
242
|
+
#
|
243
|
+
# ant:: a little insect that is known
|
244
|
+
# to enjoy picnics
|
245
|
+
#
|
246
|
+
# produces:
|
247
|
+
#
|
248
|
+
# cat:: a small furry mammal
|
249
|
+
# that seems to sleep a lot
|
250
|
+
#
|
251
|
+
# ant:: a little insect that is known
|
252
|
+
# to enjoy picnics
|
253
|
+
#
|
254
|
+
# Notice that blank lines right after the label are ignored in labeled lists:
|
255
|
+
#
|
256
|
+
# [one]
|
257
|
+
#
|
258
|
+
# definition 1
|
259
|
+
#
|
260
|
+
# [two]
|
261
|
+
#
|
262
|
+
# definition 2
|
263
|
+
#
|
264
|
+
# produces the same output as
|
265
|
+
#
|
266
|
+
# [one] definition 1
|
267
|
+
# [two] definition 2
|
268
|
+
#
|
269
|
+
#
|
270
|
+
# === Lists and Verbatim
|
271
|
+
#
|
272
|
+
# If you want to introduce a verbatim section right after a list, it has to be
|
273
|
+
# less indented than the list item bodies, but more indented than the list
|
274
|
+
# label, letter, digit or bullet. For instance:
|
275
|
+
#
|
276
|
+
# * point 1
|
277
|
+
#
|
278
|
+
# * point 2, first paragraph
|
279
|
+
#
|
280
|
+
# point 2, second paragraph
|
281
|
+
# verbatim text inside point 2
|
282
|
+
# point 2, third paragraph
|
283
|
+
# verbatim text outside of the list (the list is therefore closed)
|
284
|
+
# regular paragraph after the list
|
285
|
+
#
|
286
|
+
# produces:
|
287
|
+
#
|
288
|
+
# * point 1
|
289
|
+
#
|
290
|
+
# * point 2, first paragraph
|
291
|
+
#
|
292
|
+
# point 2, second paragraph
|
293
|
+
# verbatim text inside point 2
|
294
|
+
# point 2, third paragraph
|
295
|
+
# verbatim text outside of the list (the list is therefore closed)
|
296
|
+
# regular paragraph after the list
|
297
|
+
#
|
298
|
+
# == Text Markup
|
299
|
+
#
|
300
|
+
# === Bold, Italic, Typewriter Text
|
301
|
+
#
|
302
|
+
# You can use markup within text (except verbatim) to change the
|
303
|
+
# appearance of parts of that text. Out of the box, RDoc::Markup
|
304
|
+
# supports word-based and general markup.
|
305
|
+
#
|
306
|
+
# Word-based markup uses flag characters around individual words:
|
307
|
+
#
|
308
|
+
# <tt>\*_word_\*</tt>:: displays _word_ in a *bold* font
|
309
|
+
# <tt>\__word_\_</tt>:: displays _word_ in an _emphasized_ font
|
310
|
+
# <tt>\+_word_\+</tt>:: displays _word_ in a +code+ font
|
311
|
+
#
|
312
|
+
# General markup affects text between a start delimiter and an end
|
313
|
+
# delimiter. Not surprisingly, these delimiters look like HTML markup.
|
314
|
+
#
|
315
|
+
# <tt>\<b>_text_</b></tt>:: displays _text_ in a *bold* font
|
316
|
+
# <tt>\<em>_text_</em></tt>:: displays _text_ in an _emphasized_ font
|
317
|
+
# (alternate tag: <tt>\<i></tt>)
|
318
|
+
# <tt>\<tt>_text_\</tt></tt>:: displays _text_ in a +code+ font
|
319
|
+
# (alternate tag: <tt>\<code></tt>)
|
320
|
+
#
|
321
|
+
# Unlike conventional Wiki markup, general markup can cross line
|
322
|
+
# boundaries. You can turn off the interpretation of markup by
|
323
|
+
# preceding the first character with a backslash (see <i>Escaping
|
324
|
+
# Text Markup</i>, below).
|
325
|
+
#
|
326
|
+
# === Links
|
327
|
+
#
|
328
|
+
# Links to starting with +http:+, +https:+, +mailto:+, +ftp:+ or +www.+
|
329
|
+
# are recognized. An HTTP url that references an external image is converted
|
330
|
+
# into an inline image element.
|
331
|
+
#
|
332
|
+
# Classes and methods will be automatically linked to their definition. For
|
333
|
+
# example, <tt>RDoc::Markup</tt> will link to this documentation. By default
|
334
|
+
# methods will only be automatically linked if they contain an <tt>_</tt> (all
|
335
|
+
# methods can be automatically linked through the <tt>--hyperlink-all</tt>
|
336
|
+
# command line option).
|
337
|
+
#
|
338
|
+
# Single-word methods can be linked by using the <tt>#</tt> character for
|
339
|
+
# instance methods or <tt>::</tt> for class methods. For example,
|
340
|
+
# <tt>#convert</tt> links to #convert. A class or method may be combined like
|
341
|
+
# <tt>RDoc::Markup#convert</tt>.
|
342
|
+
#
|
343
|
+
# A heading inside the documentation can be linked by following the class
|
344
|
+
# or method by an <tt>@</tt> then the heading name.
|
345
|
+
# <tt>RDoc::Markup@Links</tt> will link to this section like this:
|
346
|
+
# RDoc::Markup@Links. Spaces in headings with multiple words must be escaped
|
347
|
+
# with <tt>+</tt> like <tt>RDoc::Markup@Escaping+Text+Markup</tt>.
|
348
|
+
# Punctuation and other special characters must be escaped like CGI.escape.
|
349
|
+
#
|
350
|
+
# The <tt>@</tt> can also be used to link to sections. If a section and a
|
351
|
+
# heading share the same name the section is preferred for the link.
|
352
|
+
#
|
353
|
+
# Links can also be of the form <tt>label[url]</tt>, in which case +label+ is
|
354
|
+
# used in the displayed text, and +url+ is used as the target. If +label+
|
355
|
+
# contains multiple words, put it in braces: <tt>{multi word label}[url]</tt>.
|
356
|
+
# The +url+ may be an +http:+-type link or a cross-reference to a class,
|
357
|
+
# module or method with a label.
|
358
|
+
#
|
359
|
+
# Links with the <code>rdoc-image:</code> scheme will create an image tag for
|
360
|
+
# HTML output. Only fully-qualified URLs are supported.
|
361
|
+
#
|
362
|
+
# Links with the <tt>rdoc-ref:</tt> scheme will link to the referenced class,
|
363
|
+
# module, method, file, etc. If the referenced item is does not exist
|
364
|
+
# no link will be generated and <tt>rdoc-ref:</tt> will be removed from the
|
365
|
+
# resulting text.
|
366
|
+
#
|
367
|
+
# Links starting with <tt>rdoc-label:label_name</tt> will link to the
|
368
|
+
# +label_name+. You can create a label for the current link (for
|
369
|
+
# bidirectional links) by supplying a name for the current link like
|
370
|
+
# <tt>rdoc-label:label-other:label-mine</tt>.
|
371
|
+
#
|
372
|
+
# Links starting with +link:+ refer to local files whose path is relative to
|
373
|
+
# the <tt>--op</tt> directory. Use <tt>rdoc-ref:</tt> instead of
|
374
|
+
# <tt>link:</tt> to link to files generated by RDoc as the link target may
|
375
|
+
# be different across RDoc generators.
|
376
|
+
#
|
377
|
+
# Example links:
|
378
|
+
#
|
379
|
+
# https://github.com/ruby/rdoc
|
380
|
+
# mailto:user@example.com
|
381
|
+
# {RDoc Documentation}[http://rdoc.rubyforge.org]
|
382
|
+
# {RDoc Markup}[rdoc-ref:RDoc::Markup]
|
383
|
+
#
|
384
|
+
# === Escaping Text Markup
|
385
|
+
#
|
386
|
+
# Text markup can be escaped with a backslash, as in \<tt>, which was obtained
|
387
|
+
# with <tt>\\<tt></tt>. Except in verbatim sections and between \<tt> tags,
|
388
|
+
# to produce a backslash you have to double it unless it is followed by a
|
389
|
+
# space, tab or newline. Otherwise, the HTML formatter will discard it, as it
|
390
|
+
# is used to escape potential links:
|
391
|
+
#
|
392
|
+
# * The \ must be doubled if not followed by white space: \\.
|
393
|
+
# * But not in \<tt> tags: in a Regexp, <tt>\S</tt> matches non-space.
|
394
|
+
# * This is a link to {ruby-lang}[www.ruby-lang.org].
|
395
|
+
# * This is not a link, however: \{ruby-lang.org}[www.ruby-lang.org].
|
396
|
+
# * This will not be linked to \RDoc::RDoc#document
|
397
|
+
#
|
398
|
+
# generates:
|
399
|
+
#
|
400
|
+
# * The \ must be doubled if not followed by white space: \\.
|
401
|
+
# * But not in \<tt> tags: in a Regexp, <tt>\S</tt> matches non-space.
|
402
|
+
# * This is a link to {ruby-lang}[www.ruby-lang.org]
|
403
|
+
# * This is not a link, however: \{ruby-lang.org}[www.ruby-lang.org]
|
404
|
+
# * This will not be linked to \RDoc::RDoc#document
|
405
|
+
#
|
406
|
+
# Inside \<tt> tags, more precisely, leading backslashes are removed only if
|
407
|
+
# followed by a markup character (<tt><*_+</tt>), a backslash, or a known link
|
408
|
+
# reference (a known class or method). So in the example above, the backslash
|
409
|
+
# of <tt>\S</tt> would be removed if there was a class or module named +S+ in
|
410
|
+
# the current context.
|
411
|
+
#
|
412
|
+
# This behavior is inherited from RDoc version 1, and has been kept for
|
413
|
+
# compatibility with existing RDoc documentation.
|
414
|
+
#
|
415
|
+
# === Conversion of characters
|
416
|
+
#
|
417
|
+
# HTML will convert two/three dashes to an em-dash. Other common characters are
|
418
|
+
# converted as well:
|
419
|
+
#
|
420
|
+
# em-dash:: -- or ---
|
421
|
+
# ellipsis:: ...
|
422
|
+
#
|
423
|
+
# single quotes:: 'text' or `text'
|
424
|
+
# double quotes:: "text" or ``text''
|
425
|
+
#
|
426
|
+
# copyright:: (c)
|
427
|
+
# registered trademark:: (r)
|
428
|
+
#
|
429
|
+
# produces:
|
430
|
+
#
|
431
|
+
# em-dash:: -- or ---
|
432
|
+
# ellipsis:: ...
|
433
|
+
#
|
434
|
+
# single quotes:: 'text' or `text'
|
435
|
+
# double quotes:: "text" or ``text''
|
436
|
+
#
|
437
|
+
# copyright:: (c)
|
438
|
+
# registered trademark:: (r)
|
439
|
+
#
|
440
|
+
#
|
441
|
+
# == Documenting Source Code
|
442
|
+
#
|
443
|
+
# Comment blocks can be written fairly naturally, either using <tt>#</tt> on
|
444
|
+
# successive lines of the comment, or by including the comment in
|
445
|
+
# a <tt>=begin</tt>/<tt>=end</tt> block. If you use the latter form,
|
446
|
+
# the <tt>=begin</tt> line _must_ be flagged with an +rdoc+ tag:
|
447
|
+
#
|
448
|
+
# =begin rdoc
|
449
|
+
# Documentation to be processed by RDoc.
|
450
|
+
#
|
451
|
+
# ...
|
452
|
+
# =end
|
453
|
+
#
|
454
|
+
# RDoc stops processing comments if it finds a comment line starting
|
455
|
+
# with <tt>--</tt> right after the <tt>#</tt> character (otherwise,
|
456
|
+
# it will be treated as a rule if it has three dashes or more).
|
457
|
+
# This can be used to separate external from internal comments,
|
458
|
+
# or to stop a comment being associated with a method, class, or module.
|
459
|
+
# Commenting can be turned back on with a line that starts with <tt>++</tt>.
|
460
|
+
#
|
461
|
+
# ##
|
462
|
+
# # Extract the age and calculate the date-of-birth.
|
463
|
+
# #--
|
464
|
+
# # FIXME: fails if the birthday falls on February 29th
|
465
|
+
# #++
|
466
|
+
# # The DOB is returned as a Time object.
|
467
|
+
#
|
468
|
+
# def get_dob(person)
|
469
|
+
# # ...
|
470
|
+
# end
|
471
|
+
#
|
472
|
+
# Names of classes, files, and any method names containing an underscore or
|
473
|
+
# preceded by a hash character are automatically linked from comment text to
|
474
|
+
# their description. This linking works inside the current class or module,
|
475
|
+
# and with ancestor methods (in included modules or in the superclass).
|
476
|
+
#
|
477
|
+
# Method parameter lists are extracted and displayed with the method
|
478
|
+
# description. If a method calls +yield+, then the parameters passed to yield
|
479
|
+
# will also be displayed:
|
480
|
+
#
|
481
|
+
# def fred
|
482
|
+
# ...
|
483
|
+
# yield line, address
|
484
|
+
#
|
485
|
+
# This will get documented as:
|
486
|
+
#
|
487
|
+
# fred() { |line, address| ... }
|
488
|
+
#
|
489
|
+
# You can override this using a comment containing ':yields: ...' immediately
|
490
|
+
# after the method definition
|
491
|
+
#
|
492
|
+
# def fred # :yields: index, position
|
493
|
+
# # ...
|
494
|
+
#
|
495
|
+
# yield line, address
|
496
|
+
#
|
497
|
+
# which will get documented as
|
498
|
+
#
|
499
|
+
# fred() { |index, position| ... }
|
500
|
+
#
|
501
|
+
# +:yields:+ is an example of a documentation directive. These appear
|
502
|
+
# immediately after the start of the document element they are modifying.
|
503
|
+
#
|
504
|
+
# RDoc automatically cross-references words with underscores or camel-case.
|
505
|
+
# To suppress cross-references, prefix the word with a \ character. To
|
506
|
+
# include special characters like "<tt>\n</tt>", you'll need to use
|
507
|
+
# two \ characters in normal text, but only one in \<tt> text:
|
508
|
+
#
|
509
|
+
# "\\n" or "<tt>\n</tt>"
|
510
|
+
#
|
511
|
+
# produces:
|
512
|
+
#
|
513
|
+
# "\\n" or "<tt>\n</tt>"
|
514
|
+
#
|
515
|
+
# == Directives
|
516
|
+
#
|
517
|
+
# Directives are keywords surrounded by ":" characters.
|
518
|
+
#
|
519
|
+
# === Controlling what is documented
|
520
|
+
#
|
521
|
+
# [+:nodoc:+ / <tt>:nodoc: all</tt>]
|
522
|
+
# This directive prevents documentation for the element from
|
523
|
+
# being generated. For classes and modules, methods, aliases,
|
524
|
+
# constants, and attributes directly within the affected class or
|
525
|
+
# module also will be omitted. By default, though, modules and
|
526
|
+
# classes within that class or module _will_ be documented. This is
|
527
|
+
# turned off by adding the +all+ modifier.
|
528
|
+
#
|
529
|
+
# module MyModule # :nodoc:
|
530
|
+
# class Input
|
531
|
+
# end
|
532
|
+
# end
|
533
|
+
#
|
534
|
+
# module OtherModule # :nodoc: all
|
535
|
+
# class Output
|
536
|
+
# end
|
537
|
+
# end
|
538
|
+
#
|
539
|
+
# In the above code, only class <tt>MyModule::Input</tt> will be documented.
|
540
|
+
#
|
541
|
+
# The +:nodoc:+ directive, like +:enddoc:+, +:stopdoc:+ and +:startdoc:+
|
542
|
+
# presented below, is local to the current file: if you do not want to
|
543
|
+
# document a module that appears in several files, specify +:nodoc:+ on each
|
544
|
+
# appearance, at least once per file.
|
545
|
+
#
|
546
|
+
# [+:stopdoc:+ / +:startdoc:+]
|
547
|
+
# Stop and start adding new documentation elements to the current container.
|
548
|
+
# For example, if a class has a number of constants that you don't want to
|
549
|
+
# document, put a +:stopdoc:+ before the first, and a +:startdoc:+ after the
|
550
|
+
# last. If you don't specify a +:startdoc:+ by the end of the container,
|
551
|
+
# disables documentation for the rest of the current file.
|
552
|
+
#
|
553
|
+
# [+:doc:+]
|
554
|
+
# Forces a method or attribute to be documented even if it wouldn't be
|
555
|
+
# otherwise. Useful if, for example, you want to include documentation of a
|
556
|
+
# particular private method.
|
557
|
+
#
|
558
|
+
# [+:enddoc:+]
|
559
|
+
# Document nothing further at the current level: directives +:startdoc:+ and
|
560
|
+
# +:doc:+ that appear after this will not be honored for the current container
|
561
|
+
# (file, class or module), in the current file.
|
562
|
+
#
|
563
|
+
# [+:notnew:+ / +:not_new:+ / +:not-new:+ ]
|
564
|
+
# Only applicable to the +initialize+ instance method. Normally RDoc
|
565
|
+
# assumes that the documentation and parameters for +initialize+ are
|
566
|
+
# actually for the +new+ method, and so fakes out a +new+ for the class.
|
567
|
+
# The +:notnew:+ directive stops this. Remember that +initialize+ is private,
|
568
|
+
# so you won't see the documentation unless you use the +-a+ command line
|
569
|
+
# option.
|
570
|
+
#
|
571
|
+
# === Method arguments
|
572
|
+
#
|
573
|
+
# [+:arg:+ or +:args:+ _parameters_]
|
574
|
+
# Overrides the default argument handling with exactly these parameters.
|
575
|
+
#
|
576
|
+
# ##
|
577
|
+
# # :args: a, b
|
578
|
+
#
|
579
|
+
# def some_method(*a)
|
580
|
+
# end
|
581
|
+
#
|
582
|
+
# [+:yield:+ or +:yields:+ _parameters_]
|
583
|
+
# Overrides the default yield discovery with these parameters.
|
584
|
+
#
|
585
|
+
# ##
|
586
|
+
# # :yields: key, value
|
587
|
+
#
|
588
|
+
# def each_thing &block
|
589
|
+
# @things.each(&block)
|
590
|
+
# end
|
591
|
+
#
|
592
|
+
# [+:call-seq:+]
|
593
|
+
# Lines up to the next blank line or lines with a common prefix in the
|
594
|
+
# comment are treated as the method's calling sequence, overriding the
|
595
|
+
# default parsing of method parameters and yield arguments.
|
596
|
+
#
|
597
|
+
# Multiple lines may be used.
|
598
|
+
#
|
599
|
+
# # :call-seq:
|
600
|
+
# # ARGF.readlines(sep=$/) -> array
|
601
|
+
# # ARGF.readlines(limit) -> array
|
602
|
+
# # ARGF.readlines(sep, limit) -> array
|
603
|
+
# #
|
604
|
+
# # ARGF.to_a(sep=$/) -> array
|
605
|
+
# # ARGF.to_a(limit) -> array
|
606
|
+
# # ARGF.to_a(sep, limit) -> array
|
607
|
+
# #
|
608
|
+
# # The remaining lines are documentation ...
|
609
|
+
#
|
610
|
+
# === Sections
|
611
|
+
#
|
612
|
+
# Sections allow you to group methods in a class into sensible containers. If
|
613
|
+
# you use the sections 'Public', 'Internal' and 'Deprecated' (the three
|
614
|
+
# allowed method statuses from TomDoc) the sections will be displayed in that
|
615
|
+
# order placing the most useful methods at the top. Otherwise, sections will
|
616
|
+
# be displayed in alphabetical order.
|
617
|
+
#
|
618
|
+
# [+:category:+ _section_]
|
619
|
+
# Adds this item to the named +section+ overriding the current section. Use
|
620
|
+
# this to group methods by section in RDoc output while maintaining a
|
621
|
+
# sensible ordering (like alphabetical).
|
622
|
+
#
|
623
|
+
# # :category: Utility Methods
|
624
|
+
# #
|
625
|
+
# # CGI escapes +text+
|
626
|
+
#
|
627
|
+
# def convert_string text
|
628
|
+
# CGI.escapeHTML text
|
629
|
+
# end
|
630
|
+
#
|
631
|
+
# An empty category will place the item in the default category:
|
632
|
+
#
|
633
|
+
# # :category:
|
634
|
+
# #
|
635
|
+
# # This method is in the default category
|
636
|
+
#
|
637
|
+
# def some_method
|
638
|
+
# # ...
|
639
|
+
# end
|
640
|
+
#
|
641
|
+
# Unlike the :section: directive, :category: is not sticky. The category
|
642
|
+
# only applies to the item immediately following the comment.
|
643
|
+
#
|
644
|
+
# Use the :section: directive to provide introductory text for a section of
|
645
|
+
# documentation.
|
646
|
+
#
|
647
|
+
# [+:section:+ _title_]
|
648
|
+
# Provides section introductory text in RDoc output. The title following
|
649
|
+
# +:section:+ is used as the section name and the remainder of the comment
|
650
|
+
# containing the section is used as introductory text. A section's comment
|
651
|
+
# block must be separated from following comment blocks. Use an empty title
|
652
|
+
# to switch to the default section.
|
653
|
+
#
|
654
|
+
# The :section: directive is sticky, so subsequent methods, aliases,
|
655
|
+
# attributes, and classes will be contained in this section until the
|
656
|
+
# section is changed. The :category: directive will override the :section:
|
657
|
+
# directive.
|
658
|
+
#
|
659
|
+
# A :section: comment block may have one or more lines before the :section:
|
660
|
+
# directive. These will be removed, and any identical lines at the end of
|
661
|
+
# the block are also removed. This allows you to add visual cues to the
|
662
|
+
# section.
|
663
|
+
#
|
664
|
+
# Example:
|
665
|
+
#
|
666
|
+
# # ----------------------------------------
|
667
|
+
# # :section: My Section
|
668
|
+
# # This is the section that I wrote.
|
669
|
+
# # See it glisten in the noon-day sun.
|
670
|
+
# # ----------------------------------------
|
671
|
+
#
|
672
|
+
# ##
|
673
|
+
# # Comment for some_method
|
674
|
+
#
|
675
|
+
# def some_method
|
676
|
+
# # ...
|
677
|
+
# end
|
678
|
+
#
|
679
|
+
# === Other directives
|
680
|
+
#
|
681
|
+
# [+:markup:+ _type_]
|
682
|
+
# Overrides the default markup type for this comment with the specified
|
683
|
+
# markup type. For Ruby files, if the first comment contains this directive
|
684
|
+
# it is applied automatically to all comments in the file.
|
685
|
+
#
|
686
|
+
# Unless you are converting between markup formats you should use a
|
687
|
+
# <code>.rdoc_options</code> file to specify the default documentation
|
688
|
+
# format for your entire project. See RDoc::Options@Saved+Options for
|
689
|
+
# instructions.
|
690
|
+
#
|
691
|
+
# At the top of a file the +:markup:+ directive applies to the entire file:
|
692
|
+
#
|
693
|
+
# # coding: UTF-8
|
694
|
+
# # :markup: TomDoc
|
695
|
+
#
|
696
|
+
# # TomDoc comment here ...
|
697
|
+
#
|
698
|
+
# class MyClass
|
699
|
+
# # ...
|
700
|
+
#
|
701
|
+
# For just one comment:
|
702
|
+
#
|
703
|
+
# # ...
|
704
|
+
# end
|
705
|
+
#
|
706
|
+
# # :markup: RDoc
|
707
|
+
# #
|
708
|
+
# # This is a comment in RDoc markup format ...
|
709
|
+
#
|
710
|
+
# def some_method
|
711
|
+
# # ...
|
712
|
+
#
|
713
|
+
# See Markup@CONTRIBUTING for instructions on adding a new markup format.
|
714
|
+
#
|
715
|
+
# [+:include:+ _filename_]
|
716
|
+
# Include the contents of the named file at this point. This directive
|
717
|
+
# must appear alone on one line, possibly preceded by spaces. In this
|
718
|
+
# position, it can be escaped with a \ in front of the first colon.
|
719
|
+
#
|
720
|
+
# The file will be searched for in the directories listed by the +--include+
|
721
|
+
# option, or in the current directory by default. The contents of the file
|
722
|
+
# will be shifted to have the same indentation as the ':' at the start of
|
723
|
+
# the +:include:+ directive.
|
724
|
+
#
|
725
|
+
# [+:title:+ _text_]
|
726
|
+
# Sets the title for the document. Equivalent to the <tt>--title</tt>
|
727
|
+
# command line parameter. (The command line parameter overrides any :title:
|
728
|
+
# directive in the source).
|
729
|
+
#
|
730
|
+
# [+:main:+ _name_]
|
731
|
+
# Equivalent to the <tt>--main</tt> command line parameter.
|
732
|
+
#
|
733
|
+
#--
|
734
|
+
# Original Author:: Dave Thomas, dave@pragmaticprogrammer.com
|
735
|
+
# License:: Ruby license
|
736
|
+
|
737
|
+
class RDoc::Markup
|
738
|
+
|
739
|
+
##
|
740
|
+
# An AttributeManager which handles inline markup.
|
741
|
+
|
742
|
+
attr_reader :attribute_manager
|
743
|
+
|
744
|
+
##
|
745
|
+
# Parses +str+ into an RDoc::Markup::Document.
|
746
|
+
|
747
|
+
def self.parse str
|
748
|
+
RDoc::Markup::Parser.parse str
|
749
|
+
rescue RDoc::Markup::Parser::Error => e
|
750
|
+
$stderr.puts <<-EOF
|
751
|
+
While parsing markup, RDoc encountered a #{e.class}:
|
752
|
+
|
753
|
+
#{e}
|
754
|
+
\tfrom #{e.backtrace.join "\n\tfrom "}
|
755
|
+
|
756
|
+
---8<---
|
757
|
+
#{text}
|
758
|
+
---8<---
|
759
|
+
|
760
|
+
RDoc #{RDoc::VERSION}
|
761
|
+
|
762
|
+
Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} #{RUBY_RELEASE_DATE}
|
763
|
+
|
764
|
+
Please file a bug report with the above information at:
|
765
|
+
|
766
|
+
https://github.com/ruby/rdoc/issues
|
767
|
+
|
768
|
+
EOF
|
769
|
+
raise
|
770
|
+
end
|
771
|
+
|
772
|
+
##
|
773
|
+
# Take a block of text and use various heuristics to determine its
|
774
|
+
# structure (paragraphs, lists, and so on). Invoke an event handler as we
|
775
|
+
# identify significant chunks.
|
776
|
+
|
777
|
+
def initialize attribute_manager = nil
|
778
|
+
@attribute_manager = attribute_manager || RDoc::Markup::AttributeManager.new
|
779
|
+
@output = nil
|
780
|
+
end
|
781
|
+
|
782
|
+
##
|
783
|
+
# Add to the sequences used to add formatting to an individual word (such
|
784
|
+
# as *bold*). Matching entries will generate attributes that the output
|
785
|
+
# formatters can recognize by their +name+.
|
786
|
+
|
787
|
+
def add_word_pair(start, stop, name)
|
788
|
+
@attribute_manager.add_word_pair(start, stop, name)
|
789
|
+
end
|
790
|
+
|
791
|
+
##
|
792
|
+
# Add to the sequences recognized as general markup.
|
793
|
+
|
794
|
+
def add_html(tag, name)
|
795
|
+
@attribute_manager.add_html(tag, name)
|
796
|
+
end
|
797
|
+
|
798
|
+
##
|
799
|
+
# Add to other inline sequences. For example, we could add WikiWords using
|
800
|
+
# something like:
|
801
|
+
#
|
802
|
+
# parser.add_regexp_handling(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)
|
803
|
+
#
|
804
|
+
# Each wiki word will be presented to the output formatter.
|
805
|
+
|
806
|
+
def add_regexp_handling(pattern, name)
|
807
|
+
@attribute_manager.add_regexp_handling(pattern, name)
|
808
|
+
end
|
809
|
+
|
810
|
+
##
|
811
|
+
# We take +input+, parse it if necessary, then invoke the output +formatter+
|
812
|
+
# using a Visitor to render the result.
|
813
|
+
|
814
|
+
def convert input, formatter
|
815
|
+
document = case input
|
816
|
+
when RDoc::Markup::Document then
|
817
|
+
input
|
818
|
+
else
|
819
|
+
RDoc::Markup::Parser.parse input
|
820
|
+
end
|
821
|
+
|
822
|
+
document.accept formatter
|
823
|
+
end
|
824
|
+
|
825
|
+
autoload :Parser, 'rdoc/markup/parser'
|
826
|
+
autoload :PreProcess, 'rdoc/markup/pre_process'
|
827
|
+
|
828
|
+
# Inline markup classes
|
829
|
+
autoload :AttrChanger, 'rdoc/markup/attr_changer'
|
830
|
+
autoload :AttrSpan, 'rdoc/markup/attr_span'
|
831
|
+
autoload :Attributes, 'rdoc/markup/attributes'
|
832
|
+
autoload :AttributeManager, 'rdoc/markup/attribute_manager'
|
833
|
+
autoload :RegexpHandling, 'rdoc/markup/regexp_handling'
|
834
|
+
|
835
|
+
# RDoc::Markup AST
|
836
|
+
autoload :BlankLine, 'rdoc/markup/blank_line'
|
837
|
+
autoload :BlockQuote, 'rdoc/markup/block_quote'
|
838
|
+
autoload :Document, 'rdoc/markup/document'
|
839
|
+
autoload :HardBreak, 'rdoc/markup/hard_break'
|
840
|
+
autoload :Heading, 'rdoc/markup/heading'
|
841
|
+
autoload :Include, 'rdoc/markup/include'
|
842
|
+
autoload :IndentedParagraph, 'rdoc/markup/indented_paragraph'
|
843
|
+
autoload :List, 'rdoc/markup/list'
|
844
|
+
autoload :ListItem, 'rdoc/markup/list_item'
|
845
|
+
autoload :Paragraph, 'rdoc/markup/paragraph'
|
846
|
+
autoload :Table, 'rdoc/markup/table'
|
847
|
+
autoload :Raw, 'rdoc/markup/raw'
|
848
|
+
autoload :Rule, 'rdoc/markup/rule'
|
849
|
+
autoload :Verbatim, 'rdoc/markup/verbatim'
|
850
|
+
|
851
|
+
# Formatters
|
852
|
+
autoload :Formatter, 'rdoc/markup/formatter'
|
853
|
+
|
854
|
+
autoload :ToAnsi, 'rdoc/markup/to_ansi'
|
855
|
+
autoload :ToBs, 'rdoc/markup/to_bs'
|
856
|
+
autoload :ToHtml, 'rdoc/markup/to_html'
|
857
|
+
autoload :ToHtmlCrossref, 'rdoc/markup/to_html_crossref'
|
858
|
+
autoload :ToHtmlSnippet, 'rdoc/markup/to_html_snippet'
|
859
|
+
autoload :ToLabel, 'rdoc/markup/to_label'
|
860
|
+
autoload :ToMarkdown, 'rdoc/markup/to_markdown'
|
861
|
+
autoload :ToRdoc, 'rdoc/markup/to_rdoc'
|
862
|
+
autoload :ToTableOfContents, 'rdoc/markup/to_table_of_contents'
|
863
|
+
autoload :ToTest, 'rdoc/markup/to_test'
|
864
|
+
autoload :ToTtOnly, 'rdoc/markup/to_tt_only'
|
865
|
+
|
866
|
+
end
|
867
|
+
|