rdoc 6.3.4.1 → 8.0.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 (205) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +195 -0
  3. data/History.rdoc +65 -63
  4. data/LEGAL.rdoc +7 -1
  5. data/LICENSE.rdoc +6 -0
  6. data/README.md +236 -0
  7. data/RI.md +842 -0
  8. data/TODO.rdoc +8 -7
  9. data/doc/markup_reference/markdown.md +659 -0
  10. data/doc/markup_reference/rdoc.rdoc +1169 -0
  11. data/exe/rdoc +0 -1
  12. data/lib/rdoc/{alias.rb → code_object/alias.rb} +4 -18
  13. data/lib/rdoc/{any_method.rb → code_object/any_method.rb} +50 -24
  14. data/lib/rdoc/{attr.rb → code_object/attr.rb} +16 -14
  15. data/lib/rdoc/{class_module.rb → code_object/class_module.rb} +225 -58
  16. data/lib/rdoc/{constant.rb → code_object/constant.rb} +44 -10
  17. data/lib/rdoc/code_object/context/section.rb +182 -0
  18. data/lib/rdoc/{context.rb → code_object/context.rb} +78 -106
  19. data/lib/rdoc/{extend.rb → code_object/extend.rb} +0 -1
  20. data/lib/rdoc/{include.rb → code_object/include.rb} +0 -1
  21. data/lib/rdoc/{method_attr.rb → code_object/method_attr.rb} +46 -48
  22. data/lib/rdoc/{mixin.rb → code_object/mixin.rb} +6 -4
  23. data/lib/rdoc/{normal_class.rb → code_object/normal_class.rb} +2 -3
  24. data/lib/rdoc/{normal_module.rb → code_object/normal_module.rb} +2 -3
  25. data/lib/rdoc/{require.rb → code_object/require.rb} +1 -2
  26. data/lib/rdoc/{single_class.rb → code_object/single_class.rb} +5 -1
  27. data/lib/rdoc/{top_level.rb → code_object/top_level.rb} +60 -63
  28. data/lib/rdoc/code_object.rb +11 -39
  29. data/lib/rdoc/code_objects.rb +1 -2
  30. data/lib/rdoc/comment.rb +202 -99
  31. data/lib/rdoc/cross_reference.rb +75 -62
  32. data/lib/rdoc/encoding.rb +8 -24
  33. data/lib/rdoc/erb_partial.rb +1 -2
  34. data/lib/rdoc/erbio.rb +3 -8
  35. data/lib/rdoc/generator/aliki.rb +200 -0
  36. data/lib/rdoc/generator/darkfish.rb +156 -122
  37. data/lib/rdoc/generator/json_index.rb +8 -24
  38. data/lib/rdoc/generator/markup.rb +70 -34
  39. data/lib/rdoc/generator/pot/message_extractor.rb +7 -7
  40. data/lib/rdoc/generator/pot/po.rb +1 -1
  41. data/lib/rdoc/generator/pot/po_entry.rb +8 -8
  42. data/lib/rdoc/generator/pot.rb +1 -5
  43. data/lib/rdoc/generator/ri.rb +1 -2
  44. data/lib/rdoc/generator/template/aliki/DESIGN.md +536 -0
  45. data/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +8 -0
  46. data/lib/rdoc/generator/template/aliki/_footer.rhtml +23 -0
  47. data/lib/rdoc/generator/template/aliki/_head.rhtml +163 -0
  48. data/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
  49. data/lib/rdoc/generator/template/aliki/_icons.rhtml +208 -0
  50. data/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +16 -0
  51. data/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +15 -0
  52. data/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +27 -0
  53. data/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +27 -0
  54. data/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
  55. data/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +41 -0
  56. data/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +67 -0
  57. data/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
  58. data/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +21 -0
  59. data/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
  60. data/lib/rdoc/generator/template/aliki/class.rhtml +230 -0
  61. data/lib/rdoc/generator/template/aliki/css/rdoc.css +2181 -0
  62. data/lib/rdoc/generator/template/aliki/index.rhtml +22 -0
  63. data/lib/rdoc/generator/template/aliki/js/aliki.js +513 -0
  64. data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  65. data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +299 -0
  66. data/lib/rdoc/generator/template/aliki/js/search_controller.js +129 -0
  67. data/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  68. data/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  69. data/lib/rdoc/generator/template/aliki/js/theme-toggle.js +112 -0
  70. data/lib/rdoc/generator/template/aliki/page.rhtml +18 -0
  71. data/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +14 -0
  72. data/lib/rdoc/generator/template/aliki/servlet_root.rhtml +65 -0
  73. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +3 -3
  74. data/lib/rdoc/generator/template/darkfish/_head.rhtml +35 -14
  75. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +1 -5
  76. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +11 -9
  77. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +11 -9
  78. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +7 -6
  79. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +20 -11
  80. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +25 -5
  81. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +4 -9
  82. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +2 -1
  83. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
  84. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +28 -7
  85. data/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
  86. data/lib/rdoc/generator/template/darkfish/class.rhtml +138 -90
  87. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +420 -358
  88. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  89. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  90. data/lib/rdoc/generator/template/darkfish/index.rhtml +14 -12
  91. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +59 -3
  92. data/lib/rdoc/generator/template/darkfish/js/search.js +15 -5
  93. data/lib/rdoc/generator/template/darkfish/page.rhtml +7 -6
  94. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +12 -9
  95. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +24 -21
  96. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +35 -21
  97. data/lib/rdoc/generator/template/json_index/js/navigation.js +8 -8
  98. data/lib/rdoc/generator/template/json_index/js/searcher.js +48 -6
  99. data/lib/rdoc/generator.rb +6 -5
  100. data/lib/rdoc/i18n/text.rb +3 -3
  101. data/lib/rdoc/i18n.rb +1 -1
  102. data/lib/rdoc/known_classes.rb +5 -4
  103. data/lib/rdoc/markdown/entities.rb +0 -1
  104. data/lib/rdoc/markdown/literals.kpeg +0 -2
  105. data/lib/rdoc/markdown/literals.rb +0 -1
  106. data/lib/rdoc/markdown.kpeg +140 -62
  107. data/lib/rdoc/markdown.rb +1015 -873
  108. data/lib/rdoc/markup/blank_line.rb +25 -24
  109. data/lib/rdoc/markup/block_quote.rb +1 -2
  110. data/lib/rdoc/markup/document.rb +10 -11
  111. data/lib/rdoc/markup/element.rb +21 -0
  112. data/lib/rdoc/markup/formatter.rb +134 -115
  113. data/lib/rdoc/markup/hard_break.rb +30 -28
  114. data/lib/rdoc/markup/heading.rb +163 -72
  115. data/lib/rdoc/markup/include.rb +3 -4
  116. data/lib/rdoc/markup/indented_paragraph.rb +4 -5
  117. data/lib/rdoc/markup/inline_parser.rb +312 -0
  118. data/lib/rdoc/markup/list.rb +6 -7
  119. data/lib/rdoc/markup/list_item.rb +6 -7
  120. data/lib/rdoc/markup/paragraph.rb +2 -3
  121. data/lib/rdoc/markup/parser.rb +29 -19
  122. data/lib/rdoc/markup/pre_process.rb +39 -18
  123. data/lib/rdoc/markup/raw.rb +52 -56
  124. data/lib/rdoc/markup/rule.rb +2 -3
  125. data/lib/rdoc/markup/table.rb +49 -32
  126. data/lib/rdoc/markup/to_ansi.rb +58 -8
  127. data/lib/rdoc/markup/to_bs.rb +47 -38
  128. data/lib/rdoc/markup/to_html.rb +343 -105
  129. data/lib/rdoc/markup/to_html_crossref.rb +143 -58
  130. data/lib/rdoc/markup/to_html_snippet.rb +78 -76
  131. data/lib/rdoc/markup/to_joined_paragraph.rb +3 -9
  132. data/lib/rdoc/markup/to_label.rb +34 -25
  133. data/lib/rdoc/markup/to_markdown.rb +74 -51
  134. data/lib/rdoc/markup/to_rdoc.rb +141 -82
  135. data/lib/rdoc/markup/to_table_of_contents.rb +4 -5
  136. data/lib/rdoc/markup/to_test.rb +10 -3
  137. data/lib/rdoc/markup/to_tt_only.rb +17 -31
  138. data/lib/rdoc/markup/verbatim.rb +5 -6
  139. data/lib/rdoc/markup.rb +59 -707
  140. data/lib/rdoc/options.rb +228 -101
  141. data/lib/rdoc/parser/c.rb +186 -184
  142. data/lib/rdoc/parser/changelog.rb +57 -13
  143. data/lib/rdoc/parser/markdown.rb +0 -2
  144. data/lib/rdoc/parser/rbs.rb +275 -0
  145. data/lib/rdoc/parser/rd.rb +0 -1
  146. data/lib/rdoc/parser/ruby.rb +963 -2024
  147. data/lib/rdoc/parser/ruby_colorizer.rb +253 -0
  148. data/lib/rdoc/parser/simple.rb +6 -23
  149. data/lib/rdoc/parser/text.rb +0 -1
  150. data/lib/rdoc/parser.rb +35 -14
  151. data/lib/rdoc/rbs_helper.rb +186 -0
  152. data/lib/rdoc/rd/block_parser.rb +659 -11
  153. data/lib/rdoc/rd/block_parser.ry +13 -9
  154. data/lib/rdoc/rd/inline.rb +4 -5
  155. data/lib/rdoc/rd/inline_parser.rb +646 -2
  156. data/lib/rdoc/rd.rb +4 -5
  157. data/lib/rdoc/rdoc.rb +234 -90
  158. data/lib/rdoc/ri/driver.rb +172 -172
  159. data/lib/rdoc/ri/paths.rb +3 -3
  160. data/lib/rdoc/{servlet.rb → ri/servlet.rb} +28 -27
  161. data/lib/rdoc/ri/store.rb +0 -1
  162. data/lib/rdoc/ri/task.rb +3 -3
  163. data/lib/rdoc/ri.rb +5 -5
  164. data/lib/rdoc/rubygems_hook.rb +106 -25
  165. data/lib/rdoc/server.rb +460 -0
  166. data/lib/rdoc/stats/normal.rb +1 -1
  167. data/lib/rdoc/stats/quiet.rb +1 -2
  168. data/lib/rdoc/stats/verbose.rb +3 -5
  169. data/lib/rdoc/stats.rb +158 -136
  170. data/lib/rdoc/store.rb +267 -48
  171. data/lib/rdoc/task.rb +54 -28
  172. data/lib/rdoc/text.rb +60 -120
  173. data/lib/rdoc/token_stream.rb +30 -45
  174. data/lib/rdoc/tom_doc.rb +9 -15
  175. data/lib/rdoc/version.rb +3 -1
  176. data/lib/rdoc.rb +90 -52
  177. data/lib/rubygems_plugin.rb +14 -0
  178. data/man/ri.1 +2 -0
  179. data/rdoc-logo.svg +43 -0
  180. data/rdoc.gemspec +25 -200
  181. metadata +120 -53
  182. data/CONTRIBUTING.rdoc +0 -220
  183. data/ExampleMarkdown.md +0 -37
  184. data/ExampleRDoc.rdoc +0 -208
  185. data/Gemfile +0 -12
  186. data/README.rdoc +0 -129
  187. data/RI.rdoc +0 -57
  188. data/Rakefile +0 -101
  189. data/bin/console +0 -7
  190. data/bin/setup +0 -6
  191. data/lib/rdoc/anon_class.rb +0 -11
  192. data/lib/rdoc/context/section.rb +0 -232
  193. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  194. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +0 -19
  195. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +0 -9
  196. data/lib/rdoc/generator/template/json_index/.document +0 -1
  197. data/lib/rdoc/ghost_method.rb +0 -7
  198. data/lib/rdoc/markup/attr_changer.rb +0 -23
  199. data/lib/rdoc/markup/attr_span.rb +0 -36
  200. data/lib/rdoc/markup/attribute_manager.rb +0 -409
  201. data/lib/rdoc/markup/attributes.rb +0 -71
  202. data/lib/rdoc/markup/regexp_handling.rb +0 -41
  203. data/lib/rdoc/meta_method.rb +0 -7
  204. data/lib/rdoc/parser/ripper_state_lex.rb +0 -590
  205. data/lib/rdoc/parser/ruby_tools.rb +0 -167
