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,176 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
##
|
3
|
+
# Subclass of the RDoc::Markup::ToHtml class that supports looking up method
|
4
|
+
# names, classes, etc to create links. RDoc::CrossReference is used to
|
5
|
+
# generate those links based on the current context.
|
6
|
+
|
7
|
+
class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
8
|
+
|
9
|
+
# :stopdoc:
|
10
|
+
ALL_CROSSREF_REGEXP = RDoc::CrossReference::ALL_CROSSREF_REGEXP
|
11
|
+
CLASS_REGEXP_STR = RDoc::CrossReference::CLASS_REGEXP_STR
|
12
|
+
CROSSREF_REGEXP = RDoc::CrossReference::CROSSREF_REGEXP
|
13
|
+
METHOD_REGEXP_STR = RDoc::CrossReference::METHOD_REGEXP_STR
|
14
|
+
# :startdoc:
|
15
|
+
|
16
|
+
##
|
17
|
+
# RDoc::CodeObject for generating references
|
18
|
+
|
19
|
+
attr_accessor :context
|
20
|
+
|
21
|
+
##
|
22
|
+
# Should we show '#' characters on method references?
|
23
|
+
|
24
|
+
attr_accessor :show_hash
|
25
|
+
|
26
|
+
##
|
27
|
+
# Creates a new crossref resolver that generates links relative to +context+
|
28
|
+
# which lives at +from_path+ in the generated files. '#' characters on
|
29
|
+
# references are removed unless +show_hash+ is true. Only method names
|
30
|
+
# preceded by '#' or '::' are linked, unless +hyperlink_all+ is true.
|
31
|
+
|
32
|
+
def initialize(options, from_path, context, markup = nil)
|
33
|
+
raise ArgumentError, 'from_path cannot be nil' if from_path.nil?
|
34
|
+
|
35
|
+
super options, markup
|
36
|
+
|
37
|
+
@context = context
|
38
|
+
@from_path = from_path
|
39
|
+
@hyperlink_all = @options.hyperlink_all
|
40
|
+
@show_hash = @options.show_hash
|
41
|
+
|
42
|
+
@cross_reference = RDoc::CrossReference.new @context
|
43
|
+
end
|
44
|
+
|
45
|
+
def init_link_notation_regexp_handlings
|
46
|
+
add_regexp_handling_RDOCLINK
|
47
|
+
|
48
|
+
# The crossref must be linked before tidylink because Klass.method[:sym]
|
49
|
+
# will be processed as a tidylink first and will be broken.
|
50
|
+
crossref_re = @options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
|
51
|
+
@markup.add_regexp_handling crossref_re, :CROSSREF
|
52
|
+
|
53
|
+
add_regexp_handling_TIDYLINK
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Creates a link to the reference +name+ if the name exists. If +text+ is
|
58
|
+
# given it is used as the link text, otherwise +name+ is used.
|
59
|
+
|
60
|
+
def cross_reference name, text = nil, code = true
|
61
|
+
lookup = name
|
62
|
+
|
63
|
+
name = name[1..-1] unless @show_hash if name[0, 1] == '#'
|
64
|
+
|
65
|
+
if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/
|
66
|
+
text ||= "#{CGI.unescape $'} at <code>#{$1}</code>"
|
67
|
+
code = false
|
68
|
+
else
|
69
|
+
text ||= name
|
70
|
+
end
|
71
|
+
|
72
|
+
link lookup, text, code
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# We're invoked when any text matches the CROSSREF pattern. If we find the
|
77
|
+
# corresponding reference, generate a link. If the name we're looking for
|
78
|
+
# contains no punctuation, we look for it up the module/class chain. For
|
79
|
+
# example, ToHtml is found, even without the <tt>RDoc::Markup::</tt> prefix,
|
80
|
+
# because we look for it in module Markup first.
|
81
|
+
|
82
|
+
def handle_regexp_CROSSREF(target)
|
83
|
+
name = target.text
|
84
|
+
|
85
|
+
return name if name =~ /@[\w-]+\.[\w-]/ # labels that look like emails
|
86
|
+
|
87
|
+
unless @hyperlink_all then
|
88
|
+
# This ensures that words entirely consisting of lowercase letters will
|
89
|
+
# not have cross-references generated (to suppress lots of erroneous
|
90
|
+
# cross-references to "new" in text, for instance)
|
91
|
+
return name if name =~ /\A[a-z]*\z/
|
92
|
+
end
|
93
|
+
|
94
|
+
cross_reference name
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Handles <tt>rdoc-ref:</tt> scheme links and allows RDoc::Markup::ToHtml to
|
99
|
+
# handle other schemes.
|
100
|
+
|
101
|
+
def handle_regexp_HYPERLINK target
|
102
|
+
return cross_reference $' if target.text =~ /\Ardoc-ref:/
|
103
|
+
|
104
|
+
super
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# +target+ is an rdoc-schemed link that will be converted into a hyperlink.
|
109
|
+
# For the rdoc-ref scheme the cross-reference will be looked up and the
|
110
|
+
# given name will be used.
|
111
|
+
#
|
112
|
+
# All other contents are handled by
|
113
|
+
# {the superclass}[rdoc-ref:RDoc::Markup::ToHtml#handle_regexp_RDOCLINK]
|
114
|
+
|
115
|
+
def handle_regexp_RDOCLINK target
|
116
|
+
url = target.text
|
117
|
+
|
118
|
+
case url
|
119
|
+
when /\Ardoc-ref:/ then
|
120
|
+
cross_reference $'
|
121
|
+
else
|
122
|
+
super
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
##
|
127
|
+
# Generates links for <tt>rdoc-ref:</tt> scheme URLs and allows
|
128
|
+
# RDoc::Markup::ToHtml to handle other schemes.
|
129
|
+
|
130
|
+
def gen_url url, text
|
131
|
+
return super unless url =~ /\Ardoc-ref:/
|
132
|
+
|
133
|
+
name = $'
|
134
|
+
cross_reference name, text, name == text
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
# Creates an HTML link to +name+ with the given +text+.
|
139
|
+
|
140
|
+
def link name, text, code = true
|
141
|
+
if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/
|
142
|
+
name = $1
|
143
|
+
label = $'
|
144
|
+
end
|
145
|
+
|
146
|
+
ref = @cross_reference.resolve name, text
|
147
|
+
|
148
|
+
case ref
|
149
|
+
when String then
|
150
|
+
ref
|
151
|
+
else
|
152
|
+
path = ref.as_href @from_path
|
153
|
+
|
154
|
+
if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref)
|
155
|
+
text = "<code>#{CGI.escapeHTML text}</code>"
|
156
|
+
end
|
157
|
+
|
158
|
+
if path =~ /#/ then
|
159
|
+
path << "-label-#{label}"
|
160
|
+
elsif ref.sections and
|
161
|
+
ref.sections.any? { |section| label == section.title } then
|
162
|
+
path << "##{label}"
|
163
|
+
else
|
164
|
+
if ref.respond_to?(:aref)
|
165
|
+
path << "##{ref.aref}-label-#{label}"
|
166
|
+
else
|
167
|
+
path << "#label-#{label}"
|
168
|
+
end
|
169
|
+
end if label
|
170
|
+
|
171
|
+
"<a href=\"#{path}\">#{text}</a>"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
@@ -0,0 +1,285 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
##
|
3
|
+
# Outputs RDoc markup as paragraphs with inline markup only.
|
4
|
+
|
5
|
+
class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
6
|
+
|
7
|
+
##
|
8
|
+
# After this many characters the input will be cut off.
|
9
|
+
|
10
|
+
attr_reader :character_limit
|
11
|
+
|
12
|
+
##
|
13
|
+
# The number of characters seen so far.
|
14
|
+
|
15
|
+
attr_reader :characters # :nodoc:
|
16
|
+
|
17
|
+
##
|
18
|
+
# The attribute bitmask
|
19
|
+
|
20
|
+
attr_reader :mask
|
21
|
+
|
22
|
+
##
|
23
|
+
# After this many paragraphs the input will be cut off.
|
24
|
+
|
25
|
+
attr_reader :paragraph_limit
|
26
|
+
|
27
|
+
##
|
28
|
+
# Count of paragraphs found
|
29
|
+
|
30
|
+
attr_reader :paragraphs
|
31
|
+
|
32
|
+
##
|
33
|
+
# Creates a new ToHtmlSnippet formatter that will cut off the input on the
|
34
|
+
# next word boundary after the given number of +characters+ or +paragraphs+
|
35
|
+
# of text have been encountered.
|
36
|
+
|
37
|
+
def initialize options, characters = 100, paragraphs = 3, markup = nil
|
38
|
+
super options, markup
|
39
|
+
|
40
|
+
@character_limit = characters
|
41
|
+
@paragraph_limit = paragraphs
|
42
|
+
|
43
|
+
@characters = 0
|
44
|
+
@mask = 0
|
45
|
+
@paragraphs = 0
|
46
|
+
|
47
|
+
@markup.add_regexp_handling RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Adds +heading+ to the output as a paragraph
|
52
|
+
|
53
|
+
def accept_heading heading
|
54
|
+
@res << "<p>#{to_html heading.text}\n"
|
55
|
+
|
56
|
+
add_paragraph
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Raw sections are untrusted and ignored
|
61
|
+
|
62
|
+
alias accept_raw ignore
|
63
|
+
|
64
|
+
##
|
65
|
+
# Rules are ignored
|
66
|
+
|
67
|
+
alias accept_rule ignore
|
68
|
+
|
69
|
+
def accept_paragraph paragraph
|
70
|
+
para = @in_list_entry.last || "<p>"
|
71
|
+
|
72
|
+
text = paragraph.text @hard_break
|
73
|
+
|
74
|
+
@res << "#{para}#{to_html text}\n"
|
75
|
+
|
76
|
+
add_paragraph
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Finishes consumption of +list_item+
|
81
|
+
|
82
|
+
def accept_list_item_end list_item
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Prepares the visitor for consuming +list_item+
|
87
|
+
|
88
|
+
def accept_list_item_start list_item
|
89
|
+
@res << list_item_start(list_item, @list.last)
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# Prepares the visitor for consuming +list+
|
94
|
+
|
95
|
+
def accept_list_start list
|
96
|
+
@list << list.type
|
97
|
+
@res << html_list_name(list.type, true)
|
98
|
+
@in_list_entry.push ''
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# Adds +verbatim+ to the output
|
103
|
+
|
104
|
+
def accept_verbatim verbatim
|
105
|
+
throw :done if @characters >= @character_limit
|
106
|
+
input = verbatim.text.rstrip
|
107
|
+
|
108
|
+
text = truncate input
|
109
|
+
text << ' ...' unless text == input
|
110
|
+
|
111
|
+
super RDoc::Markup::Verbatim.new text
|
112
|
+
|
113
|
+
add_paragraph
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Prepares the visitor for HTML snippet generation
|
118
|
+
|
119
|
+
def start_accepting
|
120
|
+
super
|
121
|
+
|
122
|
+
@characters = 0
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# Removes escaping from the cross-references in +target+
|
127
|
+
|
128
|
+
def handle_regexp_CROSSREF target
|
129
|
+
target.text.sub(/\A\\/, '')
|
130
|
+
end
|
131
|
+
|
132
|
+
##
|
133
|
+
# +target+ is a <code><br></code>
|
134
|
+
|
135
|
+
def handle_regexp_HARD_BREAK target
|
136
|
+
@characters -= 4
|
137
|
+
'<br>'
|
138
|
+
end
|
139
|
+
|
140
|
+
##
|
141
|
+
# Lists are paragraphs, but notes and labels have a separator
|
142
|
+
|
143
|
+
def list_item_start list_item, list_type
|
144
|
+
throw :done if @characters >= @character_limit
|
145
|
+
|
146
|
+
case list_type
|
147
|
+
when :BULLET, :LALPHA, :NUMBER, :UALPHA then
|
148
|
+
"<p>"
|
149
|
+
when :LABEL, :NOTE then
|
150
|
+
labels = Array(list_item.label).map do |label|
|
151
|
+
to_html label
|
152
|
+
end.join ', '
|
153
|
+
|
154
|
+
labels << " — " unless labels.empty?
|
155
|
+
|
156
|
+
start = "<p>#{labels}"
|
157
|
+
@characters += 1 # try to include the label
|
158
|
+
start
|
159
|
+
else
|
160
|
+
raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
##
|
165
|
+
# Returns just the text of +link+, +url+ is only used to determine the link
|
166
|
+
# type.
|
167
|
+
|
168
|
+
def gen_url url, text
|
169
|
+
if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
|
170
|
+
type = "link"
|
171
|
+
elsif url =~ /([A-Za-z]+):(.*)/ then
|
172
|
+
type = $1
|
173
|
+
else
|
174
|
+
type = "http"
|
175
|
+
end
|
176
|
+
|
177
|
+
if (type == "http" or type == "https" or type == "link") and
|
178
|
+
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
|
179
|
+
''
|
180
|
+
else
|
181
|
+
text.sub(%r%^#{type}:/*%, '')
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
##
|
186
|
+
# In snippets, there are no lists
|
187
|
+
|
188
|
+
def html_list_name list_type, open_tag
|
189
|
+
''
|
190
|
+
end
|
191
|
+
|
192
|
+
##
|
193
|
+
# Throws +:done+ when paragraph_limit paragraphs have been encountered
|
194
|
+
|
195
|
+
def add_paragraph
|
196
|
+
@paragraphs += 1
|
197
|
+
|
198
|
+
throw :done if @paragraphs >= @paragraph_limit
|
199
|
+
end
|
200
|
+
|
201
|
+
##
|
202
|
+
# Marks up +content+
|
203
|
+
|
204
|
+
def convert content
|
205
|
+
catch :done do
|
206
|
+
return super
|
207
|
+
end
|
208
|
+
|
209
|
+
end_accepting
|
210
|
+
end
|
211
|
+
|
212
|
+
##
|
213
|
+
# Converts flow items +flow+
|
214
|
+
|
215
|
+
def convert_flow flow
|
216
|
+
throw :done if @characters >= @character_limit
|
217
|
+
|
218
|
+
res = []
|
219
|
+
@mask = 0
|
220
|
+
|
221
|
+
flow.each do |item|
|
222
|
+
case item
|
223
|
+
when RDoc::Markup::AttrChanger then
|
224
|
+
off_tags res, item
|
225
|
+
on_tags res, item
|
226
|
+
when String then
|
227
|
+
text = convert_string item
|
228
|
+
res << truncate(text)
|
229
|
+
when RDoc::Markup::RegexpHandling then
|
230
|
+
text = convert_regexp_handling item
|
231
|
+
res << truncate(text)
|
232
|
+
else
|
233
|
+
raise "Unknown flow element: #{item.inspect}"
|
234
|
+
end
|
235
|
+
|
236
|
+
if @characters >= @character_limit then
|
237
|
+
off_tags res, RDoc::Markup::AttrChanger.new(0, @mask)
|
238
|
+
break
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
res << ' ...' if @characters >= @character_limit
|
243
|
+
|
244
|
+
res.join
|
245
|
+
end
|
246
|
+
|
247
|
+
##
|
248
|
+
# Maintains a bitmask to allow HTML elements to be closed properly. See
|
249
|
+
# RDoc::Markup::Formatter.
|
250
|
+
|
251
|
+
def on_tags res, item
|
252
|
+
@mask ^= item.turn_on
|
253
|
+
|
254
|
+
super
|
255
|
+
end
|
256
|
+
|
257
|
+
##
|
258
|
+
# Maintains a bitmask to allow HTML elements to be closed properly. See
|
259
|
+
# RDoc::Markup::Formatter.
|
260
|
+
|
261
|
+
def off_tags res, item
|
262
|
+
@mask ^= item.turn_off
|
263
|
+
|
264
|
+
super
|
265
|
+
end
|
266
|
+
|
267
|
+
##
|
268
|
+
# Truncates +text+ at the end of the first word after the character_limit.
|
269
|
+
|
270
|
+
def truncate text
|
271
|
+
length = text.length
|
272
|
+
characters = @characters
|
273
|
+
@characters += length
|
274
|
+
|
275
|
+
return text if @characters < @character_limit
|
276
|
+
|
277
|
+
remaining = @character_limit - characters
|
278
|
+
|
279
|
+
text =~ /\A(.{#{remaining},}?)(\s|$)/m # TODO word-break instead of \s?
|
280
|
+
|
281
|
+
$1
|
282
|
+
end
|
283
|
+
|
284
|
+
end
|
285
|
+
|