rdoc 3.12.2 → 4.0.0.preview2
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.
- checksums.yaml +6 -6
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.autotest +3 -2
- data/DEVELOPERS.rdoc +53 -0
- data/History.rdoc +159 -25
- data/LEGAL.rdoc +12 -0
- data/Manifest.txt +56 -3
- data/README.rdoc +87 -19
- data/Rakefile +11 -2
- data/TODO.rdoc +20 -13
- data/bin/rdoc +4 -0
- data/lib/gauntlet_rdoc.rb +1 -1
- data/lib/rdoc.rb +32 -71
- data/lib/rdoc/any_method.rb +75 -21
- data/lib/rdoc/attr.rb +49 -10
- data/lib/rdoc/class_module.rb +182 -32
- data/lib/rdoc/code_object.rb +54 -12
- data/lib/rdoc/comment.rb +8 -1
- data/lib/rdoc/constant.rb +100 -6
- data/lib/rdoc/context.rb +93 -41
- data/lib/rdoc/context/section.rb +143 -28
- data/lib/rdoc/cross_reference.rb +58 -50
- data/lib/rdoc/encoding.rb +34 -29
- data/lib/rdoc/erb_partial.rb +18 -0
- data/lib/rdoc/extend.rb +117 -0
- data/lib/rdoc/generator.rb +11 -6
- data/lib/rdoc/generator/darkfish.rb +250 -62
- data/lib/rdoc/generator/json_index.rb +20 -12
- data/lib/rdoc/generator/markup.rb +10 -12
- data/lib/rdoc/generator/ri.rb +7 -60
- data/lib/rdoc/generator/template/darkfish/_head.rhtml +7 -7
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +16 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +14 -0
- data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +13 -0
- data/lib/rdoc/generator/template/darkfish/class.rhtml +15 -1
- data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
- data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -3
- data/lib/rdoc/generator/template/darkfish/js/darkfish.js +7 -9
- data/lib/rdoc/generator/template/darkfish/page.rhtml +2 -0
- data/lib/rdoc/generator/template/darkfish/rdoc.css +31 -0
- data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
- data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +37 -0
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
- data/lib/rdoc/include.rb +12 -3
- data/lib/rdoc/markdown.kpeg +1186 -0
- data/lib/rdoc/markdown.rb +16336 -0
- data/lib/rdoc/markdown/entities.rb +2128 -0
- data/lib/rdoc/markdown/literals_1_8.kpeg +18 -0
- data/lib/rdoc/markdown/literals_1_8.rb +454 -0
- data/lib/rdoc/markdown/literals_1_9.kpeg +22 -0
- data/lib/rdoc/markdown/literals_1_9.rb +417 -0
- data/lib/rdoc/markup.rb +69 -10
- data/lib/rdoc/markup/attr_changer.rb +2 -5
- data/lib/rdoc/markup/attribute_manager.rb +23 -14
- data/lib/rdoc/markup/attributes.rb +70 -0
- data/lib/rdoc/markup/block_quote.rb +14 -0
- data/lib/rdoc/markup/document.rb +20 -4
- data/lib/rdoc/markup/formatter.rb +17 -6
- data/lib/rdoc/markup/formatter_test_case.rb +93 -24
- data/lib/rdoc/markup/hard_break.rb +31 -0
- data/lib/rdoc/markup/heading.rb +1 -1
- data/lib/rdoc/markup/indented_paragraph.rb +14 -0
- data/lib/rdoc/markup/list.rb +23 -4
- data/lib/rdoc/markup/list_item.rb +17 -4
- data/lib/rdoc/markup/paragraph.rb +14 -0
- data/lib/rdoc/markup/parser.rb +107 -60
- data/lib/rdoc/markup/raw.rb +4 -4
- data/lib/rdoc/markup/special.rb +3 -3
- data/lib/rdoc/markup/to_ansi.rb +7 -1
- data/lib/rdoc/markup/to_html.rb +42 -14
- data/lib/rdoc/markup/to_html_crossref.rb +10 -9
- data/lib/rdoc/markup/to_html_snippet.rb +20 -4
- data/lib/rdoc/markup/to_joined_paragraph.rb +68 -0
- data/lib/rdoc/markup/to_label.rb +20 -1
- data/lib/rdoc/markup/to_markdown.rb +134 -0
- data/lib/rdoc/markup/to_rdoc.rb +36 -5
- data/lib/rdoc/markup/to_table_of_contents.rb +6 -1
- data/lib/rdoc/markup/to_tt_only.rb +11 -2
- data/lib/rdoc/markup/verbatim.rb +19 -0
- data/lib/rdoc/method_attr.rb +33 -19
- data/lib/rdoc/normal_class.rb +26 -7
- data/lib/rdoc/normal_module.rb +10 -5
- data/lib/rdoc/options.rb +95 -21
- data/lib/rdoc/parser.rb +6 -2
- data/lib/rdoc/parser/c.rb +212 -97
- data/lib/rdoc/parser/markdown.rb +23 -0
- data/lib/rdoc/parser/ruby.rb +115 -35
- data/lib/rdoc/parser/ruby_tools.rb +8 -3
- data/lib/rdoc/rd.rb +8 -4
- data/lib/rdoc/rd/block_parser.rb +1 -1
- data/lib/rdoc/rd/block_parser.ry +1 -1
- data/lib/rdoc/rdoc.rb +45 -21
- data/lib/rdoc/ri/driver.rb +322 -76
- data/lib/rdoc/ri/paths.rb +90 -31
- data/lib/rdoc/ri/store.rb +2 -353
- data/lib/rdoc/ruby_lex.rb +5 -21
- data/lib/rdoc/ruby_token.rb +2 -3
- data/lib/rdoc/rubygems_hook.rb +21 -9
- data/lib/rdoc/servlet.rb +302 -0
- data/lib/rdoc/stats.rb +28 -20
- data/lib/rdoc/store.rb +881 -0
- data/lib/rdoc/task.rb +2 -1
- data/lib/rdoc/test_case.rb +103 -1
- data/lib/rdoc/text.rb +5 -4
- data/lib/rdoc/tom_doc.rb +17 -16
- data/lib/rdoc/top_level.rb +43 -285
- data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +21 -0
- data/test/MarkdownTest_1.0.3/Auto links.text +13 -0
- data/test/MarkdownTest_1.0.3/Backslash escapes.text +120 -0
- data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +11 -0
- data/test/MarkdownTest_1.0.3/Code Blocks.text +14 -0
- data/test/MarkdownTest_1.0.3/Code Spans.text +6 -0
- data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +8 -0
- data/test/MarkdownTest_1.0.3/Horizontal rules.text +67 -0
- data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +15 -0
- data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +69 -0
- data/test/MarkdownTest_1.0.3/Inline HTML comments.text +13 -0
- data/test/MarkdownTest_1.0.3/Links, inline style.text +12 -0
- data/test/MarkdownTest_1.0.3/Links, reference style.text +71 -0
- data/test/MarkdownTest_1.0.3/Links, shortcut references.text +20 -0
- data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +7 -0
- data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +306 -0
- data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +888 -0
- data/test/MarkdownTest_1.0.3/Nested blockquotes.text +5 -0
- data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +131 -0
- data/test/MarkdownTest_1.0.3/Strong and em together.text +7 -0
- data/test/MarkdownTest_1.0.3/Tabs.text +21 -0
- data/test/MarkdownTest_1.0.3/Tidyness.text +5 -0
- data/test/test_attribute_manager.rb +7 -4
- data/test/test_rdoc_any_method.rb +84 -13
- data/test/test_rdoc_attr.rb +59 -9
- data/test/test_rdoc_class_module.rb +670 -73
- data/test/test_rdoc_code_object.rb +21 -1
- data/test/test_rdoc_comment.rb +1 -1
- data/test/test_rdoc_constant.rb +132 -0
- data/test/test_rdoc_context.rb +84 -18
- data/test/test_rdoc_context_section.rb +99 -15
- data/test/test_rdoc_cross_reference.rb +1 -1
- data/test/test_rdoc_encoding.rb +17 -1
- data/test/test_rdoc_extend.rb +94 -0
- data/test/test_rdoc_generator_darkfish.rb +45 -19
- data/test/test_rdoc_generator_json_index.rb +27 -7
- data/test/test_rdoc_generator_markup.rb +3 -3
- data/test/test_rdoc_generator_ri.rb +11 -9
- data/test/test_rdoc_include.rb +12 -0
- data/test/test_rdoc_markdown.rb +977 -0
- data/test/test_rdoc_markdown_test.rb +1891 -0
- data/test/test_rdoc_markup.rb +1 -1
- data/test/test_rdoc_markup_attribute_manager.rb +2 -2
- data/test/test_rdoc_markup_attributes.rb +39 -0
- data/test/test_rdoc_markup_document.rb +16 -1
- data/test/test_rdoc_markup_formatter.rb +7 -4
- data/test/test_rdoc_markup_hard_break.rb +31 -0
- data/test/test_rdoc_markup_indented_paragraph.rb +14 -0
- data/test/test_rdoc_markup_paragraph.rb +15 -1
- data/test/test_rdoc_markup_parser.rb +152 -89
- data/test/test_rdoc_markup_to_ansi.rb +23 -2
- data/test/test_rdoc_markup_to_bs.rb +24 -0
- data/test/test_rdoc_markup_to_html.rb +50 -19
- data/test/test_rdoc_markup_to_html_crossref.rb +23 -5
- data/test/test_rdoc_markup_to_html_snippet.rb +49 -8
- data/test/test_rdoc_markup_to_joined_paragraph.rb +32 -0
- data/test/test_rdoc_markup_to_label.rb +63 -1
- data/test/test_rdoc_markup_to_markdown.rb +352 -0
- data/test/test_rdoc_markup_to_rdoc.rb +22 -2
- data/test/test_rdoc_markup_to_table_of_contents.rb +44 -39
- data/test/test_rdoc_markup_to_tt_only.rb +20 -0
- data/test/test_rdoc_markup_verbatim.rb +13 -0
- data/test/test_rdoc_method_attr.rb +5 -0
- data/test/test_rdoc_normal_class.rb +24 -5
- data/test/test_rdoc_normal_module.rb +1 -1
- data/test/test_rdoc_options.rb +21 -6
- data/test/test_rdoc_parser.rb +24 -0
- data/test/test_rdoc_parser_c.rb +151 -26
- data/test/test_rdoc_parser_markdown.rb +55 -0
- data/test/test_rdoc_parser_rd.rb +2 -2
- data/test/test_rdoc_parser_ruby.rb +468 -109
- data/test/test_rdoc_parser_simple.rb +2 -2
- data/test/test_rdoc_rd_block_parser.rb +0 -4
- data/test/test_rdoc_rdoc.rb +110 -22
- data/test/test_rdoc_ri_driver.rb +415 -80
- data/test/test_rdoc_ri_paths.rb +122 -13
- data/test/test_rdoc_ruby_lex.rb +5 -61
- data/test/test_rdoc_ruby_token.rb +19 -0
- data/test/test_rdoc_rubygems_hook.rb +64 -43
- data/test/test_rdoc_servlet.rb +429 -0
- data/test/test_rdoc_stats.rb +83 -24
- data/test/{test_rdoc_ri_store.rb → test_rdoc_store.rb} +395 -22
- data/test/test_rdoc_task.rb +2 -2
- data/test/test_rdoc_text.rb +37 -11
- data/test/test_rdoc_tom_doc.rb +59 -62
- data/test/test_rdoc_top_level.rb +71 -113
- data/test/xref_test_case.rb +7 -9
- metadata +122 -39
- metadata.gz.sig +0 -0
- data/CVE-2013-0256.rdoc +0 -49
- data/lib/rdoc/markup/attribute.rb +0 -51
data/lib/rdoc/markup/raw.rb
CHANGED
@@ -13,7 +13,7 @@ class RDoc::Markup::Raw
|
|
13
13
|
|
14
14
|
def initialize *parts
|
15
15
|
@parts = []
|
16
|
-
@parts.
|
16
|
+
@parts.concat parts
|
17
17
|
end
|
18
18
|
|
19
19
|
##
|
@@ -38,11 +38,11 @@ class RDoc::Markup::Raw
|
|
38
38
|
# Appends +other+'s parts
|
39
39
|
|
40
40
|
def merge other
|
41
|
-
@parts.
|
41
|
+
@parts.concat other.parts
|
42
42
|
end
|
43
43
|
|
44
44
|
def pretty_print q # :nodoc:
|
45
|
-
self.class.name =~ /.*::(\w{1,4})
|
45
|
+
self.class.name =~ /.*::(\w{1,4})/i
|
46
46
|
|
47
47
|
q.group 2, "[#{$1.downcase}: ", ']' do
|
48
48
|
q.seplist @parts do |part|
|
@@ -55,7 +55,7 @@ class RDoc::Markup::Raw
|
|
55
55
|
# Appends +texts+ onto this Paragraph
|
56
56
|
|
57
57
|
def push *texts
|
58
|
-
self.parts.
|
58
|
+
self.parts.concat texts
|
59
59
|
end
|
60
60
|
|
61
61
|
##
|
data/lib/rdoc/markup/special.rb
CHANGED
@@ -28,12 +28,12 @@ class RDoc::Markup::Special
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def inspect # :nodoc:
|
31
|
-
"#<RDoc::Markup::Special:0x%x @type=%p,
|
32
|
-
object_id, @type,
|
31
|
+
"#<RDoc::Markup::Special:0x%x @type=%p, @text=%p>" % [
|
32
|
+
object_id, @type, text.dump]
|
33
33
|
end
|
34
34
|
|
35
35
|
def to_s # :nodoc:
|
36
|
-
"Special: type=#{type}
|
36
|
+
"Special: type=#{type} text=#{text.dump}"
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
data/lib/rdoc/markup/to_ansi.rb
CHANGED
@@ -56,7 +56,13 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
|
|
56
56
|
when :BULLET then
|
57
57
|
'*'
|
58
58
|
when :NOTE, :LABEL then
|
59
|
-
|
59
|
+
labels = Array(list_item.label).map do |label|
|
60
|
+
attributes(label).strip
|
61
|
+
end.join "\n"
|
62
|
+
|
63
|
+
labels << ":\n" unless labels.empty?
|
64
|
+
|
65
|
+
labels
|
60
66
|
else
|
61
67
|
@list_index.last.to_s + '.'
|
62
68
|
end
|
data/lib/rdoc/markup/to_html.rb
CHANGED
@@ -65,7 +65,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
65
65
|
##
|
66
66
|
# Creates a new formatter that will output HTML
|
67
67
|
|
68
|
-
def initialize markup = nil
|
68
|
+
def initialize options, markup = nil
|
69
69
|
super
|
70
70
|
|
71
71
|
@code_object = nil
|
@@ -73,16 +73,23 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
73
73
|
@in_list_entry = nil
|
74
74
|
@list = nil
|
75
75
|
@th = nil
|
76
|
+
@hard_break = "<br>\n"
|
76
77
|
|
77
78
|
# external links
|
78
|
-
@markup.add_special(/(
|
79
|
+
@markup.add_special(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
|
79
80
|
:HYPERLINK)
|
80
81
|
|
81
82
|
# internal links
|
82
83
|
@markup.add_special(/rdoc-[a-z]+:\S+/, :RDOCLINK)
|
83
84
|
|
84
85
|
# and links of the form <text>[<url>]
|
85
|
-
@markup.add_special(/(
|
86
|
+
@markup.add_special(/(?:
|
87
|
+
\{.*?\} | # multi-word label
|
88
|
+
\b[^\s{}]+? # single-word label
|
89
|
+
)
|
90
|
+
|
91
|
+
\[\S+?\] # link target
|
92
|
+
/x, :TIDYLINK)
|
86
93
|
|
87
94
|
init_tags
|
88
95
|
end
|
@@ -91,6 +98,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
91
98
|
#
|
92
99
|
# These methods handle special markup added by RDoc::Markup#add_special.
|
93
100
|
|
101
|
+
##
|
102
|
+
# +special+ is a <code><br></code>
|
103
|
+
|
104
|
+
def handle_special_HARD_BREAK special
|
105
|
+
'<br>'
|
106
|
+
end
|
107
|
+
|
94
108
|
##
|
95
109
|
# +special+ is a potential link. The following schemes are handled:
|
96
110
|
#
|
@@ -176,12 +190,26 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
176
190
|
@res.join
|
177
191
|
end
|
178
192
|
|
193
|
+
##
|
194
|
+
# Adds +block_quote+ to the output
|
195
|
+
|
196
|
+
def accept_block_quote block_quote
|
197
|
+
@res << "\n<blockquote>"
|
198
|
+
|
199
|
+
block_quote.parts.each do |part|
|
200
|
+
part.accept self
|
201
|
+
end
|
202
|
+
|
203
|
+
@res << "</blockquote>\n"
|
204
|
+
end
|
205
|
+
|
179
206
|
##
|
180
207
|
# Adds +paragraph+ to the output
|
181
208
|
|
182
|
-
def accept_paragraph
|
209
|
+
def accept_paragraph paragraph
|
183
210
|
@res << "\n<p>"
|
184
|
-
|
211
|
+
text = paragraph.text @hard_break
|
212
|
+
@res << wrap(to_html(text))
|
185
213
|
@res << "</p>\n"
|
186
214
|
end
|
187
215
|
|
@@ -192,14 +220,12 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
192
220
|
text = verbatim.text.rstrip
|
193
221
|
|
194
222
|
@res << if verbatim.ruby? or parseable? text then
|
195
|
-
options = RDoc::RDoc.current.options if RDoc::RDoc.current
|
196
|
-
|
197
223
|
begin
|
198
|
-
tokens = RDoc::RubyLex.tokenize text, options
|
224
|
+
tokens = RDoc::RubyLex.tokenize text, @options
|
225
|
+
|
226
|
+
html = RDoc::TokenStream.to_html tokens
|
199
227
|
|
200
|
-
"\n<pre class=\"ruby\"
|
201
|
-
"#{RDoc::TokenStream.to_html tokens}" \
|
202
|
-
"</pre>\n"
|
228
|
+
"\n<pre class=\"ruby\">#{html}</pre>\n"
|
203
229
|
rescue RDoc::RubyLex::Error
|
204
230
|
"\n<pre>#{CGI.escapeHTML text}</pre>\n"
|
205
231
|
end
|
@@ -288,7 +314,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
288
314
|
# :section: Utilities
|
289
315
|
|
290
316
|
##
|
291
|
-
# CGI
|
317
|
+
# CGI-escapes +text+
|
292
318
|
|
293
319
|
def convert_string(text)
|
294
320
|
CGI.escapeHTML text
|
@@ -355,7 +381,9 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
355
381
|
when :BULLET, :LALPHA, :NUMBER, :UALPHA then
|
356
382
|
"<li>"
|
357
383
|
when :LABEL, :NOTE then
|
358
|
-
|
384
|
+
Array(list_item.label).map do |label|
|
385
|
+
"<dt>#{to_html label}\n"
|
386
|
+
end.join << "<dd>"
|
359
387
|
else
|
360
388
|
raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
|
361
389
|
end
|
@@ -379,7 +407,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
|
|
379
407
|
# Returns true if Ripper is available it can create a sexp from +text+
|
380
408
|
|
381
409
|
def parseable? text
|
382
|
-
text =~ /\b(def|class|module|require)
|
410
|
+
text =~ /\b(def|class|module|require) |=>|\{\s?\||do \|/ and
|
383
411
|
text !~ /<%|%>/
|
384
412
|
end
|
385
413
|
|
@@ -28,21 +28,20 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|
28
28
|
# references are removed unless +show_hash+ is true. Only method names
|
29
29
|
# preceded by '#' or '::' are linked, unless +hyperlink_all+ is true.
|
30
30
|
|
31
|
-
def initialize(from_path, context,
|
32
|
-
markup = nil)
|
31
|
+
def initialize(options, from_path, context, markup = nil)
|
33
32
|
raise ArgumentError, 'from_path cannot be nil' if from_path.nil?
|
34
|
-
super markup
|
35
33
|
|
36
|
-
|
34
|
+
super options, markup
|
37
35
|
|
38
|
-
@
|
36
|
+
@context = context
|
37
|
+
@from_path = from_path
|
38
|
+
@hyperlink_all = @options.hyperlink_all
|
39
|
+
@show_hash = @options.show_hash
|
39
40
|
|
41
|
+
crossref_re = @hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
|
40
42
|
@markup.add_special crossref_re, :CROSSREF
|
41
43
|
|
42
|
-
@
|
43
|
-
@from_path = from_path
|
44
|
-
@hyperlink_all = hyperlink_all
|
45
|
-
@show_hash = show_hash
|
44
|
+
@cross_reference = RDoc::CrossReference.new @context
|
46
45
|
end
|
47
46
|
|
48
47
|
##
|
@@ -71,6 +70,8 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
|
71
70
|
def handle_special_CROSSREF(special)
|
72
71
|
name = special.text
|
73
72
|
|
73
|
+
return name if name =~ /@[\w-]+\.[\w-]/ # labels that look like emails
|
74
|
+
|
74
75
|
unless @hyperlink_all then
|
75
76
|
# This ensures that words entirely consisting of lowercase letters will
|
76
77
|
# not have cross-references generated (to suppress lots of erroneous
|
@@ -33,8 +33,8 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|
33
33
|
# next word boundary after the given number of +characters+ or +paragraphs+
|
34
34
|
# of text have been encountered.
|
35
35
|
|
36
|
-
def initialize characters = 100, paragraphs = 3, markup = nil
|
37
|
-
super markup
|
36
|
+
def initialize options, characters = 100, paragraphs = 3, markup = nil
|
37
|
+
super options, markup
|
38
38
|
|
39
39
|
@character_limit = characters
|
40
40
|
@paragraph_limit = paragraphs
|
@@ -68,7 +68,9 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|
68
68
|
def accept_paragraph paragraph
|
69
69
|
para = @in_list_entry.last || "<p>"
|
70
70
|
|
71
|
-
|
71
|
+
text = paragraph.text @hard_break
|
72
|
+
|
73
|
+
@res << "#{para}#{wrap to_html text}\n"
|
72
74
|
|
73
75
|
add_paragraph
|
74
76
|
end
|
@@ -126,6 +128,14 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|
126
128
|
special.text.sub(/\A\\/, '')
|
127
129
|
end
|
128
130
|
|
131
|
+
##
|
132
|
+
# +special+ is a <code><br></code>
|
133
|
+
|
134
|
+
def handle_special_HARD_BREAK special
|
135
|
+
@characters -= 4
|
136
|
+
'<br>'
|
137
|
+
end
|
138
|
+
|
129
139
|
##
|
130
140
|
# Lists are paragraphs, but notes and labels have a separator
|
131
141
|
|
@@ -136,7 +146,13 @@ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
|
|
136
146
|
when :BULLET, :LALPHA, :NUMBER, :UALPHA then
|
137
147
|
"<p>"
|
138
148
|
when :LABEL, :NOTE then
|
139
|
-
|
149
|
+
labels = Array(list_item.label).map do |label|
|
150
|
+
to_html label
|
151
|
+
end.join ', '
|
152
|
+
|
153
|
+
labels << " — " unless labels.empty?
|
154
|
+
|
155
|
+
start = "<p>#{labels}"
|
140
156
|
@characters += 1 # try to include the label
|
141
157
|
start
|
142
158
|
else
|
@@ -0,0 +1,68 @@
|
|
1
|
+
##
|
2
|
+
# Joins the parts of an RDoc::Markup::Paragraph into a single String.
|
3
|
+
#
|
4
|
+
# This allows for easier maintenance and testing of Markdown support.
|
5
|
+
#
|
6
|
+
# This formatter only works on Paragraph instances. Attempting to process
|
7
|
+
# other markup syntax items will not work.
|
8
|
+
|
9
|
+
class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
|
10
|
+
|
11
|
+
def initialize # :nodoc:
|
12
|
+
super nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def start_accepting
|
16
|
+
end
|
17
|
+
|
18
|
+
def end_accepting
|
19
|
+
end
|
20
|
+
|
21
|
+
def accept_paragraph paragraph
|
22
|
+
parts = []
|
23
|
+
string = false
|
24
|
+
|
25
|
+
paragraph.parts.each do |part|
|
26
|
+
if String === part then
|
27
|
+
if string then
|
28
|
+
string << part
|
29
|
+
else
|
30
|
+
parts << part
|
31
|
+
string = part
|
32
|
+
end
|
33
|
+
else
|
34
|
+
parts << part
|
35
|
+
string = false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
parts = parts.map do |part|
|
40
|
+
if String === part then
|
41
|
+
part.rstrip
|
42
|
+
else
|
43
|
+
part
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# TODO use Enumerable#chunk when ruby 1.8 support is dropped
|
48
|
+
#parts = paragraph.parts.chunk do |part|
|
49
|
+
# String === part
|
50
|
+
#end.map do |string, chunk|
|
51
|
+
# string ? chunk.join.rstrip : chunk
|
52
|
+
#end.flatten
|
53
|
+
|
54
|
+
paragraph.parts.replace parts
|
55
|
+
end
|
56
|
+
|
57
|
+
alias accept_block_quote ignore
|
58
|
+
alias accept_heading ignore
|
59
|
+
alias accept_list_end ignore
|
60
|
+
alias accept_list_item_end ignore
|
61
|
+
alias accept_list_item_start ignore
|
62
|
+
alias accept_list_start ignore
|
63
|
+
alias accept_raw ignore
|
64
|
+
alias accept_rule ignore
|
65
|
+
alias accept_verbatim ignore
|
66
|
+
|
67
|
+
end
|
68
|
+
|
data/lib/rdoc/markup/to_label.rb
CHANGED
@@ -7,11 +7,13 @@ require 'cgi'
|
|
7
7
|
|
8
8
|
class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
9
9
|
|
10
|
+
attr_reader :res # :nodoc:
|
11
|
+
|
10
12
|
##
|
11
13
|
# Creates a new formatter that will output HTML-safe labels
|
12
14
|
|
13
15
|
def initialize markup = nil
|
14
|
-
super
|
16
|
+
super nil, markup
|
15
17
|
|
16
18
|
@markup.add_special RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
|
17
19
|
@markup.add_special(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)
|
@@ -19,6 +21,8 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
|
19
21
|
add_tag :BOLD, '', ''
|
20
22
|
add_tag :TT, '', ''
|
21
23
|
add_tag :EM, '', ''
|
24
|
+
|
25
|
+
@res = []
|
22
26
|
end
|
23
27
|
|
24
28
|
##
|
@@ -51,5 +55,20 @@ class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
|
51
55
|
$1
|
52
56
|
end
|
53
57
|
|
58
|
+
alias accept_blank_line ignore
|
59
|
+
alias accept_block_quote ignore
|
60
|
+
alias accept_heading ignore
|
61
|
+
alias accept_list_end ignore
|
62
|
+
alias accept_list_item_end ignore
|
63
|
+
alias accept_list_item_start ignore
|
64
|
+
alias accept_list_start ignore
|
65
|
+
alias accept_paragraph ignore
|
66
|
+
alias accept_raw ignore
|
67
|
+
alias accept_rule ignore
|
68
|
+
alias accept_verbatim ignore
|
69
|
+
alias end_accepting ignore
|
70
|
+
alias handle_special_HARD_BREAK ignore
|
71
|
+
alias start_accepting ignore
|
72
|
+
|
54
73
|
end
|
55
74
|
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# :markup: markdown
|
2
|
+
|
3
|
+
##
|
4
|
+
# Outputs parsed markup as Markdown
|
5
|
+
|
6
|
+
class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
7
|
+
|
8
|
+
##
|
9
|
+
# Creates a new formatter that will output Markdown format text
|
10
|
+
|
11
|
+
def initialize markup = nil
|
12
|
+
super
|
13
|
+
|
14
|
+
@headings[1] = ['# ', '']
|
15
|
+
@headings[2] = ['## ', '']
|
16
|
+
@headings[3] = ['### ', '']
|
17
|
+
@headings[4] = ['#### ', '']
|
18
|
+
@headings[5] = ['##### ', '']
|
19
|
+
@headings[6] = ['###### ', '']
|
20
|
+
|
21
|
+
@hard_break = " \n"
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Maps attributes to HTML sequences
|
26
|
+
|
27
|
+
def init_tags
|
28
|
+
add_tag :BOLD, '**', '**'
|
29
|
+
add_tag :EM, '*', '*'
|
30
|
+
add_tag :TT, '`', '`'
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Adds a newline to the output
|
35
|
+
|
36
|
+
def handle_special_HARD_BREAK special
|
37
|
+
" \n"
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Finishes consumption of `list`
|
42
|
+
|
43
|
+
def accept_list_end list
|
44
|
+
@res << "\n"
|
45
|
+
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# Finishes consumption of `list_item`
|
51
|
+
|
52
|
+
def accept_list_item_end list_item
|
53
|
+
width = case @list_type.last
|
54
|
+
when :BULLET then
|
55
|
+
4
|
56
|
+
when :NOTE, :LABEL then
|
57
|
+
use_prefix
|
58
|
+
|
59
|
+
4
|
60
|
+
else
|
61
|
+
@list_index[-1] = @list_index.last.succ
|
62
|
+
4
|
63
|
+
end
|
64
|
+
|
65
|
+
@indent -= width
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Prepares the visitor for consuming `list_item`
|
70
|
+
|
71
|
+
def accept_list_item_start list_item
|
72
|
+
type = @list_type.last
|
73
|
+
|
74
|
+
case type
|
75
|
+
when :NOTE, :LABEL then
|
76
|
+
bullets = Array(list_item.label).map do |label|
|
77
|
+
attributes(label).strip
|
78
|
+
end.join "\n"
|
79
|
+
|
80
|
+
bullets << "\n:"
|
81
|
+
|
82
|
+
@prefix = ' ' * @indent
|
83
|
+
@indent += 4
|
84
|
+
@prefix << bullets + (' ' * (@indent - 1))
|
85
|
+
else
|
86
|
+
bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.'
|
87
|
+
@prefix = (' ' * @indent) + bullet.ljust(4)
|
88
|
+
|
89
|
+
@indent += 4
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Prepares the visitor for consuming `list`
|
95
|
+
|
96
|
+
def accept_list_start list
|
97
|
+
case list.type
|
98
|
+
when :BULLET, :LABEL, :NOTE then
|
99
|
+
@list_index << nil
|
100
|
+
when :LALPHA, :NUMBER, :UALPHA then
|
101
|
+
@list_index << 1
|
102
|
+
else
|
103
|
+
raise RDoc::Error, "invalid list type #{list.type}"
|
104
|
+
end
|
105
|
+
|
106
|
+
@list_width << 4
|
107
|
+
@list_type << list.type
|
108
|
+
end
|
109
|
+
|
110
|
+
##
|
111
|
+
# Adds `rule` to the output
|
112
|
+
|
113
|
+
def accept_rule rule
|
114
|
+
use_prefix or @res << ' ' * @indent
|
115
|
+
@res << '-' * 3
|
116
|
+
@res << "\n"
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# Outputs `verbatim` indented 4 columns
|
121
|
+
|
122
|
+
def accept_verbatim verbatim
|
123
|
+
indent = ' ' * (@indent + 4)
|
124
|
+
|
125
|
+
verbatim.parts.each do |part|
|
126
|
+
@res << indent unless part == "\n"
|
127
|
+
@res << part
|
128
|
+
end
|
129
|
+
|
130
|
+
@res << "\n" unless @res =~ /\n\z/
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|