@@ -1,28 +1,29 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # An empty line. This class is a singleton.
4
2
 
5
- class RDoc::Markup::BlankLine
6
-
7
- @instance = new
8
-
9
- ##
10
- # RDoc::Markup::BlankLine is a singleton
11
-
12
- def self.new
13
- @instance
14
- end
15
-
16
- ##
17
- # Calls #accept_blank_line on +visitor+
18
-
19
- def accept visitor
20
- visitor.accept_blank_line self
21
- end
22
-
23
- def pretty_print q # :nodoc:
24
- q.text 'blankline'
3
+ module RDoc
4
+ class Markup
5
+ # An empty line
6
+ class BlankLine < Element
7
+ @instance = new
8
+
9
+ # RDoc::Markup::BlankLine is a singleton
10
+ #: () -> BlankLine
11
+ def self.new
12
+ @instance
13
+ end
14
+
15
+ # Calls #accept_blank_line on +visitor+
16
+ # @override
17
+ #: (untyped) -> void
18
+ def accept(visitor)
19
+ visitor.accept_blank_line(self)
20
+ end
21
+
22
+ # @override
23
+ #: (PP) -> void
24
+ def pretty_print(q) # :nodoc:
25
+ q.text("blankline")
26
+ end
27
+ end
25
28
  end
