rdoc 6.17.0 → 8.1.0
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 +4 -4
- data/CONTRIBUTING.md +193 -0
- data/LEGAL.rdoc +6 -0
- data/LICENSE.rdoc +4 -0
- data/README.md +132 -8
- data/RI.md +75 -75
- data/doc/markup_reference/markdown.md +659 -0
- data/doc/markup_reference/rdoc.rdoc +1169 -0
- data/exe/rdoc +2 -2
- data/lib/rdoc/code_object/alias.rb +70 -74
- data/lib/rdoc/code_object/any_method.rb +308 -293
- data/lib/rdoc/code_object/attr.rb +150 -142
- data/lib/rdoc/code_object/class_module.rb +802 -715
- data/lib/rdoc/code_object/constant.rb +181 -144
- data/lib/rdoc/code_object/context/section.rb +140 -130
- data/lib/rdoc/code_object/context.rb +925 -941
- data/lib/rdoc/code_object/extend.rb +7 -5
- data/lib/rdoc/code_object/include.rb +7 -5
- data/lib/rdoc/code_object/method_attr.rb +328 -315
- data/lib/rdoc/code_object/mixin.rb +97 -92
- data/lib/rdoc/code_object/normal_class.rb +77 -78
- data/lib/rdoc/code_object/normal_module.rb +61 -59
- data/lib/rdoc/code_object/require.rb +23 -39
- data/lib/rdoc/code_object/single_class.rb +21 -19
- data/lib/rdoc/code_object/top_level.rb +215 -202
- data/lib/rdoc/code_object.rb +305 -305
- data/lib/rdoc/comment.rb +274 -337
- data/lib/rdoc/cross_reference.rb +195 -206
- data/lib/rdoc/encoding.rb +105 -103
- data/lib/rdoc/erb_partial.rb +13 -11
- data/lib/rdoc/erbio.rb +29 -27
- data/lib/rdoc/generator/aliki.rb +196 -30
- data/lib/rdoc/generator/darkfish.rb +647 -629
- data/lib/rdoc/generator/json_index.rb +233 -229
- data/lib/rdoc/generator/markup.rb +165 -122
- data/lib/rdoc/generator/pot/message_extractor.rb +57 -51
- data/lib/rdoc/generator/pot/po.rb +52 -51
- data/lib/rdoc/generator/pot/po_entry.rb +138 -132
- data/lib/rdoc/generator/pot.rb +85 -81
- data/lib/rdoc/generator/ri.rb +23 -19
- data/lib/rdoc/generator/template/aliki/DESIGN.md +538 -0
- data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_footer.rhtml +2 -2
- data/lib/rdoc/generator/template/aliki/_head.rhtml +15 -10
- data/lib/rdoc/generator/template/aliki/_header.rhtml +29 -44
- data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +8 -6
- data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +8 -6
- data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +3 -3
- data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +3 -3
- data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/class.rhtml +71 -61
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +796 -323
- data/lib/rdoc/generator/template/aliki/index.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/js/aliki.js +119 -113
- data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
- data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
- data/lib/rdoc/generator/template/aliki/js/{search.js → search_controller.js} +16 -7
- data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
- data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
- data/lib/rdoc/generator/template/aliki/page.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +1 -1
- data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_footer.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +8 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +8 -6
- data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +2 -2
- data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +1 -1
- data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +5 -5
- data/lib/rdoc/generator/template/darkfish/class.rhtml +29 -32
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -1
- data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +3 -3
- data/lib/rdoc/generator.rb +48 -46
- data/lib/rdoc/i18n/locale.rb +99 -95
- data/lib/rdoc/i18n/text.rb +109 -105
- data/lib/rdoc/i18n.rb +7 -5
- data/lib/rdoc/markdown/byte_runtime.rb +80 -0
- data/lib/rdoc/markdown.kpeg +52 -33
- data/lib/rdoc/markdown.rb +365 -177
- data/lib/rdoc/markup/blank_line.rb +25 -23
- data/lib/rdoc/markup/block_quote.rb +12 -8
- data/lib/rdoc/markup/document.rb +127 -123
- data/lib/rdoc/markup/element.rb +21 -0
- data/lib/rdoc/markup/formatter.rb +220 -203
- data/lib/rdoc/markup/hard_break.rb +30 -27
- data/lib/rdoc/markup/heading.rb +163 -77
- data/lib/rdoc/markup/include.rb +33 -29
- data/lib/rdoc/markup/indented_paragraph.rb +37 -33
- data/lib/rdoc/markup/inline_parser.rb +316 -0
- data/lib/rdoc/markup/list.rb +80 -88
- data/lib/rdoc/markup/list_item.rb +73 -85
- data/lib/rdoc/markup/paragraph.rb +23 -19
- data/lib/rdoc/markup/parser.rb +501 -497
- data/lib/rdoc/markup/pre_process.rb +284 -305
- data/lib/rdoc/markup/raw.rb +52 -55
- data/lib/rdoc/markup/rule.rb +16 -12
- data/lib/rdoc/markup/table.rb +48 -40
- data/lib/rdoc/markup/to_ansi.rb +143 -92
- data/lib/rdoc/markup/to_bs.rb +86 -102
- data/lib/rdoc/markup/to_html.rb +608 -506
- data/lib/rdoc/markup/to_html_crossref.rb +219 -210
- data/lib/rdoc/markup/to_html_snippet.rb +210 -205
- data/lib/rdoc/markup/to_joined_paragraph.rb +40 -41
- data/lib/rdoc/markup/to_label.rb +64 -51
- data/lib/rdoc/markup/to_markdown.rb +212 -184
- data/lib/rdoc/markup/to_rdoc.rb +341 -277
- data/lib/rdoc/markup/to_table_of_contents.rb +66 -62
- data/lib/rdoc/markup/to_test.rb +62 -50
- data/lib/rdoc/markup/to_tt_only.rb +83 -92
- data/lib/rdoc/markup/verbatim.rb +62 -58
- data/lib/rdoc/markup.rb +196 -215
- data/lib/rdoc/options.rb +1063 -1076
- data/lib/rdoc/parser/c.rb +1039 -1036
- data/lib/rdoc/parser/changelog.rb +320 -287
- data/lib/rdoc/parser/markdown.rb +17 -13
- data/lib/rdoc/parser/rbs.rb +279 -0
- data/lib/rdoc/parser/rd.rb +17 -13
- data/lib/rdoc/parser/ruby.rb +1231 -2222
- data/lib/rdoc/parser/ruby_colorizer.rb +303 -0
- data/lib/rdoc/parser/simple.rb +31 -27
- data/lib/rdoc/parser/text.rb +12 -8
- data/lib/rdoc/parser.rb +230 -221
- data/lib/rdoc/rbs_helper.rb +186 -0
- data/lib/rdoc/rd/inline.rb +57 -53
- data/lib/rdoc/rd.rb +90 -88
- data/lib/rdoc/rdoc.rb +547 -366
- data/lib/rdoc/ri/driver.rb +1141 -1130
- data/lib/rdoc/ri/formatter.rb +7 -3
- data/lib/rdoc/ri/paths.rb +140 -136
- data/lib/rdoc/ri/servlet.rb +456 -0
- data/lib/rdoc/ri/store.rb +4 -2
- data/lib/rdoc/ri/task.rb +55 -51
- data/lib/rdoc/ri.rb +14 -11
- data/lib/rdoc/rubygems_hook.rb +194 -192
- data/lib/rdoc/server.rb +462 -0
- data/lib/rdoc/stats/normal.rb +46 -42
- data/lib/rdoc/stats/quiet.rb +39 -35
- data/lib/rdoc/stats/verbose.rb +35 -31
- data/lib/rdoc/stats.rb +363 -338
- data/lib/rdoc/store.rb +919 -725
- data/lib/rdoc/task.rb +260 -255
- data/lib/rdoc/text.rb +164 -240
- data/lib/rdoc/token_stream.rb +88 -106
- data/lib/rdoc/tom_doc.rb +203 -201
- data/lib/rdoc/version.rb +1 -1
- data/lib/rdoc.rb +35 -7
- data/lib/rubygems_plugin.rb +2 -11
- data/rdoc-logo.svg +43 -0
- data/rdoc.gemspec +9 -7
- metadata +46 -32
- data/CONTRIBUTING.rdoc +0 -219
- data/ExampleMarkdown.md +0 -39
- data/ExampleRDoc.rdoc +0 -210
- data/lib/rdoc/code_object/anon_class.rb +0 -10
- data/lib/rdoc/code_object/ghost_method.rb +0 -6
- data/lib/rdoc/code_object/meta_method.rb +0 -6
- data/lib/rdoc/markdown/literals.kpeg +0 -21
- data/lib/rdoc/markdown/literals.rb +0 -454
- data/lib/rdoc/markup/attr_changer.rb +0 -22
- data/lib/rdoc/markup/attr_span.rb +0 -35
- data/lib/rdoc/markup/attribute_manager.rb +0 -405
- data/lib/rdoc/markup/attributes.rb +0 -70
- data/lib/rdoc/markup/regexp_handling.rb +0 -40
- data/lib/rdoc/parser/prism_ruby.rb +0 -1100
- data/lib/rdoc/parser/ripper_state_lex.rb +0 -302
- data/lib/rdoc/parser/ruby_tools.rb +0 -163
- data/lib/rdoc/servlet.rb +0 -452
data/lib/rdoc/markup/raw.rb
CHANGED
|
@@ -1,69 +1,66 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
##
|
|
3
|
-
# A section of text that is added to the output document as-is
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
##
|
|
21
|
-
# Appends +text+
|
|
3
|
+
module RDoc
|
|
4
|
+
class Markup
|
|
5
|
+
# A section of text that is added to the output document as-is
|
|
6
|
+
class Raw < Element
|
|
7
|
+
# The component parts of the raw text
|
|
8
|
+
#: Array[String]
|
|
9
|
+
attr_reader :parts
|
|
10
|
+
|
|
11
|
+
# Creates a new Raw containing +parts+
|
|
12
|
+
#: (*String) -> void
|
|
13
|
+
def initialize(*parts)
|
|
14
|
+
@parts = parts
|
|
15
|
+
end
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
# Appends +text+
|
|
18
|
+
#: (String) -> void
|
|
19
|
+
def <<(text)
|
|
20
|
+
@parts << text
|
|
21
|
+
end
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
#: (top) -> bool
|
|
24
|
+
def ==(other) # :nodoc:
|
|
25
|
+
self.class == other.class && @parts == other.parts
|
|
26
|
+
end
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
# Calls #accept_raw+ on +visitor+
|
|
29
|
+
# @override
|
|
30
|
+
#: (untyped) -> void
|
|
31
|
+
def accept(visitor)
|
|
32
|
+
visitor.accept_raw(self)
|
|
33
|
+
end
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
# Appends +other+'s parts
|
|
36
|
+
#: (Raw) -> void
|
|
37
|
+
def merge(other)
|
|
38
|
+
@parts.concat(other.parts)
|
|
39
|
+
end
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
# @override
|
|
42
|
+
#: (PP) -> void
|
|
43
|
+
def pretty_print(q) # :nodoc:
|
|
44
|
+
self.class.name =~ /.*::(\w{1,4})/i
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
q.group(2, "[#{$1.downcase}: ", ']') do
|
|
47
|
+
q.seplist(@parts) do |part|
|
|
48
|
+
q.pp(part)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
44
52
|
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
# Appends +texts+ onto this Paragraph
|
|
54
|
+
#: (*String) -> void
|
|
55
|
+
def push(*texts)
|
|
56
|
+
self.parts.concat(texts)
|
|
57
|
+
end
|
|
47
58
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
# The raw text
|
|
60
|
+
#: () -> String
|
|
61
|
+
def text
|
|
62
|
+
@parts.join(" ")
|
|
51
63
|
end
|
|
52
64
|
end
|
|
53
65
|
end
|
|
54
|
-
|
|
55
|
-
##
|
|
56
|
-
# Appends +texts+ onto this Paragraph
|
|
57
|
-
|
|
58
|
-
def push *texts
|
|
59
|
-
self.parts.concat texts
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
##
|
|
63
|
-
# The raw text
|
|
64
|
-
|
|
65
|
-
def text
|
|
66
|
-
@parts.join ' '
|
|
67
|
-
end
|
|
68
|
-
|
|
69
66
|
end
|
data/lib/rdoc/markup/rule.rb
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
module RDoc
|
|
3
|
+
class Markup
|
|
4
|
+
##
|
|
5
|
+
# A horizontal rule with a weight
|
|
4
6
|
|
|
5
|
-
class
|
|
7
|
+
class Rule < Struct.new :weight
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
##
|
|
10
|
+
# Calls #accept_rule on +visitor+
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
def accept(visitor)
|
|
13
|
+
visitor.accept_rule self
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def pretty_print(q) # :nodoc:
|
|
17
|
+
q.group 2, '[rule:', ']' do
|
|
18
|
+
q.pp weight
|
|
19
|
+
end
|
|
20
|
+
end
|
|
13
21
|
|
|
14
|
-
def pretty_print(q) # :nodoc:
|
|
15
|
-
q.group 2, '[rule:', ']' do
|
|
16
|
-
q.pp weight
|
|
17
22
|
end
|
|
18
23
|
end
|
|
19
|
-
|
|
20
24
|
end
|
data/lib/rdoc/markup/table.rb
CHANGED
|
@@ -1,52 +1,60 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
##
|
|
3
|
-
# A section of table
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
module RDoc
|
|
4
|
+
class Markup
|
|
5
|
+
# A section of table
|
|
6
|
+
class Table < Element
|
|
7
|
+
# Headers of each column
|
|
8
|
+
#: Array[String]
|
|
9
|
+
attr_accessor :header
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
# Alignments of each column
|
|
12
|
+
#: Array[Symbol?]
|
|
13
|
+
attr_accessor :align
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
# Body texts of each column
|
|
16
|
+
#: Array[String]
|
|
17
|
+
attr_accessor :body
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# :stopdoc:
|
|
21
|
-
def ==(other)
|
|
22
|
-
self.class == other.class and
|
|
23
|
-
@header == other.header and
|
|
24
|
-
@align == other.align and
|
|
25
|
-
@body == other.body
|
|
26
|
-
end
|
|
19
|
+
#: (Array[String], Array[Symbol?], Array[String]) -> void
|
|
20
|
+
def initialize(header, align, body)
|
|
21
|
+
@header, @align, @body = header, align, body
|
|
22
|
+
end
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
#: (Object) -> bool
|
|
25
|
+
def ==(other)
|
|
26
|
+
self.class == other.class && @header == other.header &&
|
|
27
|
+
@align == other.align && @body == other.body
|
|
28
|
+
end
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
q.pp text
|
|
37
|
-
if align
|
|
38
|
-
q.text ":"
|
|
39
|
-
q.breakable
|
|
40
|
-
q.text align.to_s
|
|
41
|
-
end
|
|
42
|
-
end
|
|
30
|
+
# @override
|
|
31
|
+
#: (untyped) -> void
|
|
32
|
+
def accept(visitor)
|
|
33
|
+
visitor.accept_table(@header, @body, @align)
|
|
43
34
|
end
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
|
|
36
|
+
# @override
|
|
37
|
+
#: (untyped) -> String
|
|
38
|
+
def pretty_print(q)
|
|
39
|
+
q.group 2, '[Table: ', ']' do
|
|
40
|
+
q.group 2, '[Head: ', ']' do
|
|
41
|
+
q.seplist @header.zip(@align) do |text, align|
|
|
49
42
|
q.pp text
|
|
43
|
+
if align
|
|
44
|
+
q.text ":"
|
|
45
|
+
q.breakable
|
|
46
|
+
q.text align.to_s
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
q.breakable
|
|
51
|
+
q.group 2, '[Body: ', ']' do
|
|
52
|
+
q.seplist @body do |body|
|
|
53
|
+
q.group 2, '[', ']' do
|
|
54
|
+
q.seplist body do |text|
|
|
55
|
+
q.pp text
|
|
56
|
+
end
|
|
57
|
+
end
|
|
50
58
|
end
|
|
51
59
|
end
|
|
52
60
|
end
|
data/lib/rdoc/markup/to_ansi.rb
CHANGED
|
@@ -1,97 +1,148 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
module RDoc
|
|
3
|
+
class Markup
|
|
4
|
+
##
|
|
5
|
+
# Outputs RDoc markup with vibrant ANSI color!
|
|
6
|
+
|
|
7
|
+
class ToAnsi < Markup::ToRdoc
|
|
8
|
+
|
|
9
|
+
##
|
|
10
|
+
# Creates a new ToAnsi visitor that is ready to output vibrant ANSI color!
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
super
|
|
14
|
+
|
|
15
|
+
@headings.clear
|
|
16
|
+
@headings[1] = ["\e[1;32m", "\e[m"] # bold
|
|
17
|
+
@headings[2] = ["\e[4;32m", "\e[m"] # underline
|
|
18
|
+
@headings[3] = ["\e[32m", "\e[m"] # just green
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
##
|
|
22
|
+
# Maps attributes to ANSI sequences
|
|
23
|
+
|
|
24
|
+
ANSI_STYLE_CODES_ON = {
|
|
25
|
+
BOLD: 1,
|
|
26
|
+
TT: 7,
|
|
27
|
+
EM: 4,
|
|
28
|
+
STRIKE: 9
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
ANSI_STYLE_CODES_OFF = {
|
|
32
|
+
BOLD: 22,
|
|
33
|
+
TT: 27,
|
|
34
|
+
EM: 24,
|
|
35
|
+
STRIKE: 29
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# Apply the given attributes by emitting ANSI sequences.
|
|
39
|
+
# Emitting attribute changes are deferred until new text is added and applied in batch.
|
|
40
|
+
# This method computes the necessary ANSI codes to transition from the
|
|
41
|
+
# current set of applied attributes to the new set of +attributes+.
|
|
42
|
+
|
|
43
|
+
def apply_attributes(attributes)
|
|
44
|
+
before = @applied_attributes
|
|
45
|
+
after = attributes.sort
|
|
46
|
+
return if before == after
|
|
47
|
+
|
|
48
|
+
if after.empty?
|
|
49
|
+
emit_inline("\e[m")
|
|
50
|
+
elsif !before.empty? && before.size > (before & after).size + 1
|
|
51
|
+
codes = after.map {|attr| ANSI_STYLE_CODES_ON[attr] }.compact
|
|
52
|
+
emit_inline("\e[#{[0, *codes].join(';')}m")
|
|
53
|
+
else
|
|
54
|
+
off_codes = (before - after).map {|attr| ANSI_STYLE_CODES_OFF[attr] }.compact
|
|
55
|
+
on_codes = (after - before).map {|attr| ANSI_STYLE_CODES_ON[attr] }.compact
|
|
56
|
+
emit_inline("\e[#{(off_codes + on_codes).join(';')}m")
|
|
57
|
+
end
|
|
58
|
+
@applied_attributes = attributes
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def add_text(text)
|
|
62
|
+
attrs = @attributes.keys
|
|
63
|
+
if @applied_attributes != attrs
|
|
64
|
+
apply_attributes(attrs)
|
|
65
|
+
end
|
|
66
|
+
emit_inline(text)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def handle_inline(text)
|
|
70
|
+
@applied_attributes = []
|
|
71
|
+
res = super
|
|
72
|
+
res << "\e[m" unless @applied_attributes.empty?
|
|
73
|
+
@applied_attributes = []
|
|
74
|
+
res
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
##
|
|
78
|
+
# Overrides indent width to ensure output lines up correctly.
|
|
79
|
+
|
|
80
|
+
def accept_list_item_end(list_item)
|
|
81
|
+
width = case @list_type.last
|
|
82
|
+
when :BULLET
|
|
83
|
+
2
|
|
84
|
+
when :NOTE, :LABEL
|
|
85
|
+
if @prefix
|
|
86
|
+
@res << @prefix.strip
|
|
87
|
+
@prefix = nil
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
@res << "\n" unless res.length == 1
|
|
91
|
+
2
|
|
92
|
+
else
|
|
93
|
+
bullet = @list_index.last.to_s
|
|
94
|
+
@list_index[-1] = @list_index.last.succ
|
|
95
|
+
bullet.length + 2
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
@indent -= width
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
##
|
|
102
|
+
# Adds coloring to note and label list items
|
|
103
|
+
|
|
104
|
+
def accept_list_item_start(list_item)
|
|
105
|
+
bullet = case @list_type.last
|
|
106
|
+
when :BULLET
|
|
107
|
+
'*'
|
|
108
|
+
when :NOTE, :LABEL
|
|
109
|
+
labels = Array(list_item.label).map do |label|
|
|
110
|
+
attributes(label).strip
|
|
111
|
+
end.join "\n"
|
|
112
|
+
|
|
113
|
+
labels << ":\n" unless labels.empty?
|
|
114
|
+
|
|
115
|
+
labels
|
|
116
|
+
else
|
|
117
|
+
@list_index.last.to_s + '.'
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
case @list_type.last
|
|
121
|
+
when :NOTE, :LABEL
|
|
122
|
+
@indent += 2
|
|
123
|
+
@prefix = bullet + (' ' * @indent)
|
|
124
|
+
else
|
|
125
|
+
@prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1)
|
|
126
|
+
|
|
127
|
+
width = bullet.gsub(/\e\[[\d;]*m/, '').length + 1
|
|
128
|
+
|
|
129
|
+
@indent += width
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def calculate_text_width(text)
|
|
134
|
+
text.gsub(/\e\[[\d;]*m/, '').size
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
##
|
|
138
|
+
# Starts accepting with a reset screen
|
|
139
|
+
|
|
140
|
+
def start_accepting
|
|
141
|
+
super
|
|
142
|
+
|
|
143
|
+
@res = ["\e[0m"]
|
|
144
|
+
end
|
|
4
145
|
|
|
5
|
-
class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
# Creates a new ToAnsi visitor that is ready to output vibrant ANSI color!
|
|
9
|
-
|
|
10
|
-
def initialize(markup = nil)
|
|
11
|
-
super
|
|
12
|
-
|
|
13
|
-
@headings.clear
|
|
14
|
-
@headings[1] = ["\e[1;32m", "\e[m"] # bold
|
|
15
|
-
@headings[2] = ["\e[4;32m", "\e[m"] # underline
|
|
16
|
-
@headings[3] = ["\e[32m", "\e[m"] # just green
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
##
|
|
20
|
-
# Maps attributes to ANSI sequences
|
|
21
|
-
|
|
22
|
-
def init_tags
|
|
23
|
-
add_tag :BOLD, "\e[1m", "\e[m"
|
|
24
|
-
add_tag :TT, "\e[7m", "\e[m"
|
|
25
|
-
add_tag :EM, "\e[4m", "\e[m"
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
##
|
|
29
|
-
# Overrides indent width to ensure output lines up correctly.
|
|
30
|
-
|
|
31
|
-
def accept_list_item_end(list_item)
|
|
32
|
-
width = case @list_type.last
|
|
33
|
-
when :BULLET then
|
|
34
|
-
2
|
|
35
|
-
when :NOTE, :LABEL then
|
|
36
|
-
if @prefix then
|
|
37
|
-
@res << @prefix.strip
|
|
38
|
-
@prefix = nil
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
@res << "\n" unless res.length == 1
|
|
42
|
-
2
|
|
43
|
-
else
|
|
44
|
-
bullet = @list_index.last.to_s
|
|
45
|
-
@list_index[-1] = @list_index.last.succ
|
|
46
|
-
bullet.length + 2
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
@indent -= width
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
##
|
|
53
|
-
# Adds coloring to note and label list items
|
|
54
|
-
|
|
55
|
-
def accept_list_item_start(list_item)
|
|
56
|
-
bullet = case @list_type.last
|
|
57
|
-
when :BULLET then
|
|
58
|
-
'*'
|
|
59
|
-
when :NOTE, :LABEL then
|
|
60
|
-
labels = Array(list_item.label).map do |label|
|
|
61
|
-
attributes(label).strip
|
|
62
|
-
end.join "\n"
|
|
63
|
-
|
|
64
|
-
labels << ":\n" unless labels.empty?
|
|
65
|
-
|
|
66
|
-
labels
|
|
67
|
-
else
|
|
68
|
-
@list_index.last.to_s + '.'
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
case @list_type.last
|
|
72
|
-
when :NOTE, :LABEL then
|
|
73
|
-
@indent += 2
|
|
74
|
-
@prefix = bullet + (' ' * @indent)
|
|
75
|
-
else
|
|
76
|
-
@prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1)
|
|
77
|
-
|
|
78
|
-
width = bullet.gsub(/\e\[[\d;]*m/, '').length + 1
|
|
79
|
-
|
|
80
|
-
@indent += width
|
|
81
146
|
end
|
|
82
147
|
end
|
|
83
|
-
|
|
84
|
-
def calculate_text_width(text)
|
|
85
|
-
text.gsub(/\e\[[\d;]*m/, '').size
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
##
|
|
89
|
-
# Starts accepting with a reset screen
|
|
90
|
-
|
|
91
|
-
def start_accepting
|
|
92
|
-
super
|
|
93
|
-
|
|
94
|
-
@res = ["\e[0m"]
|
|
95
|
-
end
|
|
96
|
-
|
|
97
148
|
end
|
data/lib/rdoc/markup/to_bs.rb
CHANGED
|
@@ -1,106 +1,90 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
2
|
+
module RDoc
|
|
3
|
+
class Markup
|
|
4
|
+
##
|
|
5
|
+
# Outputs RDoc markup with hot backspace action! You will probably need a
|
|
6
|
+
# pager to use this output format.
|
|
7
|
+
#
|
|
8
|
+
# This formatter won't work on 1.8.6 because it lacks String#chars.
|
|
9
|
+
|
|
10
|
+
class ToBs < Markup::ToRdoc
|
|
11
|
+
|
|
12
|
+
##
|
|
13
|
+
# Returns a new ToBs that is ready for hot backspace action!
|
|
14
|
+
|
|
15
|
+
def initialize
|
|
16
|
+
super
|
|
17
|
+
|
|
18
|
+
@in_b = false
|
|
19
|
+
@in_em = false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def handle_inline(text)
|
|
23
|
+
initial_style = []
|
|
24
|
+
initial_style << :BOLD if @in_b
|
|
25
|
+
initial_style << :EM if @in_em
|
|
26
|
+
super(text, initial_style)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def add_text(text)
|
|
30
|
+
attrs = @attributes.keys
|
|
31
|
+
if attrs.include? :BOLD
|
|
32
|
+
styled = +''
|
|
33
|
+
text.chars.each do |c|
|
|
34
|
+
styled << "#{c}\b#{c}"
|
|
35
|
+
end
|
|
36
|
+
text = styled
|
|
37
|
+
elsif attrs.include? :EM
|
|
38
|
+
styled = +''
|
|
39
|
+
text.chars.each do |c|
|
|
40
|
+
styled << "_\b#{c}"
|
|
41
|
+
end
|
|
42
|
+
text = styled
|
|
43
|
+
end
|
|
44
|
+
emit_inline(text)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
##
|
|
48
|
+
# Makes heading text bold.
|
|
49
|
+
|
|
50
|
+
def accept_heading(heading)
|
|
51
|
+
use_prefix or @res << ' ' * @indent
|
|
52
|
+
@res << @headings[heading.level][0]
|
|
53
|
+
@in_b = true
|
|
54
|
+
@res << attributes(heading.text)
|
|
55
|
+
@in_b = false
|
|
56
|
+
@res << @headings[heading.level][1]
|
|
57
|
+
@res << "\n"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
##
|
|
61
|
+
# Prepares the visitor for consuming +list_item+
|
|
62
|
+
|
|
63
|
+
def accept_list_item_start(list_item)
|
|
64
|
+
type = @list_type.last
|
|
65
|
+
|
|
66
|
+
case type
|
|
67
|
+
when :NOTE, :LABEL
|
|
68
|
+
bullets = Array(list_item.label).map do |label|
|
|
69
|
+
attributes(label).strip
|
|
70
|
+
end.join "\n"
|
|
71
|
+
|
|
72
|
+
bullets << ":\n" unless bullets.empty?
|
|
73
|
+
|
|
74
|
+
@prefix = ' ' * @indent
|
|
75
|
+
@indent += 2
|
|
76
|
+
@prefix << bullets + (' ' * @indent)
|
|
77
|
+
else
|
|
78
|
+
bullet = type == :BULLET ? '*' : @list_index.last.to_s + '.'
|
|
79
|
+
@prefix = (' ' * @indent) + bullet.ljust(bullet.length + 1)
|
|
80
|
+
width = bullet.length + 1
|
|
81
|
+
@indent += width
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def calculate_text_width(text)
|
|
86
|
+
text.gsub(/_\x08/, '').gsub(/\x08./, '').size
|
|
87
|
+
end
|
|
81
88
|
end
|
|
82
|
-
''
|
|
83
89
|
end
|
|
84
|
-
|
|
85
|
-
##
|
|
86
|
-
# Calls convert_string on the result of convert_regexp_handling
|
|
87
|
-
|
|
88
|
-
def convert_regexp_handling(target)
|
|
89
|
-
convert_string super
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
##
|
|
93
|
-
# Adds bold or underline mixed with backspaces
|
|
94
|
-
|
|
95
|
-
def convert_string(string)
|
|
96
|
-
return string unless @in_b or @in_em
|
|
97
|
-
chars = if @in_b then
|
|
98
|
-
string.chars.map do |char| "#{char}\b#{char}" end
|
|
99
|
-
elsif @in_em then
|
|
100
|
-
string.chars.map do |char| "_\b#{char}" end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
chars.join
|
|
104
|
-
end
|
|
105
|
-
|
|
106
90
|
end
|