gitlab-rdoc 6.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
##
|
|
3
|
+
# Joins the parts of an RDoc::Markup::Paragraph into a single String.
|
|
4
|
+
#
|
|
5
|
+
# This allows for easier maintenance and testing of Markdown support.
|
|
6
|
+
#
|
|
7
|
+
# This formatter only works on Paragraph instances. Attempting to process
|
|
8
|
+
# other markup syntax items will not work.
|
|
9
|
+
|
|
10
|
+
class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
|
|
11
|
+
|
|
12
|
+
def initialize # :nodoc:
|
|
13
|
+
super nil
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def start_accepting # :nodoc:
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def end_accepting # :nodoc:
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
##
|
|
23
|
+
# Converts the parts of +paragraph+ to a single entry.
|
|
24
|
+
|
|
25
|
+
def accept_paragraph paragraph
|
|
26
|
+
parts = paragraph.parts.chunk do |part|
|
|
27
|
+
String === part
|
|
28
|
+
end.map do |string, chunk|
|
|
29
|
+
string ? chunk.join.rstrip : chunk
|
|
30
|
+
end.flatten
|
|
31
|
+
|
|
32
|
+
paragraph.parts.replace parts
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
alias accept_block_quote ignore
|
|
36
|
+
alias accept_heading ignore
|
|
37
|
+
alias accept_list_end ignore
|
|
38
|
+
alias accept_list_item_end ignore
|
|
39
|
+
alias accept_list_item_start ignore
|
|
40
|
+
alias accept_list_start ignore
|
|
41
|
+
alias accept_raw ignore
|
|
42
|
+
alias accept_rule ignore
|
|
43
|
+
alias accept_verbatim ignore
|
|
44
|
+
alias accept_table ignore
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'cgi'
|
|
3
|
+
|
|
4
|
+
##
|
|
5
|
+
# Creates HTML-safe labels suitable for use in id attributes. Tidylinks are
|
|
6
|
+
# converted to their link part and cross-reference links have the suppression
|
|
7
|
+
# marks removed (\\SomeClass is converted to SomeClass).
|
|
8
|
+
|
|
9
|
+
class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
|
|
10
|
+
|
|
11
|
+
attr_reader :res # :nodoc:
|
|
12
|
+
|
|
13
|
+
##
|
|
14
|
+
# Creates a new formatter that will output HTML-safe labels
|
|
15
|
+
|
|
16
|
+
def initialize markup = nil
|
|
17
|
+
super nil, markup
|
|
18
|
+
|
|
19
|
+
@markup.add_regexp_handling RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
|
|
20
|
+
@markup.add_regexp_handling(/(((\{.*?\})|\b\S+?)\[\S+?\])/, :TIDYLINK)
|
|
21
|
+
|
|
22
|
+
add_tag :BOLD, '', ''
|
|
23
|
+
add_tag :TT, '', ''
|
|
24
|
+
add_tag :EM, '', ''
|
|
25
|
+
|
|
26
|
+
@res = []
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
##
|
|
30
|
+
# Converts +text+ to an HTML-safe label
|
|
31
|
+
|
|
32
|
+
def convert text
|
|
33
|
+
label = convert_flow @am.flow text
|
|
34
|
+
|
|
35
|
+
CGI.escape(label).gsub('%', '-').sub(/^-/, '')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
# Converts the CROSSREF +target+ to plain text, removing the suppression
|
|
40
|
+
# marker, if any
|
|
41
|
+
|
|
42
|
+
def handle_regexp_CROSSREF target
|
|
43
|
+
text = target.text
|
|
44
|
+
|
|
45
|
+
text.sub(/^\\/, '')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
##
|
|
49
|
+
# Converts the TIDYLINK +target+ to just the text part
|
|
50
|
+
|
|
51
|
+
def handle_regexp_TIDYLINK target
|
|
52
|
+
text = target.text
|
|
53
|
+
|
|
54
|
+
return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
|
|
55
|
+
|
|
56
|
+
$1
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
alias accept_blank_line ignore
|
|
60
|
+
alias accept_block_quote ignore
|
|
61
|
+
alias accept_heading ignore
|
|
62
|
+
alias accept_list_end ignore
|
|
63
|
+
alias accept_list_item_end ignore
|
|
64
|
+
alias accept_list_item_start ignore
|
|
65
|
+
alias accept_list_start ignore
|
|
66
|
+
alias accept_paragraph ignore
|
|
67
|
+
alias accept_raw ignore
|
|
68
|
+
alias accept_rule ignore
|
|
69
|
+
alias accept_verbatim ignore
|
|
70
|
+
alias end_accepting ignore
|
|
71
|
+
alias handle_regexp_HARD_BREAK ignore
|
|
72
|
+
alias start_accepting ignore
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# :markup: markdown
|
|
3
|
+
|
|
4
|
+
##
|
|
5
|
+
# Outputs parsed markup as Markdown
|
|
6
|
+
|
|
7
|
+
class RDoc::Markup::ToMarkdown < RDoc::Markup::ToRdoc
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
# Creates a new formatter that will output Markdown format text
|
|
11
|
+
|
|
12
|
+
def initialize markup = nil
|
|
13
|
+
super
|
|
14
|
+
|
|
15
|
+
@headings[1] = ['# ', '']
|
|
16
|
+
@headings[2] = ['## ', '']
|
|
17
|
+
@headings[3] = ['### ', '']
|
|
18
|
+
@headings[4] = ['#### ', '']
|
|
19
|
+
@headings[5] = ['##### ', '']
|
|
20
|
+
@headings[6] = ['###### ', '']
|
|
21
|
+
|
|
22
|
+
add_regexp_handling_RDOCLINK
|
|
23
|
+
add_regexp_handling_TIDYLINK
|
|
24
|
+
|
|
25
|
+
@hard_break = " \n"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
# Maps attributes to HTML sequences
|
|
30
|
+
|
|
31
|
+
def init_tags
|
|
32
|
+
add_tag :BOLD, '**', '**'
|
|
33
|
+
add_tag :EM, '*', '*'
|
|
34
|
+
add_tag :TT, '`', '`'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
##
|
|
38
|
+
# Adds a newline to the output
|
|
39
|
+
|
|
40
|
+
def handle_regexp_HARD_BREAK target
|
|
41
|
+
" \n"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
##
|
|
45
|
+
# Finishes consumption of `list`
|
|
46
|
+
|
|
47
|
+
def accept_list_end list
|
|
48
|
+
@res << "\n"
|
|
49
|
+
|
|
50
|
+
super
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
##
|
|
54
|
+
# Finishes consumption of `list_item`
|
|
55
|
+
|
|
56
|
+
def accept_list_item_end list_item
|
|
57
|
+
width = case @list_type.last
|
|
58
|
+
when :BULLET then
|
|
59
|
+
4
|
|
60
|
+
when :NOTE, :LABEL then
|
|
61
|
+
use_prefix
|
|
62
|
+
|
|
63
|
+
4
|
|
64
|
+
else
|
|
65
|
+
@list_index[-1] = @list_index.last.succ
|
|
66
|
+
4
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
@indent -= width
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
##
|
|
73
|
+
# Prepares the visitor for consuming `list_item`
|
|
74
|
+
|
|
75
|
+
def accept_list_item_start list_item
|
|
76
|
+
type = @list_type.last
|
|
77
|
+
|
|
78
|
+
case type
|
|
79
|
+
when :NOTE, :LABEL then
|
|
80
|
+
bullets = Array(list_item.label).map do |label|
|
|
81
|
+
attributes(label).strip
|
|
82
|
+
end.join "\n"
|
|
83
|
+
|
|
84
|
+
bullets << "\n:"
|
|
85
|
+
|
|
86
|
+
@prefix = ' ' * @indent
|
|
87
|
+
@indent += 4
|
|
88
|
+
@prefix << bullets + (' ' * (@indent - 1))
|
|
89
|
+
else
|
|
90
|
+
bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.'
|
|
91
|
+
@prefix = (' ' * @indent) + bullet.ljust(4)
|
|
92
|
+
|
|
93
|
+
@indent += 4
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
##
|
|
98
|
+
# Prepares the visitor for consuming `list`
|
|
99
|
+
|
|
100
|
+
def accept_list_start list
|
|
101
|
+
case list.type
|
|
102
|
+
when :BULLET, :LABEL, :NOTE then
|
|
103
|
+
@list_index << nil
|
|
104
|
+
when :LALPHA, :NUMBER, :UALPHA then
|
|
105
|
+
@list_index << 1
|
|
106
|
+
else
|
|
107
|
+
raise RDoc::Error, "invalid list type #{list.type}"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
@list_width << 4
|
|
111
|
+
@list_type << list.type
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
##
|
|
115
|
+
# Adds `rule` to the output
|
|
116
|
+
|
|
117
|
+
def accept_rule rule
|
|
118
|
+
use_prefix or @res << ' ' * @indent
|
|
119
|
+
@res << '-' * 3
|
|
120
|
+
@res << "\n"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
##
|
|
124
|
+
# Outputs `verbatim` indented 4 columns
|
|
125
|
+
|
|
126
|
+
def accept_verbatim verbatim
|
|
127
|
+
indent = ' ' * (@indent + 4)
|
|
128
|
+
|
|
129
|
+
verbatim.parts.each do |part|
|
|
130
|
+
@res << indent unless part == "\n"
|
|
131
|
+
@res << part
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
@res << "\n"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
##
|
|
138
|
+
# Creates a Markdown-style URL from +url+ with +text+.
|
|
139
|
+
|
|
140
|
+
def gen_url url, text
|
|
141
|
+
scheme, url, = parse_url url
|
|
142
|
+
|
|
143
|
+
"[#{text.sub(%r{^#{scheme}:/*}i, '')}](#{url})"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
##
|
|
147
|
+
# Handles <tt>rdoc-</tt> type links for footnotes.
|
|
148
|
+
|
|
149
|
+
def handle_rdoc_link url
|
|
150
|
+
case url
|
|
151
|
+
when /^rdoc-ref:/ then
|
|
152
|
+
$'
|
|
153
|
+
when /^rdoc-label:footmark-(\d+)/ then
|
|
154
|
+
"[^#{$1}]:"
|
|
155
|
+
when /^rdoc-label:foottext-(\d+)/ then
|
|
156
|
+
"[^#{$1}]"
|
|
157
|
+
when /^rdoc-label:label-/ then
|
|
158
|
+
gen_url url, $'
|
|
159
|
+
when /^rdoc-image:/ then
|
|
160
|
+
""
|
|
161
|
+
when /^rdoc-[a-z]+:/ then
|
|
162
|
+
$'
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
##
|
|
167
|
+
# Converts the RDoc markup tidylink into a Markdown.style link.
|
|
168
|
+
|
|
169
|
+
def handle_regexp_TIDYLINK target
|
|
170
|
+
text = target.text
|
|
171
|
+
|
|
172
|
+
return text unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
|
|
173
|
+
|
|
174
|
+
label = $1
|
|
175
|
+
url = $2
|
|
176
|
+
|
|
177
|
+
if url =~ /^rdoc-label:foot/ then
|
|
178
|
+
handle_rdoc_link url
|
|
179
|
+
else
|
|
180
|
+
gen_url url, label
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
##
|
|
185
|
+
# Converts the rdoc-...: links into a Markdown.style links.
|
|
186
|
+
|
|
187
|
+
def handle_regexp_RDOCLINK target
|
|
188
|
+
handle_rdoc_link target.text
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
end
|
|
192
|
+
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
##
|
|
3
|
+
# Outputs RDoc markup as RDoc markup! (mostly)
|
|
4
|
+
|
|
5
|
+
class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
|
|
6
|
+
|
|
7
|
+
##
|
|
8
|
+
# Current indent amount for output in characters
|
|
9
|
+
|
|
10
|
+
attr_accessor :indent
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
# Output width in characters
|
|
14
|
+
|
|
15
|
+
attr_accessor :width
|
|
16
|
+
|
|
17
|
+
##
|
|
18
|
+
# Stack of current list indexes for alphabetic and numeric lists
|
|
19
|
+
|
|
20
|
+
attr_reader :list_index
|
|
21
|
+
|
|
22
|
+
##
|
|
23
|
+
# Stack of list types
|
|
24
|
+
|
|
25
|
+
attr_reader :list_type
|
|
26
|
+
|
|
27
|
+
##
|
|
28
|
+
# Stack of list widths for indentation
|
|
29
|
+
|
|
30
|
+
attr_reader :list_width
|
|
31
|
+
|
|
32
|
+
##
|
|
33
|
+
# Prefix for the next list item. See #use_prefix
|
|
34
|
+
|
|
35
|
+
attr_reader :prefix
|
|
36
|
+
|
|
37
|
+
##
|
|
38
|
+
# Output accumulator
|
|
39
|
+
|
|
40
|
+
attr_reader :res
|
|
41
|
+
|
|
42
|
+
##
|
|
43
|
+
# Creates a new formatter that will output (mostly) \RDoc markup
|
|
44
|
+
|
|
45
|
+
def initialize markup = nil
|
|
46
|
+
super nil, markup
|
|
47
|
+
|
|
48
|
+
@markup.add_regexp_handling(/\\\S/, :SUPPRESSED_CROSSREF)
|
|
49
|
+
@width = 78
|
|
50
|
+
init_tags
|
|
51
|
+
|
|
52
|
+
@headings = {}
|
|
53
|
+
@headings.default = []
|
|
54
|
+
|
|
55
|
+
@headings[1] = ['= ', '']
|
|
56
|
+
@headings[2] = ['== ', '']
|
|
57
|
+
@headings[3] = ['=== ', '']
|
|
58
|
+
@headings[4] = ['==== ', '']
|
|
59
|
+
@headings[5] = ['===== ', '']
|
|
60
|
+
@headings[6] = ['====== ', '']
|
|
61
|
+
|
|
62
|
+
@hard_break = "\n"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
##
|
|
66
|
+
# Maps attributes to HTML sequences
|
|
67
|
+
|
|
68
|
+
def init_tags
|
|
69
|
+
add_tag :BOLD, "<b>", "</b>"
|
|
70
|
+
add_tag :TT, "<tt>", "</tt>"
|
|
71
|
+
add_tag :EM, "<em>", "</em>"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
##
|
|
75
|
+
# Adds +blank_line+ to the output
|
|
76
|
+
|
|
77
|
+
def accept_blank_line blank_line
|
|
78
|
+
@res << "\n"
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
##
|
|
82
|
+
# Adds +paragraph+ to the output
|
|
83
|
+
|
|
84
|
+
def accept_block_quote block_quote
|
|
85
|
+
@indent += 2
|
|
86
|
+
|
|
87
|
+
block_quote.parts.each do |part|
|
|
88
|
+
@prefix = '> '
|
|
89
|
+
|
|
90
|
+
part.accept self
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
@indent -= 2
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
##
|
|
97
|
+
# Adds +heading+ to the output
|
|
98
|
+
|
|
99
|
+
def accept_heading heading
|
|
100
|
+
use_prefix or @res << ' ' * @indent
|
|
101
|
+
@res << @headings[heading.level][0]
|
|
102
|
+
@res << attributes(heading.text)
|
|
103
|
+
@res << @headings[heading.level][1]
|
|
104
|
+
@res << "\n"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
##
|
|
108
|
+
# Finishes consumption of +list+
|
|
109
|
+
|
|
110
|
+
def accept_list_end list
|
|
111
|
+
@list_index.pop
|
|
112
|
+
@list_type.pop
|
|
113
|
+
@list_width.pop
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
##
|
|
117
|
+
# Finishes consumption of +list_item+
|
|
118
|
+
|
|
119
|
+
def accept_list_item_end list_item
|
|
120
|
+
width = case @list_type.last
|
|
121
|
+
when :BULLET then
|
|
122
|
+
2
|
|
123
|
+
when :NOTE, :LABEL then
|
|
124
|
+
if @prefix then
|
|
125
|
+
@res << @prefix.strip
|
|
126
|
+
@prefix = nil
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
@res << "\n"
|
|
130
|
+
2
|
|
131
|
+
else
|
|
132
|
+
bullet = @list_index.last.to_s
|
|
133
|
+
@list_index[-1] = @list_index.last.succ
|
|
134
|
+
bullet.length + 2
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
@indent -= width
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
##
|
|
141
|
+
# Prepares the visitor for consuming +list_item+
|
|
142
|
+
|
|
143
|
+
def accept_list_item_start list_item
|
|
144
|
+
type = @list_type.last
|
|
145
|
+
|
|
146
|
+
case type
|
|
147
|
+
when :NOTE, :LABEL then
|
|
148
|
+
bullets = Array(list_item.label).map do |label|
|
|
149
|
+
attributes(label).strip
|
|
150
|
+
end.join "\n"
|
|
151
|
+
|
|
152
|
+
bullets << ":\n" unless bullets.empty?
|
|
153
|
+
|
|
154
|
+
@prefix = ' ' * @indent
|
|
155
|
+
@indent += 2
|
|
156
|
+
@prefix << bullets + (' ' * @indent)
|
|
157
|
+
else
|
|
158
|
+
bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.'
|
|
159
|
+
@prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1)
|
|
160
|
+
width = bullet.length + 1
|
|
161
|
+
@indent += width
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
##
|
|
166
|
+
# Prepares the visitor for consuming +list+
|
|
167
|
+
|
|
168
|
+
def accept_list_start list
|
|
169
|
+
case list.type
|
|
170
|
+
when :BULLET then
|
|
171
|
+
@list_index << nil
|
|
172
|
+
@list_width << 1
|
|
173
|
+
when :LABEL, :NOTE then
|
|
174
|
+
@list_index << nil
|
|
175
|
+
@list_width << 2
|
|
176
|
+
when :LALPHA then
|
|
177
|
+
@list_index << 'a'
|
|
178
|
+
@list_width << list.items.length.to_s.length
|
|
179
|
+
when :NUMBER then
|
|
180
|
+
@list_index << 1
|
|
181
|
+
@list_width << list.items.length.to_s.length
|
|
182
|
+
when :UALPHA then
|
|
183
|
+
@list_index << 'A'
|
|
184
|
+
@list_width << list.items.length.to_s.length
|
|
185
|
+
else
|
|
186
|
+
raise RDoc::Error, "invalid list type #{list.type}"
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
@list_type << list.type
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
##
|
|
193
|
+
# Adds +paragraph+ to the output
|
|
194
|
+
|
|
195
|
+
def accept_paragraph paragraph
|
|
196
|
+
text = paragraph.text @hard_break
|
|
197
|
+
wrap attributes text
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
##
|
|
201
|
+
# Adds +paragraph+ to the output
|
|
202
|
+
|
|
203
|
+
def accept_indented_paragraph paragraph
|
|
204
|
+
@indent += paragraph.indent
|
|
205
|
+
text = paragraph.text @hard_break
|
|
206
|
+
wrap attributes text
|
|
207
|
+
@indent -= paragraph.indent
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
##
|
|
211
|
+
# Adds +raw+ to the output
|
|
212
|
+
|
|
213
|
+
def accept_raw raw
|
|
214
|
+
@res << raw.parts.join("\n")
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
##
|
|
218
|
+
# Adds +rule+ to the output
|
|
219
|
+
|
|
220
|
+
def accept_rule rule
|
|
221
|
+
use_prefix or @res << ' ' * @indent
|
|
222
|
+
@res << '-' * (@width - @indent)
|
|
223
|
+
@res << "\n"
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
##
|
|
227
|
+
# Outputs +verbatim+ indented 2 columns
|
|
228
|
+
|
|
229
|
+
def accept_verbatim verbatim
|
|
230
|
+
indent = ' ' * (@indent + 2)
|
|
231
|
+
|
|
232
|
+
verbatim.parts.each do |part|
|
|
233
|
+
@res << indent unless part == "\n"
|
|
234
|
+
@res << part
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
@res << "\n"
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
##
|
|
241
|
+
# Adds +table+ to the output
|
|
242
|
+
|
|
243
|
+
def accept_table header, body, aligns
|
|
244
|
+
widths = header.zip(body) do |h, b|
|
|
245
|
+
[h.size, b.size].max
|
|
246
|
+
end
|
|
247
|
+
aligns = aligns.map do |a|
|
|
248
|
+
case a
|
|
249
|
+
when nil
|
|
250
|
+
:center
|
|
251
|
+
when :left
|
|
252
|
+
:ljust
|
|
253
|
+
when :right
|
|
254
|
+
:rjust
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
@res << header.zip(widths, aligns) do |h, w, a|
|
|
258
|
+
h.__send__(a, w)
|
|
259
|
+
end.join("|").rstrip << "\n"
|
|
260
|
+
@res << widths.map {|w| "-" * w }.join("|") << "\n"
|
|
261
|
+
body.each do |row|
|
|
262
|
+
@res << row.zip(widths, aligns) do |t, w, a|
|
|
263
|
+
t.__send__(a, w)
|
|
264
|
+
end.join("|").rstrip << "\n"
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
##
|
|
269
|
+
# Applies attribute-specific markup to +text+ using RDoc::AttributeManager
|
|
270
|
+
|
|
271
|
+
def attributes text
|
|
272
|
+
flow = @am.flow text.dup
|
|
273
|
+
convert_flow flow
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
##
|
|
277
|
+
# Returns the generated output
|
|
278
|
+
|
|
279
|
+
def end_accepting
|
|
280
|
+
@res.join
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
##
|
|
284
|
+
# Removes preceding \\ from the suppressed crossref +target+
|
|
285
|
+
|
|
286
|
+
def handle_regexp_SUPPRESSED_CROSSREF target
|
|
287
|
+
text = target.text
|
|
288
|
+
text = text.sub('\\', '') unless in_tt?
|
|
289
|
+
text
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
##
|
|
293
|
+
# Adds a newline to the output
|
|
294
|
+
|
|
295
|
+
def handle_regexp_HARD_BREAK target
|
|
296
|
+
"\n"
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
##
|
|
300
|
+
# Prepares the visitor for text generation
|
|
301
|
+
|
|
302
|
+
def start_accepting
|
|
303
|
+
@res = [""]
|
|
304
|
+
@indent = 0
|
|
305
|
+
@prefix = nil
|
|
306
|
+
|
|
307
|
+
@list_index = []
|
|
308
|
+
@list_type = []
|
|
309
|
+
@list_width = []
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
##
|
|
313
|
+
# Adds the stored #prefix to the output and clears it. Lists generate a
|
|
314
|
+
# prefix for later consumption.
|
|
315
|
+
|
|
316
|
+
def use_prefix
|
|
317
|
+
prefix, @prefix = @prefix, nil
|
|
318
|
+
@res << prefix if prefix
|
|
319
|
+
|
|
320
|
+
prefix
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
##
|
|
324
|
+
# Wraps +text+ to #width
|
|
325
|
+
|
|
326
|
+
def wrap text
|
|
327
|
+
return unless text && !text.empty?
|
|
328
|
+
|
|
329
|
+
text_len = @width - @indent
|
|
330
|
+
|
|
331
|
+
text_len = 20 if text_len < 20
|
|
332
|
+
|
|
333
|
+
re = /^(.{0,#{text_len}})[ \n]/
|
|
334
|
+
next_prefix = ' ' * @indent
|
|
335
|
+
|
|
336
|
+
prefix = @prefix || next_prefix
|
|
337
|
+
@prefix = nil
|
|
338
|
+
|
|
339
|
+
@res << prefix
|
|
340
|
+
|
|
341
|
+
while text.length > text_len
|
|
342
|
+
if text =~ re then
|
|
343
|
+
@res << $1
|
|
344
|
+
text.slice!(0, $&.length)
|
|
345
|
+
else
|
|
346
|
+
@res << text.slice!(0, text_len)
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
@res << "\n" << next_prefix
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
if text.empty? then
|
|
353
|
+
@res.pop
|
|
354
|
+
@res.pop
|
|
355
|
+
else
|
|
356
|
+
@res << text
|
|
357
|
+
@res << "\n"
|
|
358
|
+
end
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
end
|
|
362
|
+
|