26
-
27
29
  end
28
-
@@ -7,9 +7,8 @@ class RDoc::Markup::BlockQuote < RDoc::Markup::Raw
7
7
  ##
8
8
  # Calls #accept_block_quote on +visitor+
9
9
 
10
- def accept visitor
10
+ def accept(visitor)
11
11
  visitor.accept_block_quote self
12
12
  end
13
13
 
14
14
  end
15
-
@@ -26,7 +26,7 @@ class RDoc::Markup::Document
26
26
  ##
27
27
  # Creates a new Document with +parts+
28
28
 
29
- def initialize *parts
29
+ def initialize(*parts)
30
30
  @parts = []
31
31
  @parts.concat parts
32
32
 
@@ -37,7 +37,7 @@ class RDoc::Markup::Document
37
37
  ##
38
38
  # Appends +part+ to the document
39
39
 
40
- def << part
40
+ def <<(part)
41
41
  case part
42
42
  when RDoc::Markup::Document then
43
43
  unless part.empty? then
@@ -53,7 +53,7 @@ class RDoc::Markup::Document
53
53
  end
54
54
  end
55
55
 
56
- def == other # :nodoc:
56
+ def ==(other) # :nodoc:
57
57
  self.class == other.class and
58
58
  @file == other.file and
59
59
  @parts == other.parts
