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