@@ -62,7 +62,7 @@ class RDoc::Markup::Document
62
62
  ##
63
63
  # Runs this document and all its #items through +visitor+
64
64
 
65
- def accept visitor
65
+ def accept(visitor)
66
66
  visitor.start_accepting
67
67
 
68
68
  visitor.accept_document self
@@ -73,14 +73,14 @@ class RDoc::Markup::Document
73
73
  ##
74
74
  # Concatenates the given +parts+ onto the document
75
75
 
76
- def concat parts
76
+ def concat(parts)
77
77
  self.parts.concat parts
78
78
  end
79
79
 
80
80
  ##
81
81
  # Enumerator for the parts of this document
82
82
 
83
- def each &block
83
+ def each(&block)
84
84
  @parts.each(&block)
85
85
  end
86
86
 
@@ -94,7 +94,7 @@ class RDoc::Markup::Document
94
94
  ##
95
95
  # The file this Document was created from.
96
96
 
97
- def file= location
97
+ def file=(location)
98
98
  @file = case location
99
99
  when RDoc::TopLevel then
100
100
  location.relative_name
@@ -111,7 +111,7 @@ class RDoc::Markup::Document
111
111
  #
112
112
  # The information in +other+ is preferred over the receiver
113
113
 
114
- def merge other
114
+ def merge(other)
115
115
  if empty? then
116
116
  @parts = other.parts
117
117
  return self
@@ -135,7 +135,7 @@ class RDoc::Markup::Document
135
135
  RDoc::Markup::Document === @parts.first
136
136
  end
137
137
 
138
- def pretty_print q # :nodoc:
138
+ def pretty_print(q) # :nodoc:
139
139
  start = @file ? "[doc (#{@file}): " : '[doc: '
140
140
 
141
141
  q.group 2, start, ']' do
@@ -148,7 +148,7 @@ class RDoc::Markup::Document
148
148
  ##
149
149
  # Appends +parts+ to the document
150
150
 
151
- def push *parts
151
+ def push(*parts)
152
152
  self.parts.concat parts
153
153
  end
154
154
 
@@ -162,4 +162,3 @@ class RDoc::Markup::Document
162
162
  end
163
163
 
164
164
  end
165
-
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RDoc
4
+ class Markup
5
+ # Base class defining the interface for all markup elements found in documentation
6
+ # @abstract
7
+ class Element
8
+ # @abstract
9
+ #: (untyped) -> void
10
+ def accept(visitor)
11
+ raise NotImplementedError, "#{self.class} must implement the accept method"
12
+ end
13
+
14
+ # @abstract
15
+ #: (PP) -> void
16
+ def pretty_print(q)
17
+ raise NotImplementedError, "#{self.class} must implement the pretty_print method"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -10,18 +10,14 @@
10
10
  # RDoc::Markup::FormatterTestCase. If you're writing a text-output formatter
11
11
  # use RDoc::Markup::TextFormatterTestCase which provides extra test cases.
12
12
 
13
- class RDoc::Markup::Formatter
14
-
15
- ##
16
- # Tag for inline markup containing a +bit+ for the bitmask and the +on+ and
17
- # +off+ triggers.
13
+ require 'rdoc/markup/inline_parser'
18
14
 
19
- InlineTag = Struct.new(:bit, :on, :off)
15
+ class RDoc::Markup::Formatter
20
16
 
21
17
  ##
22
18
  # Converts a target url to one that is relative to a given path
23
19
 
24
- def self.gen_relative_url path, target
20
+ def self.gen_relative_url(path, target)
25
21
  from = File.dirname path
26
22
  to, to_file = File.split target
27
23
 
@@ -45,28 +41,16 @@ class RDoc::Markup::Formatter
45
41
  ##
46
42
  # Creates a new Formatter
47
43
 
48
- def initialize options, markup = nil
49
- @options = options
50
-
51
- @markup = markup || RDoc::Markup.new
52
- @am = @markup.attribute_manager
53
- @am.add_regexp_handling(/<br>/, :HARD_BREAK)
44
+ def initialize
45
+ @markup = RDoc::Markup.new
54
46
 
55
- @attributes = @am.attributes
56
-
57
- @attr_tags = []
58
-
59
- @in_tt = 0
60
- @tt_bit = @attributes.bitmap_for :TT
61
-
62
- @hard_break = ''
63
47
  @from_path = '.'
64
48
  end
65
49
 
66
50
  ##
67
51
  # Adds +document+ to the output
68
52
 
69
- def accept_document document
53
+ def accept_document(document)
70
54
  document.parts.each do |item|
71
55
  case item
72
56
  when RDoc::Markup::Document then # HACK
@@ -85,150 +69,186 @@ class RDoc::Markup::Formatter
85
69
  end
86
70
 
87
71
  ##
88
- # Adds a regexp handling for links of the form {<text>}[<url>] and
89
- # <word>[<url>]
90
-
91
- def add_regexp_handling_TIDYLINK
92
- @markup.add_regexp_handling(/(?:
93
- \{.*?\} | # multi-word label
94
- \b[^\s{}]+? # single-word label
95
- )
72
+ # Allows +tag+ to be decorated with additional information.
96
73
 
97
- \[\S+?\] # link target
98
- /x, :TIDYLINK)
74
+ def annotate(tag)
75
+ tag
99
76
  end
100
77
 
101
78
  ##
102
- # Add a new set of tags for an attribute. We allow separate start and end
103
- # tags for flexibility
79
+ # Marks up +content+
104
80
 
105
- def add_tag(name, start, stop)
106
- attr = @attributes.bitmap_for name
107
- @attr_tags << InlineTag.new(attr, start, stop)
81
+ def convert(content)
82
+ @markup.convert content, self
108
83
  end
109
84
 
110
- ##
111
- # Allows +tag+ to be decorated with additional information.
85
+ # Applies regexp handling to +text+ and returns an array of [text, converted?] pairs.
112
86
 
113
- def annotate(tag)
114
- tag
87
+ def apply_regexp_handling(text)
88
+ matched = []
89
+ @markup.regexp_handlings.each_with_index do |(pattern, name), priority|
90
+ text.scan(pattern) do
91
+ m = Regexp.last_match
92
+ idx = m[1] ? 1 : 0
93
+ matched << [m.begin(idx), m.end(idx), m[idx], name, priority]
94
+ end
95
+ end
96
+ # If the start positions are the same, prefer the earlier-registered one
97
+ # (lower numeric priority from each_with_index).
98
+ matched.sort_by! {|beg_pos, _, _, _, priority| [beg_pos, priority] }
99
+
100
+ pos = 0
101
+ output = []
102
+ matched.each do |beg_pos, end_pos, s, name|
103
+ next if beg_pos < pos
104
+
105
+ output << [text[pos...beg_pos], false] if beg_pos != pos
106
+ handled = public_send(:"handle_regexp_#{name}", s)
107
+ output << [handled, true]
108
+ pos = end_pos
109
+ end
110
+
111
+ output << [text[pos..], false] if pos < text.size
112
+ output
115
113
  end
116
114
 
117
- ##
118
- # Marks up +content+
115
+ # Called when processing plain text while traversing inline nodes from handle_inline.
116
+ # +text+ may need proper escaping.
119
117
 
120
- def convert content
121
- @markup.convert content, self
118
+ def handle_PLAIN_TEXT(text)
122
119
  end
123
120
 
124
- ##
125
- # Converts flow items +flow+
121
+ # Called when processing regexp-handling-processed text while traversing inline nodes from handle_inline.
122
+ # +text+ may contain markup tags.
123
+
124
+ def handle_REGEXP_HANDLING_TEXT(text)
125
+ end
126
126
 
127
- def convert_flow(flow)
128
- res = []
127
+ # Called when processing text node while traversing inline nodes from handle_inline.
128
+ # Apply regexp handling and dispatch to the appropriate handler: handle_REGEXP_HANDLING_TEXT or handle_PLAIN_TEXT.
129
129
 
130
- flow.each do |item|
131
- case item
132
- when String then
133
- res << convert_string(item)
134
- when RDoc::Markup::AttrChanger then
135
- off_tags res, item
136
- on_tags res, item
137
- when RDoc::Markup::RegexpHandling then
138
- res << convert_regexp_handling(item)
130
+ def handle_TEXT(text)
131
+ apply_regexp_handling(text).each do |part, converted|
132
+ if converted
133
+ handle_REGEXP_HANDLING_TEXT(part)
139
134
  else
140
- raise "Unknown flow element: #{item.inspect}"
135
+ handle_PLAIN_TEXT(part)
141
136
  end
142
137
  end
138
+ end
139
+
140
+ # Called when processing a hard break while traversing inline nodes from handle_inline.
143
141
 
144
- res.join
142
+ def handle_HARD_BREAK
145
143
  end
146
144
 
147
- ##
148
- # Converts added regexp handlings. See RDoc::Markup#add_regexp_handling
145
+ # Called when processing bold nodes while traversing inline nodes from handle_inline.
146
+ # Traverse the children nodes and dispatch to the appropriate handlers.
149
147
 
150
- def convert_regexp_handling target
151
- return target.text if in_tt?
148
+ def handle_BOLD(nodes)
149
+ traverse_inline_nodes(nodes)
150
+ end
152
151
 
153
- handled = false
152
+ # Called when processing emphasis nodes while traversing inline nodes from handle_inline.
153
+ # Traverse the children nodes and dispatch to the appropriate handlers.
154
154
 
155
- @attributes.each_name_of target.type do |name|
156
- method_name = "handle_regexp_#{name}"
155
+ def handle_EM(nodes)
156
+ traverse_inline_nodes(nodes)
157
+ end
157
158
 
158
- if respond_to? method_name then
159
- target.text = public_send method_name, target
160
- handled = true
161
- end
162
- end
159
+ # Called when processing bold word nodes while traversing inline nodes from handle_inline.
160
+ # +word+ may need proper escaping.
163
161
 
164
- unless handled then
165
- target_name = @attributes.as_string target.type
162
+ def handle_BOLD_WORD(word)
163
+ handle_PLAIN_TEXT(word)
164
+ end
166
165
 
167
- raise RDoc::Error, "Unhandled regexp handling #{target_name}: #{target}"
168
- end
166
+ # Called when processing emphasis word nodes while traversing inline nodes from handle_inline.
167
+ # +word+ may need proper escaping.
169
168
 
170
- target.text
169
+ def handle_EM_WORD(word)
170
+ handle_PLAIN_TEXT(word)
171
171
  end
172
172
 
173
- ##
174
- # Converts a string to be fancier if desired
173
+ # Called when processing tt nodes while traversing inline nodes from handle_inline.
174
+ # +code+ may need proper escaping.
175
175
 
176
- def convert_string string
177
- string
176
+ def handle_TT(code)
177
+ handle_PLAIN_TEXT(code)
178
178
  end
179
179
 
180
- ##
181
- # Use ignore in your subclass to ignore the content of a node.
182
- #
183
- # ##
184
- # # We don't support raw nodes in ToNoRaw
185
- #
186
- # alias accept_raw ignore
180
+ # Called when processing strike nodes while traversing inline nodes from handle_inline.
181
+ # Traverse the children nodes and dispatch to the appropriate handlers.
187
182
 
188
- def ignore *node
183
+ def handle_STRIKE(nodes)
184
+ traverse_inline_nodes(nodes)
189
185
  end
190
186
 
191
- ##
192
- # Are we currently inside tt tags?
187
+ # Called when processing tidylink nodes while traversing inline nodes from handle_inline.
188
+ # +label_part+ is an array of strings or nodes representing the link label.
189
+ # +url+ is the link URL.
190
+ # Traverse the label_part nodes and dispatch to the appropriate handlers.
193
191
 
194
- def in_tt?
195
- @in_tt > 0
192
+ def handle_TIDYLINK(label_part, url)
193
+ traverse_inline_nodes(label_part)
196
194
  end
197
195
 
198
- ##
199
- # Turns on tags for +item+ on +res+
196
+ # Parses inline +text+, traverse the resulting nodes, and calls the appropriate handler methods.
200
197
 
201
- def on_tags res, item
202
- attr_mask = item.turn_on
203
- return if attr_mask.zero?
198
+ def handle_inline(text)
199
+ nodes = RDoc::Markup::InlineParser.new(text).parse
200
+ traverse_inline_nodes(nodes)
201
+ end
204
202
 
205
- @attr_tags.each do |tag|
206
- if attr_mask & tag.bit != 0 then
207
- res << annotate(tag.on)
208
- @in_tt += 1 if tt? tag
203
+ # Traverses +nodes+ and calls the appropriate handler methods
204
+ # Nodes formats are described in RDoc::Markup::InlineParser#parse
205
+
206
+ def traverse_inline_nodes(nodes)
207
+ nodes.each do |node|
208
+ next handle_TEXT(node) if String === node
209
+ case node[:type]
210
+ when :TIDYLINK
211
+ handle_TIDYLINK(node[:children], node[:url])
212
+ when :HARD_BREAK
213
+ handle_HARD_BREAK
214
+ when :BOLD
215
+ handle_BOLD(node[:children])
216
+ when :BOLD_WORD
217
+ handle_BOLD_WORD(node[:children][0] || '')
218
+ when :EM
219
+ handle_EM(node[:children])
220
+ when :EM_WORD
221
+ handle_EM_WORD(node[:children][0] || '')
222
+ when :TT
223
+ handle_TT(node[:children][0] || '')
224
+ when :STRIKE
225
+ handle_STRIKE(node[:children])
209
226
  end
210
227
  end
211
228
  end
212
229
 
213
230
  ##
214
- # Turns off tags for +item+ on +res+
231
+ # Converts a string to be fancier if desired
215
232
 
216
- def off_tags res, item
217
- attr_mask = item.turn_off
218
- return if attr_mask.zero?
233
+ def convert_string(string)
234
+ string
235
+ end
219
236
 
220
- @attr_tags.reverse_each do |tag|
221
- if attr_mask & tag.bit != 0 then
222
- @in_tt -= 1 if tt? tag
223
- res << annotate(tag.off)
224
- end
225
- end
237
+ ##
238
+ # Use ignore in your subclass to ignore the content of a node.
239
+ #
240
+ # ##
241
+ # # We don't support raw nodes in ToNoRaw
242
+ #
243
+ # alias accept_raw ignore
244
+
245
+ def ignore(*node)
226
246
  end
227
247
 
228
248
  ##
229
249
  # Extracts and a scheme, url and an anchor id from +url+ and returns them.
230
250
 
231
- def parse_url url
251
+ def parse_url(url)
232
252
  case url
233
253
  when /^rdoc-label:([^:]*)(?::(.*))?/ then
234
254
  scheme = 'link'
@@ -258,9 +278,8 @@ class RDoc::Markup::Formatter
258
278
  ##
259
279
  # Is +tag+ a tt tag?
260
280
 
261
- def tt? tag
281
+ def tt?(tag)
262
282
  tag.bit == @tt_bit
263
283
  end
264
284
 
265
285
  end
266
-
@@ -1,32 +1,34 @@
1
1
  # frozen_string_literal: true
2
- ##
3
- # A hard-break in the middle of a paragraph.
4
2
 
5
- class RDoc::Markup::HardBreak
6
-
7
- @instance = new
8
-
9
- ##
10
- # RDoc::Markup::HardBreak is a singleton
11
-
12
- def self.new
13
- @instance
14
- end
15
-
16
- ##
17
- # Calls #accept_hard_break on +visitor+
18
-
19
- def accept visitor
20
- visitor.accept_hard_break self
3
+ module RDoc
4
+ class Markup
5
+ # A hard-break in the middle of a paragraph.
6
+ class HardBreak < Element
7
+ @instance = new
8
+
9
+ # RDoc::Markup::HardBreak is a singleton
10
+ #: () -> HardBreak
11
+ def self.new
12
+ @instance
13
+ end
14
+
15
+ # Calls #accept_hard_break on +visitor+
16
+ # @override
17
+ #: (untyped) -> void
18
+ def accept(visitor)
19
+ visitor.accept_hard_break(self)
20
+ end
21
+
22
+ #: (top) -> bool
23
+ def ==(other) # :nodoc:
24
+ self.class === other
25
+ end
26
+
27
+ # @override
28
+ #: (PP) -> void
29
+ def pretty_print(q) # :nodoc:
30
+ q.text("[break]")
31
+ end
32
+ end
21
33
  end
22
-
23
- def == other # :nodoc:
24
- self.class === other
25
- end
26
-
27
- def pretty_print q # :nodoc:
28
- q.text "[break]"
29
- end
30
-
31
34
  end
32
-