gitlab-rdoc 6.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.rdoc +220 -0
  3. data/CVE-2013-0256.rdoc +49 -0
  4. data/ExampleMarkdown.md +37 -0
  5. data/ExampleRDoc.rdoc +208 -0
  6. data/Gemfile +12 -0
  7. data/History.rdoc +1666 -0
  8. data/LEGAL.rdoc +50 -0
  9. data/LICENSE.rdoc +57 -0
  10. data/README.rdoc +133 -0
  11. data/RI.rdoc +57 -0
  12. data/Rakefile +101 -0
  13. data/TODO.rdoc +59 -0
  14. data/bin/console +7 -0
  15. data/bin/setup +6 -0
  16. data/exe/rdoc +44 -0
  17. data/exe/ri +12 -0
  18. data/lib/rdoc/alias.rb +112 -0
  19. data/lib/rdoc/anon_class.rb +11 -0
  20. data/lib/rdoc/any_method.rb +361 -0
  21. data/lib/rdoc/attr.rb +176 -0
  22. data/lib/rdoc/class_module.rb +802 -0
  23. data/lib/rdoc/code_object.rb +421 -0
  24. data/lib/rdoc/code_objects.rb +6 -0
  25. data/lib/rdoc/comment.rb +250 -0
  26. data/lib/rdoc/constant.rb +187 -0
  27. data/lib/rdoc/context/section.rb +232 -0
  28. data/lib/rdoc/context.rb +1266 -0
  29. data/lib/rdoc/cross_reference.rb +202 -0
  30. data/lib/rdoc/encoding.rb +136 -0
  31. data/lib/rdoc/erb_partial.rb +19 -0
  32. data/lib/rdoc/erbio.rb +42 -0
  33. data/lib/rdoc/extend.rb +10 -0
  34. data/lib/rdoc/generator/darkfish.rb +790 -0
  35. data/lib/rdoc/generator/json_index.rb +300 -0
  36. data/lib/rdoc/generator/markup.rb +160 -0
  37. data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  38. data/lib/rdoc/generator/pot/po.rb +84 -0
  39. data/lib/rdoc/generator/pot/po_entry.rb +141 -0
  40. data/lib/rdoc/generator/pot.rb +98 -0
  41. data/lib/rdoc/generator/ri.rb +31 -0
  42. data/lib/rdoc/generator/template/darkfish/.document +0 -0
  43. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  44. data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  57. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
  58. data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
  59. data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  60. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
  61. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  64. data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  65. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  66. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  67. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  68. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  69. data/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  70. data/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  71. data/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  72. data/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  73. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  74. data/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  75. data/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  76. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  77. data/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  78. data/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  79. data/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  80. data/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  81. data/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  82. data/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  83. data/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  84. data/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  85. data/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  86. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  87. data/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  88. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  89. data/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  90. data/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  91. data/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  92. data/lib/rdoc/generator/template/darkfish/index.rhtml +22 -0
  93. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +84 -0
  94. data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
  95. data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
  96. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  97. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
  98. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
  99. data/lib/rdoc/generator/template/json_index/.document +1 -0
  100. data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  101. data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
  102. data/lib/rdoc/generator.rb +51 -0
  103. data/lib/rdoc/ghost_method.rb +7 -0
  104. data/lib/rdoc/i18n/locale.rb +102 -0
  105. data/lib/rdoc/i18n/text.rb +126 -0
  106. data/lib/rdoc/i18n.rb +10 -0
  107. data/lib/rdoc/include.rb +10 -0
  108. data/lib/rdoc/known_classes.rb +73 -0
  109. data/lib/rdoc/markdown/entities.rb +2132 -0
  110. data/lib/rdoc/markdown/literals.kpeg +23 -0
  111. data/lib/rdoc/markdown/literals.rb +417 -0
  112. data/lib/rdoc/markdown.kpeg +1237 -0
  113. data/lib/rdoc/markdown.rb +16685 -0
  114. data/lib/rdoc/markup/attr_changer.rb +23 -0
  115. data/lib/rdoc/markup/attr_span.rb +36 -0
  116. data/lib/rdoc/markup/attribute_manager.rb +409 -0
  117. data/lib/rdoc/markup/attributes.rb +71 -0
  118. data/lib/rdoc/markup/blank_line.rb +28 -0
  119. data/lib/rdoc/markup/block_quote.rb +15 -0
  120. data/lib/rdoc/markup/document.rb +165 -0
  121. data/lib/rdoc/markup/formatter.rb +266 -0
  122. data/lib/rdoc/markup/hard_break.rb +32 -0
  123. data/lib/rdoc/markup/heading.rb +79 -0
  124. data/lib/rdoc/markup/include.rb +43 -0
  125. data/lib/rdoc/markup/indented_paragraph.rb +48 -0
  126. data/lib/rdoc/markup/list.rb +102 -0
  127. data/lib/rdoc/markup/list_item.rb +100 -0
  128. data/lib/rdoc/markup/paragraph.rb +29 -0
  129. data/lib/rdoc/markup/parser.rb +575 -0
  130. data/lib/rdoc/markup/pre_process.rb +296 -0
  131. data/lib/rdoc/markup/raw.rb +70 -0
  132. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  133. data/lib/rdoc/markup/rule.rb +21 -0
  134. data/lib/rdoc/markup/table.rb +47 -0
  135. data/lib/rdoc/markup/to_ansi.rb +94 -0
  136. data/lib/rdoc/markup/to_bs.rb +77 -0
  137. data/lib/rdoc/markup/to_html.rb +444 -0
  138. data/lib/rdoc/markup/to_html_crossref.rb +176 -0
  139. data/lib/rdoc/markup/to_html_snippet.rb +285 -0
  140. data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
  141. data/lib/rdoc/markup/to_label.rb +75 -0
  142. data/lib/rdoc/markup/to_markdown.rb +192 -0
  143. data/lib/rdoc/markup/to_rdoc.rb +362 -0
  144. data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
  145. data/lib/rdoc/markup/to_test.rb +70 -0
  146. data/lib/rdoc/markup/to_tt_only.rb +121 -0
  147. data/lib/rdoc/markup/verbatim.rb +84 -0
  148. data/lib/rdoc/markup.rb +867 -0
  149. data/lib/rdoc/meta_method.rb +7 -0
  150. data/lib/rdoc/method_attr.rb +419 -0
  151. data/lib/rdoc/mixin.rb +121 -0
  152. data/lib/rdoc/normal_class.rb +93 -0
  153. data/lib/rdoc/normal_module.rb +74 -0
  154. data/lib/rdoc/options.rb +1285 -0
  155. data/lib/rdoc/parser/c.rb +1225 -0
  156. data/lib/rdoc/parser/changelog.rb +335 -0
  157. data/lib/rdoc/parser/markdown.rb +24 -0
  158. data/lib/rdoc/parser/rd.rb +23 -0
  159. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  160. data/lib/rdoc/parser/ruby.rb +2327 -0
  161. data/lib/rdoc/parser/ruby_tools.rb +167 -0
  162. data/lib/rdoc/parser/simple.rb +61 -0
  163. data/lib/rdoc/parser/text.rb +12 -0
  164. data/lib/rdoc/parser.rb +277 -0
  165. data/lib/rdoc/rd/block_parser.rb +1056 -0
  166. data/lib/rdoc/rd/block_parser.ry +639 -0
  167. data/lib/rdoc/rd/inline.rb +72 -0
  168. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  169. data/lib/rdoc/rd/inline_parser.ry +593 -0
  170. data/lib/rdoc/rd.rb +100 -0
  171. data/lib/rdoc/rdoc.rb +579 -0
  172. data/lib/rdoc/require.rb +52 -0
  173. data/lib/rdoc/ri/driver.rb +1572 -0
  174. data/lib/rdoc/ri/formatter.rb +6 -0
  175. data/lib/rdoc/ri/paths.rb +171 -0
  176. data/lib/rdoc/ri/store.rb +7 -0
  177. data/lib/rdoc/ri/task.rb +71 -0
  178. data/lib/rdoc/ri.rb +21 -0
  179. data/lib/rdoc/rubygems_hook.rb +246 -0
  180. data/lib/rdoc/servlet.rb +451 -0
  181. data/lib/rdoc/single_class.rb +26 -0
  182. data/lib/rdoc/stats/normal.rb +58 -0
  183. data/lib/rdoc/stats/quiet.rb +60 -0
  184. data/lib/rdoc/stats/verbose.rb +46 -0
  185. data/lib/rdoc/stats.rb +462 -0
  186. data/lib/rdoc/store.rb +979 -0
  187. data/lib/rdoc/task.rb +329 -0
  188. data/lib/rdoc/text.rb +304 -0
  189. data/lib/rdoc/token_stream.rb +119 -0
  190. data/lib/rdoc/tom_doc.rb +263 -0
  191. data/lib/rdoc/top_level.rb +289 -0
  192. data/lib/rdoc/version.rb +8 -0
  193. data/lib/rdoc.rb +201 -0
  194. data/man/ri.1 +247 -0
  195. data/rdoc.gemspec +249 -0
  196. metadata +279 -0
@@ -0,0 +1,23 @@
1
+ %% name = RDoc::Markdown::Literals
2
+
3
+ %% header {
4
+ # coding: UTF-8
5
+ # frozen_string_literal: true
6
+ # :markup: markdown
7
+
8
+ ##
9
+ #--
10
+ # This set of literals is for Ruby 1.9 regular expressions and gives full
11
+ # unicode support.
12
+ #
13
+ # Unlike peg-markdown, this set of literals recognizes Unicode alphanumeric
14
+ # characters, newlines and spaces.
15
+ }
16
+
17
+ Alphanumeric = /\p{Word}/
18
+ AlphanumericAscii = /[A-Za-z0-9]/
19
+ BOM = "\uFEFF"
20
+ Newline = /\n|\r\n?|\p{Zl}|\p{Zp}/
21
+ NonAlphanumeric = /\p{^Word}/
22
+ Spacechar = /\t|\p{Zs}/
23
+
@@ -0,0 +1,417 @@
1
+ # coding: UTF-8
2
+ # frozen_string_literal: true
3
+ # :markup: markdown
4
+
5
+ ##
6
+ #--
7
+ # This set of literals is for Ruby 1.9 regular expressions and gives full
8
+ # unicode support.
9
+ #
10
+ # Unlike peg-markdown, this set of literals recognizes Unicode alphanumeric
11
+ # characters, newlines and spaces.
12
+ class RDoc::Markdown::Literals
13
+ # :stopdoc:
14
+
15
+ # This is distinct from setup_parser so that a standalone parser
16
+ # can redefine #initialize and still have access to the proper
17
+ # parser setup code.
18
+ def initialize(str, debug=false)
19
+ setup_parser(str, debug)
20
+ end
21
+
22
+
23
+
24
+ # Prepares for parsing +str+. If you define a custom initialize you must
25
+ # call this method before #parse
26
+ def setup_parser(str, debug=false)
27
+ set_string str, 0
28
+ @memoizations = Hash.new { |h,k| h[k] = {} }
29
+ @result = nil
30
+ @failed_rule = nil
31
+ @failing_rule_offset = -1
32
+
33
+ setup_foreign_grammar
34
+ end
35
+
36
+ attr_reader :string
37
+ attr_reader :failing_rule_offset
38
+ attr_accessor :result, :pos
39
+
40
+ def current_column(target=pos)
41
+ if c = string.rindex("\n", target-1)
42
+ return target - c - 1
43
+ end
44
+
45
+ target + 1
46
+ end
47
+
48
+ def current_line(target=pos)
49
+ cur_offset = 0
50
+ cur_line = 0
51
+
52
+ string.each_line do |line|
53
+ cur_line += 1
54
+ cur_offset += line.size
55
+ return cur_line if cur_offset >= target
56
+ end
57
+
58
+ -1
59
+ end
60
+
61
+ def lines
62
+ lines = []
63
+ string.each_line { |l| lines << l }
64
+ lines
65
+ end
66
+
67
+
68
+
69
+ def get_text(start)
70
+ @string[start..@pos-1]
71
+ end
72
+
73
+ # Sets the string and current parsing position for the parser.
74
+ def set_string string, pos
75
+ @string = string
76
+ @string_size = string ? string.size : 0
77
+ @pos = pos
78
+ end
79
+
80
+ def show_pos
81
+ width = 10
82
+ if @pos < width
83
+ "#{@pos} (\"#{@string[0,@pos]}\" @ \"#{@string[@pos,width]}\")"
84
+ else
85
+ "#{@pos} (\"... #{@string[@pos - width, width]}\" @ \"#{@string[@pos,width]}\")"
86
+ end
87
+ end
88
+
89
+ def failure_info
90
+ l = current_line @failing_rule_offset
91
+ c = current_column @failing_rule_offset
92
+
93
+ if @failed_rule.kind_of? Symbol
94
+ info = self.class::Rules[@failed_rule]
95
+ "line #{l}, column #{c}: failed rule '#{info.name}' = '#{info.rendered}'"
96
+ else
97
+ "line #{l}, column #{c}: failed rule '#{@failed_rule}'"
98
+ end
99
+ end
100
+
101
+ def failure_caret
102
+ l = current_line @failing_rule_offset
103
+ c = current_column @failing_rule_offset
104
+
105
+ line = lines[l-1]
106
+ "#{line}\n#{' ' * (c - 1)}^"
107
+ end
108
+
109
+ def failure_character
110
+ l = current_line @failing_rule_offset
111
+ c = current_column @failing_rule_offset
112
+ lines[l-1][c-1, 1]
113
+ end
114
+
115
+ def failure_oneline
116
+ l = current_line @failing_rule_offset
117
+ c = current_column @failing_rule_offset
118
+
119
+ char = lines[l-1][c-1, 1]
120
+
121
+ if @failed_rule.kind_of? Symbol
122
+ info = self.class::Rules[@failed_rule]
123
+ "@#{l}:#{c} failed rule '#{info.name}', got '#{char}'"
124
+ else
125
+ "@#{l}:#{c} failed rule '#{@failed_rule}', got '#{char}'"
126
+ end
127
+ end
128
+
129
+ class ParseError < RuntimeError
130
+ end
131
+
132
+ def raise_error
133
+ raise ParseError, failure_oneline
134
+ end
135
+
136
+ def show_error(io=STDOUT)
137
+ error_pos = @failing_rule_offset
138
+ line_no = current_line(error_pos)
139
+ col_no = current_column(error_pos)
140
+
141
+ io.puts "On line #{line_no}, column #{col_no}:"
142
+
143
+ if @failed_rule.kind_of? Symbol
144
+ info = self.class::Rules[@failed_rule]
145
+ io.puts "Failed to match '#{info.rendered}' (rule '#{info.name}')"
146
+ else
147
+ io.puts "Failed to match rule '#{@failed_rule}'"
148
+ end
149
+
150
+ io.puts "Got: #{string[error_pos,1].inspect}"
151
+ line = lines[line_no-1]
152
+ io.puts "=> #{line}"
153
+ io.print(" " * (col_no + 3))
154
+ io.puts "^"
155
+ end
156
+
157
+ def set_failed_rule(name)
158
+ if @pos > @failing_rule_offset
159
+ @failed_rule = name
160
+ @failing_rule_offset = @pos
161
+ end
162
+ end
163
+
164
+ attr_reader :failed_rule
165
+
166
+ def match_string(str)
167
+ len = str.size
168
+ if @string[pos,len] == str
169
+ @pos += len
170
+ return str
171
+ end
172
+
173
+ return nil
174
+ end
175
+
176
+ def scan(reg)
177
+ if m = reg.match(@string[@pos..-1])
178
+ width = m.end(0)
179
+ @pos += width
180
+ return true
181
+ end
182
+
183
+ return nil
184
+ end
185
+
186
+ if "".respond_to? :ord
187
+ def get_byte
188
+ if @pos >= @string_size
189
+ return nil
190
+ end
191
+
192
+ s = @string[@pos].ord
193
+ @pos += 1
194
+ s
195
+ end
196
+ else
197
+ def get_byte
198
+ if @pos >= @string_size
199
+ return nil
200
+ end
201
+
202
+ s = @string[@pos]
203
+ @pos += 1
204
+ s
205
+ end
206
+ end
207
+
208
+ def parse(rule=nil)
209
+ # We invoke the rules indirectly via apply
210
+ # instead of by just calling them as methods because
211
+ # if the rules use left recursion, apply needs to
212
+ # manage that.
213
+
214
+ if !rule
215
+ apply(:_root)
216
+ else
217
+ method = rule.gsub("-","_hyphen_")
218
+ apply :"_#{method}"
219
+ end
220
+ end
221
+
222
+ class MemoEntry
223
+ def initialize(ans, pos)
224
+ @ans = ans
225
+ @pos = pos
226
+ @result = nil
227
+ @set = false
228
+ @left_rec = false
229
+ end
230
+
231
+ attr_reader :ans, :pos, :result, :set
232
+ attr_accessor :left_rec
233
+
234
+ def move!(ans, pos, result)
235
+ @ans = ans
236
+ @pos = pos
237
+ @result = result
238
+ @set = true
239
+ @left_rec = false
240
+ end
241
+ end
242
+
243
+ def external_invoke(other, rule, *args)
244
+ old_pos = @pos
245
+ old_string = @string
246
+
247
+ set_string other.string, other.pos
248
+
249
+ begin
250
+ if val = __send__(rule, *args)
251
+ other.pos = @pos
252
+ other.result = @result
253
+ else
254
+ other.set_failed_rule "#{self.class}##{rule}"
255
+ end
256
+ val
257
+ ensure
258
+ set_string old_string, old_pos
259
+ end
260
+ end
261
+
262
+ def apply_with_args(rule, *args)
263
+ memo_key = [rule, args]
264
+ if m = @memoizations[memo_key][@pos]
265
+ @pos = m.pos
266
+ if !m.set
267
+ m.left_rec = true
268
+ return nil
269
+ end
270
+
271
+ @result = m.result
272
+
273
+ return m.ans
274
+ else
275
+ m = MemoEntry.new(nil, @pos)
276
+ @memoizations[memo_key][@pos] = m
277
+ start_pos = @pos
278
+
279
+ ans = __send__ rule, *args
280
+
281
+ lr = m.left_rec
282
+
283
+ m.move! ans, @pos, @result
284
+
285
+ # Don't bother trying to grow the left recursion
286
+ # if it's failing straight away (thus there is no seed)
287
+ if ans and lr
288
+ return grow_lr(rule, args, start_pos, m)
289
+ else
290
+ return ans
291
+ end
292
+ end
293
+ end
294
+
295
+ def apply(rule)
296
+ if m = @memoizations[rule][@pos]
297
+ @pos = m.pos
298
+ if !m.set
299
+ m.left_rec = true
300
+ return nil
301
+ end
302
+
303
+ @result = m.result
304
+
305
+ return m.ans
306
+ else
307
+ m = MemoEntry.new(nil, @pos)
308
+ @memoizations[rule][@pos] = m
309
+ start_pos = @pos
310
+
311
+ ans = __send__ rule
312
+
313
+ lr = m.left_rec
314
+
315
+ m.move! ans, @pos, @result
316
+
317
+ # Don't bother trying to grow the left recursion
318
+ # if it's failing straight away (thus there is no seed)
319
+ if ans and lr
320
+ return grow_lr(rule, nil, start_pos, m)
321
+ else
322
+ return ans
323
+ end
324
+ end
325
+ end
326
+
327
+ def grow_lr(rule, args, start_pos, m)
328
+ while true
329
+ @pos = start_pos
330
+ @result = m.result
331
+
332
+ if args
333
+ ans = __send__ rule, *args
334
+ else
335
+ ans = __send__ rule
336
+ end
337
+ return nil unless ans
338
+
339
+ break if @pos <= m.pos
340
+
341
+ m.move! ans, @pos, @result
342
+ end
343
+
344
+ @result = m.result
345
+ @pos = m.pos
346
+ return m.ans
347
+ end
348
+
349
+ class RuleInfo
350
+ def initialize(name, rendered)
351
+ @name = name
352
+ @rendered = rendered
353
+ end
354
+
355
+ attr_reader :name, :rendered
356
+ end
357
+
358
+ def self.rule_info(name, rendered)
359
+ RuleInfo.new(name, rendered)
360
+ end
361
+
362
+
363
+ # :startdoc:
364
+ # :stopdoc:
365
+ def setup_foreign_grammar; end
366
+
367
+ # Alphanumeric = /\p{Word}/
368
+ def _Alphanumeric
369
+ _tmp = scan(/\A(?-mix:\p{Word})/)
370
+ set_failed_rule :_Alphanumeric unless _tmp
371
+ return _tmp
372
+ end
373
+
374
+ # AlphanumericAscii = /[A-Za-z0-9]/
375
+ def _AlphanumericAscii
376
+ _tmp = scan(/\A(?-mix:[A-Za-z0-9])/)
377
+ set_failed_rule :_AlphanumericAscii unless _tmp
378
+ return _tmp
379
+ end
380
+
381
+ # BOM = "uFEFF"
382
+ def _BOM
383
+ _tmp = match_string("uFEFF")
384
+ set_failed_rule :_BOM unless _tmp
385
+ return _tmp
386
+ end
387
+
388
+ # Newline = /\n|\r\n?|\p{Zl}|\p{Zp}/
389
+ def _Newline
390
+ _tmp = scan(/\A(?-mix:\n|\r\n?|\p{Zl}|\p{Zp})/)
391
+ set_failed_rule :_Newline unless _tmp
392
+ return _tmp
393
+ end
394
+
395
+ # NonAlphanumeric = /\p{^Word}/
396
+ def _NonAlphanumeric
397
+ _tmp = scan(/\A(?-mix:\p{^Word})/)
398
+ set_failed_rule :_NonAlphanumeric unless _tmp
399
+ return _tmp
400
+ end
401
+
402
+ # Spacechar = /\t|\p{Zs}/
403
+ def _Spacechar
404
+ _tmp = scan(/\A(?-mix:\t|\p{Zs})/)
405
+ set_failed_rule :_Spacechar unless _tmp
406
+ return _tmp
407
+ end
408
+
409
+ Rules = {}
410
+ Rules[:_Alphanumeric] = rule_info("Alphanumeric", "/\\p{Word}/")
411
+ Rules[:_AlphanumericAscii] = rule_info("AlphanumericAscii", "/[A-Za-z0-9]/")
412
+ Rules[:_BOM] = rule_info("BOM", "\"uFEFF\"")
413
+ Rules[:_Newline] = rule_info("Newline", "/\\n|\\r\\n?|\\p{Zl}|\\p{Zp}/")
414
+ Rules[:_NonAlphanumeric] = rule_info("NonAlphanumeric", "/\\p{^Word}/")
415
+ Rules[:_Spacechar] = rule_info("Spacechar", "/\\t|\\p{Zs}/")
416
+ # :startdoc:
417
+ end
@@ -0,0 +1,1237 @@
1
+ %% name = RDoc::Markdown
2
+
3
+ %% header {
4
+ # coding: UTF-8
5
+ # frozen_string_literal: true
6
+ # :markup: markdown
7
+
8
+ ##
9
+ # RDoc::Markdown as described by the [markdown syntax][syntax].
10
+ #
11
+ # To choose Markdown as your only default format see
12
+ # RDoc::Options@Saved+Options for instructions on setting up a `.doc_options`
13
+ # file to store your project default.
14
+ #
15
+ # ## Usage
16
+ #
17
+ # Here is a brief example of using this parse to read a markdown file by hand.
18
+ #
19
+ # data = File.read("README.md")
20
+ # formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil)
21
+ # html = RDoc::Markdown.parse(data).accept(formatter)
22
+ #
23
+ # # do something with html
24
+ #
25
+ # ## Extensions
26
+ #
27
+ # The following markdown extensions are supported by the parser, but not all
28
+ # are used in RDoc output by default.
29
+ #
30
+ # ### RDoc
31
+ #
32
+ # The RDoc Markdown parser has the following built-in behaviors that cannot be
33
+ # disabled.
34
+ #
35
+ # Underscores embedded in words are never interpreted as emphasis. (While the
36
+ # [markdown dingus][dingus] emphasizes in-word underscores, neither the
37
+ # Markdown syntax nor MarkdownTest mention this behavior.)
38
+ #
39
+ # For HTML output, RDoc always auto-links bare URLs.
40
+ #
41
+ # ### Break on Newline
42
+ #
43
+ # The break_on_newline extension converts all newlines into hard line breaks
44
+ # as in [Github Flavored Markdown][GFM]. This extension is disabled by
45
+ # default.
46
+ #
47
+ # ### CSS
48
+ #
49
+ # The #css extension enables CSS blocks to be included in the output, but they
50
+ # are not used for any built-in RDoc output format. This extension is disabled
51
+ # by default.
52
+ #
53
+ # Example:
54
+ #
55
+ # <style type="text/css">
56
+ # h1 { font-size: 3em }
57
+ # </style>
58
+ #
59
+ # ### Definition Lists
60
+ #
61
+ # The definition_lists extension allows definition lists using the [PHP
62
+ # Markdown Extra syntax][PHPE], but only one label and definition are supported
63
+ # at this time. This extension is enabled by default.
64
+ #
65
+ # Example:
66
+ #
67
+ # ```
68
+ # cat
69
+ # : A small furry mammal
70
+ # that seems to sleep a lot
71
+ #
72
+ # ant
73
+ # : A little insect that is known
74
+ # to enjoy picnics
75
+ #
76
+ # ```
77
+ #
78
+ # Produces:
79
+ #
80
+ # cat
81
+ # : A small furry mammal
82
+ # that seems to sleep a lot
83
+ #
84
+ # ant
85
+ # : A little insect that is known
86
+ # to enjoy picnics
87
+ #
88
+ # ### Strike
89
+ #
90
+ # Example:
91
+ #
92
+ # ```
93
+ # This is ~~striked~~.
94
+ # ```
95
+ #
96
+ # Produces:
97
+ #
98
+ # This is ~~striked~~.
99
+ #
100
+ # ### Github
101
+ #
102
+ # The #github extension enables a partial set of [Github Flavored Markdown]
103
+ # [GFM]. This extension is enabled by default.
104
+ #
105
+ # Supported github extensions include:
106
+ #
107
+ # #### Fenced code blocks
108
+ #
109
+ # Use ` ``` ` around a block of code instead of indenting it four spaces.
110
+ #
111
+ # #### Syntax highlighting
112
+ #
113
+ # Use ` ``` ruby ` as the start of a code fence to add syntax highlighting.
114
+ # (Currently only `ruby` syntax is supported).
115
+ #
116
+ # ### HTML
117
+ #
118
+ # Enables raw HTML to be included in the output. This extension is enabled by
119
+ # default.
120
+ #
121
+ # Example:
122
+ #
123
+ # <table>
124
+ # ...
125
+ # </table>
126
+ #
127
+ # ### Notes
128
+ #
129
+ # The #notes extension enables footnote support. This extension is enabled by
130
+ # default.
131
+ #
132
+ # Example:
133
+ #
134
+ # Here is some text[^1] including an inline footnote ^[for short footnotes]
135
+ #
136
+ # ...
137
+ #
138
+ # [^1]: With the footnote text down at the bottom
139
+ #
140
+ # Produces:
141
+ #
142
+ # Here is some text[^1] including an inline footnote ^[for short footnotes]
143
+ #
144
+ # [^1]: With the footnote text down at the bottom
145
+ #
146
+ # ## Limitations
147
+ #
148
+ # * Link titles are not used
149
+ # * Footnotes are collapsed into a single paragraph
150
+ #
151
+ # ## Author
152
+ #
153
+ # This markdown parser is a port to kpeg from [peg-markdown][pegmarkdown] by
154
+ # John MacFarlane.
155
+ #
156
+ # It is used under the MIT license:
157
+ #
158
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
159
+ # of this software and associated documentation files (the "Software"), to deal
160
+ # in the Software without restriction, including without limitation the rights
161
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
162
+ # copies of the Software, and to permit persons to whom the Software is
163
+ # furnished to do so, subject to the following conditions:
164
+ #
165
+ # The above copyright notice and this permission notice shall be included in
166
+ # all copies or substantial portions of the Software.
167
+ #
168
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
169
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
170
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
171
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
172
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
173
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
174
+ # THE SOFTWARE.
175
+ #
176
+ # The port to kpeg was performed by Eric Hodel and Evan Phoenix
177
+ #
178
+ # [dingus]: http://daringfireball.net/projects/markdown/dingus
179
+ # [GFM]: https://github.github.com/gfm/
180
+ # [pegmarkdown]: https://github.com/jgm/peg-markdown
181
+ # [PHPE]: http://michelf.com/projects/php-markdown/extra/#def-list
182
+ # [syntax]: http://daringfireball.net/projects/markdown/syntax
183
+ #--
184
+ # Last updated to jgm/peg-markdown commit 8f8fc22ef0
185
+
186
+ }
187
+
188
+ %% {
189
+
190
+ require 'rdoc'
191
+ require 'rdoc/markup/to_joined_paragraph'
192
+ require 'rdoc/markdown/entities'
193
+
194
+ require 'rdoc/markdown/literals'
195
+
196
+ ##
197
+ # Supported extensions
198
+
199
+ EXTENSIONS = []
200
+
201
+ ##
202
+ # Extensions enabled by default
203
+
204
+ DEFAULT_EXTENSIONS = [
205
+ :definition_lists,
206
+ :github,
207
+ :html,
208
+ :notes,
209
+ :strike,
210
+ ]
211
+
212
+ # :section: Extensions
213
+
214
+ ##
215
+ # Creates extension methods for the `name` extension to enable and disable
216
+ # the extension and to query if they are active.
217
+
218
+ def self.extension name
219
+ EXTENSIONS << name
220
+
221
+ define_method "#{name}?" do
222
+ extension? name
223
+ end
224
+
225
+ define_method "#{name}=" do |enable|
226
+ extension name, enable
227
+ end
228
+ end
229
+
230
+ ##
231
+ # Converts all newlines into hard breaks
232
+
233
+ extension :break_on_newline
234
+
235
+ ##
236
+ # Allow style blocks
237
+
238
+ extension :css
239
+
240
+ ##
241
+ # Allow PHP Markdown Extras style definition lists
242
+
243
+ extension :definition_lists
244
+
245
+ ##
246
+ # Allow Github Flavored Markdown
247
+
248
+ extension :github
249
+
250
+ ##
251
+ # Allow HTML
252
+
253
+ extension :html
254
+
255
+ ##
256
+ # Enables the notes extension
257
+
258
+ extension :notes
259
+
260
+ ##
261
+ # Enables the strike extension
262
+
263
+ extension :strike
264
+
265
+ # :section:
266
+
267
+ ##
268
+ # Parses the `markdown` document into an RDoc::Document using the default
269
+ # extensions.
270
+
271
+ def self.parse markdown
272
+ parser = new
273
+
274
+ parser.parse markdown
275
+ end
276
+
277
+ # TODO remove when kpeg 0.10 is released
278
+ alias orig_initialize initialize # :nodoc:
279
+
280
+ ##
281
+ # Creates a new markdown parser that enables the given +extensions+.
282
+
283
+ def initialize extensions = DEFAULT_EXTENSIONS, debug = false
284
+ @debug = debug
285
+ @formatter = RDoc::Markup::ToJoinedParagraph.new
286
+ @extensions = extensions
287
+
288
+ @references = nil
289
+ @unlinked_references = nil
290
+
291
+ @footnotes = nil
292
+ @note_order = nil
293
+ end
294
+
295
+ ##
296
+ # Wraps `text` in emphasis for rdoc inline formatting
297
+
298
+ def emphasis text
299
+ if text =~ /\A[a-z\d.\/]+\z/i then
300
+ "_#{text}_"
301
+ else
302
+ "<em>#{text}</em>"
303
+ end
304
+ end
305
+
306
+ ##
307
+ # :category: Extensions
308
+ #
309
+ # Is the extension `name` enabled?
310
+
311
+ def extension? name
312
+ @extensions.include? name
313
+ end
314
+
315
+ ##
316
+ # :category: Extensions
317
+ #
318
+ # Enables or disables the extension with `name`
319
+
320
+ def extension name, enable
321
+ if enable then
322
+ @extensions |= [name]
323
+ else
324
+ @extensions -= [name]
325
+ end
326
+ end
327
+
328
+ ##
329
+ # Parses `text` in a clone of this parser. This is used for handling nested
330
+ # lists the same way as markdown_parser.
331
+
332
+ def inner_parse text # :nodoc:
333
+ parser = clone
334
+
335
+ parser.setup_parser text, @debug
336
+
337
+ parser.peg_parse
338
+
339
+ doc = parser.result
340
+
341
+ doc.accept @formatter
342
+
343
+ doc.parts
344
+ end
345
+
346
+ ##
347
+ # Finds a link reference for `label` and creates a new link to it with
348
+ # `content` as the link text. If `label` was not encountered in the
349
+ # reference-gathering parser pass the label and content are reconstructed
350
+ # with the linking `text` (usually whitespace).
351
+
352
+ def link_to content, label = content, text = nil
353
+ raise ParseError, 'enable notes extension' if
354
+ content.start_with? '^' and label.equal? content
355
+
356
+ if ref = @references[label] then
357
+ "{#{content}}[#{ref}]"
358
+ elsif label.equal? content then
359
+ "[#{content}]#{text}"
360
+ else
361
+ "[#{content}]#{text}[#{label}]"
362
+ end
363
+ end
364
+
365
+ ##
366
+ # Creates an RDoc::Markup::ListItem by parsing the `unparsed` content from
367
+ # the first parsing pass.
368
+
369
+ def list_item_from unparsed
370
+ parsed = inner_parse unparsed.join
371
+ RDoc::Markup::ListItem.new nil, *parsed
372
+ end
373
+
374
+ ##
375
+ # Stores `label` as a note and fills in previously unknown note references.
376
+
377
+ def note label
378
+ #foottext = "rdoc-label:foottext-#{label}:footmark-#{label}"
379
+
380
+ #ref.replace foottext if ref = @unlinked_notes.delete(label)
381
+
382
+ @notes[label] = foottext
383
+
384
+ #"{^1}[rdoc-label:footmark-#{label}:foottext-#{label}] "
385
+ end
386
+
387
+ ##
388
+ # Creates a new link for the footnote `reference` and adds the reference to
389
+ # the note order list for proper display at the end of the document.
390
+
391
+ def note_for ref
392
+ @note_order << ref
393
+
394
+ label = @note_order.length
395
+
396
+ "{*#{label}}[rdoc-label:foottext-#{label}:footmark-#{label}]"
397
+ end
398
+
399
+ ##
400
+ # The internal kpeg parse method
401
+
402
+ alias peg_parse parse # :nodoc:
403
+
404
+ ##
405
+ # Creates an RDoc::Markup::Paragraph from `parts` and including
406
+ # extension-specific behavior
407
+
408
+ def paragraph parts
409
+ parts = parts.map do |part|
410
+ if "\n" == part then
411
+ RDoc::Markup::HardBreak.new
412
+ else
413
+ part
414
+ end
415
+ end if break_on_newline?
416
+
417
+ RDoc::Markup::Paragraph.new(*parts)
418
+ end
419
+
420
+ ##
421
+ # Parses `markdown` into an RDoc::Document
422
+
423
+ def parse markdown
424
+ @references = {}
425
+ @unlinked_references = {}
426
+
427
+ markdown += "\n\n"
428
+
429
+ setup_parser markdown, @debug
430
+ peg_parse 'References'
431
+
432
+ if notes? then
433
+ @footnotes = {}
434
+
435
+ setup_parser markdown, @debug
436
+ peg_parse 'Notes'
437
+
438
+ # using note_order on the first pass would be a bug
439
+ @note_order = []
440
+ end
441
+
442
+ setup_parser markdown, @debug
443
+ peg_parse
444
+
445
+ doc = result
446
+
447
+ if notes? and not @footnotes.empty? then
448
+ doc << RDoc::Markup::Rule.new(1)
449
+
450
+ @note_order.each_with_index do |ref, index|
451
+ label = index + 1
452
+ note = @footnotes[ref]
453
+
454
+ link = "{^#{label}}[rdoc-label:footmark-#{label}:foottext-#{label}] "
455
+ note.parts.unshift link
456
+
457
+ doc << note
458
+ end
459
+ end
460
+
461
+ doc.accept @formatter
462
+
463
+ doc
464
+ end
465
+
466
+ ##
467
+ # Stores `label` as a reference to `link` and fills in previously unknown
468
+ # link references.
469
+
470
+ def reference label, link
471
+ if ref = @unlinked_references.delete(label) then
472
+ ref.replace link
473
+ end
474
+
475
+ @references[label] = link
476
+ end
477
+
478
+ ##
479
+ # Wraps `text` in strong markup for rdoc inline formatting
480
+
481
+ def strong text
482
+ if text =~ /\A[a-z\d.\/-]+\z/i then
483
+ "*#{text}*"
484
+ else
485
+ "<b>#{text}</b>"
486
+ end
487
+ end
488
+
489
+ ##
490
+ # Wraps `text` in strike markup for rdoc inline formatting
491
+
492
+ def strike text
493
+ if text =~ /\A[a-z\d.\/-]+\z/i then
494
+ "~#{text}~"
495
+ else
496
+ "<s>#{text}</s>"
497
+ end
498
+ end
499
+ }
500
+
501
+ root = Doc
502
+
503
+ Doc = BOM? Block*:a { RDoc::Markup::Document.new(*a.compact) }
504
+
505
+ Block = @BlankLine*
506
+ ( BlockQuote
507
+ | Verbatim
508
+ | CodeFence
509
+ | Table
510
+ | Note
511
+ | Reference
512
+ | HorizontalRule
513
+ | Heading
514
+ | OrderedList
515
+ | BulletList
516
+ | DefinitionList
517
+ | HtmlBlock
518
+ | StyleBlock
519
+ | Para
520
+ | Plain )
521
+
522
+ Para = @NonindentSpace Inlines:a @BlankLine+
523
+ { paragraph a }
524
+
525
+ Plain = Inlines:a
526
+ { paragraph a }
527
+
528
+ AtxInline = !@Newline !(@Sp /#*/ @Sp @Newline) Inline
529
+
530
+ AtxStart = < /\#{1,6}/ >
531
+ { text.length }
532
+
533
+ AtxHeading = AtxStart:s @Sp AtxInline+:a (@Sp /#*/ @Sp)? @Newline
534
+ { RDoc::Markup::Heading.new(s, a.join) }
535
+
536
+ SetextHeading = SetextHeading1 | SetextHeading2
537
+
538
+ SetextBottom1 = /={1,}/ @Newline
539
+
540
+ SetextBottom2 = /-{1,}/ @Newline
541
+
542
+ SetextHeading1 = &(@RawLine SetextBottom1)
543
+ @StartList:a ( !@Endline Inline:b { a << b } )+ @Sp @Newline
544
+ SetextBottom1
545
+ { RDoc::Markup::Heading.new(1, a.join) }
546
+
547
+ SetextHeading2 = &(@RawLine SetextBottom2)
548
+ @StartList:a ( !@Endline Inline:b { a << b })+ @Sp @Newline
549
+ SetextBottom2
550
+ { RDoc::Markup::Heading.new(2, a.join) }
551
+
552
+ Heading = SetextHeading | AtxHeading
553
+
554
+ BlockQuote = BlockQuoteRaw:a
555
+ { RDoc::Markup::BlockQuote.new(*a) }
556
+
557
+ BlockQuoteRaw = @StartList:a
558
+ (( ">" " "? Line:l { a << l } )
559
+ ( !">" !@BlankLine Line:c { a << c } )*
560
+ ( @BlankLine:n { a << n } )*
561
+ )+
562
+ { inner_parse a.join }
563
+
564
+ NonblankIndentedLine = !@BlankLine IndentedLine
565
+
566
+ VerbatimChunk = @BlankLine*:a
567
+ NonblankIndentedLine+:b
568
+ { a.concat b }
569
+
570
+ Verbatim = VerbatimChunk+:a
571
+ { RDoc::Markup::Verbatim.new(*a.flatten) }
572
+
573
+ HorizontalRule = @NonindentSpace
574
+ ( "*" @Sp "*" @Sp "*" (@Sp "*")*
575
+ | "-" @Sp "-" @Sp "-" (@Sp "-")*
576
+ | "_" @Sp "_" @Sp "_" (@Sp "_")*)
577
+ @Sp @Newline @BlankLine+
578
+ { RDoc::Markup::Rule.new 1 }
579
+
580
+ Bullet = !HorizontalRule @NonindentSpace /[+*-]/ @Spacechar+
581
+
582
+ BulletList = &Bullet (ListTight | ListLoose):a
583
+ { RDoc::Markup::List.new(:BULLET, *a) }
584
+
585
+ ListTight = ListItemTight+:a
586
+ @BlankLine* !(Bullet | Enumerator)
587
+ { a }
588
+
589
+ ListLoose = @StartList:a
590
+ ( ListItem:b @BlankLine* { a << b } )+
591
+ { a }
592
+
593
+ ListItem = ( Bullet | Enumerator )
594
+ @StartList:a
595
+ ListBlock:b { a << b }
596
+ ( ListContinuationBlock:c { a.push(*c) } )*
597
+ { list_item_from a }
598
+
599
+ ListItemTight =
600
+ ( Bullet | Enumerator )
601
+ ListBlock:a
602
+ ( !@BlankLine
603
+ ListContinuationBlock:b { a.push(*b) } )*
604
+ !ListContinuationBlock
605
+ { list_item_from a }
606
+
607
+ ListBlock = !@BlankLine Line:a
608
+ ListBlockLine*:c
609
+ { [a, *c] }
610
+
611
+ ListContinuationBlock = @StartList:a
612
+ ( @BlankLine*
613
+ { a << "\n" } )
614
+ ( Indent
615
+ ListBlock:b { a.concat b } )+
616
+ { a }
617
+
618
+ Enumerator = @NonindentSpace [0-9]+ "." @Spacechar+
619
+
620
+ OrderedList = &Enumerator (ListTight | ListLoose):a
621
+ { RDoc::Markup::List.new(:NUMBER, *a) }
622
+
623
+ ListBlockLine = !@BlankLine
624
+ !( Indent? (Bullet | Enumerator) )
625
+ !HorizontalRule
626
+ OptionallyIndentedLine
627
+
628
+ # Parsers for different kinds of block-level HTML content.
629
+ # This is repetitive due to constraints of PEG grammar.
630
+
631
+ HtmlOpenAnchor = "<" Spnl ("a" | "A") Spnl HtmlAttribute* ">"
632
+ HtmlCloseAnchor = "<" Spnl "/" ("a" | "A") Spnl ">"
633
+ HtmlAnchor = HtmlOpenAnchor (HtmlAnchor | !HtmlCloseAnchor .)* HtmlCloseAnchor
634
+
635
+ HtmlBlockOpenAddress = "<" Spnl ("address" | "ADDRESS") Spnl HtmlAttribute* ">"
636
+ HtmlBlockCloseAddress = "<" Spnl "/" ("address" | "ADDRESS") Spnl ">"
637
+ HtmlBlockAddress = HtmlBlockOpenAddress (HtmlBlockAddress | !HtmlBlockCloseAddress .)* HtmlBlockCloseAddress
638
+
639
+ HtmlBlockOpenBlockquote = "<" Spnl ("blockquote" | "BLOCKQUOTE") Spnl HtmlAttribute* ">"
640
+ HtmlBlockCloseBlockquote = "<" Spnl "/" ("blockquote" | "BLOCKQUOTE") Spnl ">"
641
+ HtmlBlockBlockquote = HtmlBlockOpenBlockquote (HtmlBlockBlockquote | !HtmlBlockCloseBlockquote .)* HtmlBlockCloseBlockquote
642
+
643
+ HtmlBlockOpenCenter = "<" Spnl ("center" | "CENTER") Spnl HtmlAttribute* ">"
644
+ HtmlBlockCloseCenter = "<" Spnl "/" ("center" | "CENTER") Spnl ">"
645
+ HtmlBlockCenter = HtmlBlockOpenCenter (HtmlBlockCenter | !HtmlBlockCloseCenter .)* HtmlBlockCloseCenter
646
+
647
+ HtmlBlockOpenDir = "<" Spnl ("dir" | "DIR") Spnl HtmlAttribute* ">"
648
+ HtmlBlockCloseDir = "<" Spnl "/" ("dir" | "DIR") Spnl ">"
649
+ HtmlBlockDir = HtmlBlockOpenDir (HtmlBlockDir | !HtmlBlockCloseDir .)* HtmlBlockCloseDir
650
+
651
+ HtmlBlockOpenDiv = "<" Spnl ("div" | "DIV") Spnl HtmlAttribute* ">"
652
+ HtmlBlockCloseDiv = "<" Spnl "/" ("div" | "DIV") Spnl ">"
653
+ HtmlBlockDiv = HtmlBlockOpenDiv (HtmlBlockDiv | !HtmlBlockCloseDiv .)* HtmlBlockCloseDiv
654
+
655
+ HtmlBlockOpenDl = "<" Spnl ("dl" | "DL") Spnl HtmlAttribute* ">"
656
+ HtmlBlockCloseDl = "<" Spnl "/" ("dl" | "DL") Spnl ">"
657
+ HtmlBlockDl = HtmlBlockOpenDl (HtmlBlockDl | !HtmlBlockCloseDl .)* HtmlBlockCloseDl
658
+
659
+ HtmlBlockOpenFieldset = "<" Spnl ("fieldset" | "FIELDSET") Spnl HtmlAttribute* ">"
660
+ HtmlBlockCloseFieldset = "<" Spnl "/" ("fieldset" | "FIELDSET") Spnl ">"
661
+ HtmlBlockFieldset = HtmlBlockOpenFieldset (HtmlBlockFieldset | !HtmlBlockCloseFieldset .)* HtmlBlockCloseFieldset
662
+
663
+ HtmlBlockOpenForm = "<" Spnl ("form" | "FORM") Spnl HtmlAttribute* ">"
664
+ HtmlBlockCloseForm = "<" Spnl "/" ("form" | "FORM") Spnl ">"
665
+ HtmlBlockForm = HtmlBlockOpenForm (HtmlBlockForm | !HtmlBlockCloseForm .)* HtmlBlockCloseForm
666
+
667
+ HtmlBlockOpenH1 = "<" Spnl ("h1" | "H1") Spnl HtmlAttribute* ">"
668
+ HtmlBlockCloseH1 = "<" Spnl "/" ("h1" | "H1") Spnl ">"
669
+ HtmlBlockH1 = HtmlBlockOpenH1 (HtmlBlockH1 | !HtmlBlockCloseH1 .)* HtmlBlockCloseH1
670
+
671
+ HtmlBlockOpenH2 = "<" Spnl ("h2" | "H2") Spnl HtmlAttribute* ">"
672
+ HtmlBlockCloseH2 = "<" Spnl "/" ("h2" | "H2") Spnl ">"
673
+ HtmlBlockH2 = HtmlBlockOpenH2 (HtmlBlockH2 | !HtmlBlockCloseH2 .)* HtmlBlockCloseH2
674
+
675
+ HtmlBlockOpenH3 = "<" Spnl ("h3" | "H3") Spnl HtmlAttribute* ">"
676
+ HtmlBlockCloseH3 = "<" Spnl "/" ("h3" | "H3") Spnl ">"
677
+ HtmlBlockH3 = HtmlBlockOpenH3 (HtmlBlockH3 | !HtmlBlockCloseH3 .)* HtmlBlockCloseH3
678
+
679
+ HtmlBlockOpenH4 = "<" Spnl ("h4" | "H4") Spnl HtmlAttribute* ">"
680
+ HtmlBlockCloseH4 = "<" Spnl "/" ("h4" | "H4") Spnl ">"
681
+ HtmlBlockH4 = HtmlBlockOpenH4 (HtmlBlockH4 | !HtmlBlockCloseH4 .)* HtmlBlockCloseH4
682
+
683
+ HtmlBlockOpenH5 = "<" Spnl ("h5" | "H5") Spnl HtmlAttribute* ">"
684
+ HtmlBlockCloseH5 = "<" Spnl "/" ("h5" | "H5") Spnl ">"
685
+ HtmlBlockH5 = HtmlBlockOpenH5 (HtmlBlockH5 | !HtmlBlockCloseH5 .)* HtmlBlockCloseH5
686
+
687
+ HtmlBlockOpenH6 = "<" Spnl ("h6" | "H6") Spnl HtmlAttribute* ">"
688
+ HtmlBlockCloseH6 = "<" Spnl "/" ("h6" | "H6") Spnl ">"
689
+ HtmlBlockH6 = HtmlBlockOpenH6 (HtmlBlockH6 | !HtmlBlockCloseH6 .)* HtmlBlockCloseH6
690
+
691
+ HtmlBlockOpenMenu = "<" Spnl ("menu" | "MENU") Spnl HtmlAttribute* ">"
692
+ HtmlBlockCloseMenu = "<" Spnl "/" ("menu" | "MENU") Spnl ">"
693
+ HtmlBlockMenu = HtmlBlockOpenMenu (HtmlBlockMenu | !HtmlBlockCloseMenu .)* HtmlBlockCloseMenu
694
+
695
+ HtmlBlockOpenNoframes = "<" Spnl ("noframes" | "NOFRAMES") Spnl HtmlAttribute* ">"
696
+ HtmlBlockCloseNoframes = "<" Spnl "/" ("noframes" | "NOFRAMES") Spnl ">"
697
+ HtmlBlockNoframes = HtmlBlockOpenNoframes (HtmlBlockNoframes | !HtmlBlockCloseNoframes .)* HtmlBlockCloseNoframes
698
+
699
+ HtmlBlockOpenNoscript = "<" Spnl ("noscript" | "NOSCRIPT") Spnl HtmlAttribute* ">"
700
+ HtmlBlockCloseNoscript = "<" Spnl "/" ("noscript" | "NOSCRIPT") Spnl ">"
701
+ HtmlBlockNoscript = HtmlBlockOpenNoscript (HtmlBlockNoscript | !HtmlBlockCloseNoscript .)* HtmlBlockCloseNoscript
702
+
703
+ HtmlBlockOpenOl = "<" Spnl ("ol" | "OL") Spnl HtmlAttribute* ">"
704
+ HtmlBlockCloseOl = "<" Spnl "/" ("ol" | "OL") Spnl ">"
705
+ HtmlBlockOl = HtmlBlockOpenOl (HtmlBlockOl | !HtmlBlockCloseOl .)* HtmlBlockCloseOl
706
+
707
+ HtmlBlockOpenP = "<" Spnl ("p" | "P") Spnl HtmlAttribute* ">"
708
+ HtmlBlockCloseP = "<" Spnl "/" ("p" | "P") Spnl ">"
709
+ HtmlBlockP = HtmlBlockOpenP (HtmlBlockP | !HtmlBlockCloseP .)* HtmlBlockCloseP
710
+
711
+ HtmlBlockOpenPre = "<" Spnl ("pre" | "PRE") Spnl HtmlAttribute* ">"
712
+ HtmlBlockClosePre = "<" Spnl "/" ("pre" | "PRE") Spnl ">"
713
+ HtmlBlockPre = HtmlBlockOpenPre (HtmlBlockPre | !HtmlBlockClosePre .)* HtmlBlockClosePre
714
+
715
+ HtmlBlockOpenTable = "<" Spnl ("table" | "TABLE") Spnl HtmlAttribute* ">"
716
+ HtmlBlockCloseTable = "<" Spnl "/" ("table" | "TABLE") Spnl ">"
717
+ HtmlBlockTable = HtmlBlockOpenTable (HtmlBlockTable | !HtmlBlockCloseTable .)* HtmlBlockCloseTable
718
+
719
+ HtmlBlockOpenUl = "<" Spnl ("ul" | "UL") Spnl HtmlAttribute* ">"
720
+ HtmlBlockCloseUl = "<" Spnl "/" ("ul" | "UL") Spnl ">"
721
+ HtmlBlockUl = HtmlBlockOpenUl (HtmlBlockUl | !HtmlBlockCloseUl .)* HtmlBlockCloseUl
722
+
723
+ HtmlBlockOpenDd = "<" Spnl ("dd" | "DD") Spnl HtmlAttribute* ">"
724
+ HtmlBlockCloseDd = "<" Spnl "/" ("dd" | "DD") Spnl ">"
725
+ HtmlBlockDd = HtmlBlockOpenDd (HtmlBlockDd | !HtmlBlockCloseDd .)* HtmlBlockCloseDd
726
+
727
+ HtmlBlockOpenDt = "<" Spnl ("dt" | "DT") Spnl HtmlAttribute* ">"
728
+ HtmlBlockCloseDt = "<" Spnl "/" ("dt" | "DT") Spnl ">"
729
+ HtmlBlockDt = HtmlBlockOpenDt (HtmlBlockDt | !HtmlBlockCloseDt .)* HtmlBlockCloseDt
730
+
731
+ HtmlBlockOpenFrameset = "<" Spnl ("frameset" | "FRAMESET") Spnl HtmlAttribute* ">"
732
+ HtmlBlockCloseFrameset = "<" Spnl "/" ("frameset" | "FRAMESET") Spnl ">"
733
+ HtmlBlockFrameset = HtmlBlockOpenFrameset (HtmlBlockFrameset | !HtmlBlockCloseFrameset .)* HtmlBlockCloseFrameset
734
+
735
+ HtmlBlockOpenLi = "<" Spnl ("li" | "LI") Spnl HtmlAttribute* ">"
736
+ HtmlBlockCloseLi = "<" Spnl "/" ("li" | "LI") Spnl ">"
737
+ HtmlBlockLi = HtmlBlockOpenLi (HtmlBlockLi | !HtmlBlockCloseLi .)* HtmlBlockCloseLi
738
+
739
+ HtmlBlockOpenTbody = "<" Spnl ("tbody" | "TBODY") Spnl HtmlAttribute* ">"
740
+ HtmlBlockCloseTbody = "<" Spnl "/" ("tbody" | "TBODY") Spnl ">"
741
+ HtmlBlockTbody = HtmlBlockOpenTbody (HtmlBlockTbody | !HtmlBlockCloseTbody .)* HtmlBlockCloseTbody
742
+
743
+ HtmlBlockOpenTd = "<" Spnl ("td" | "TD") Spnl HtmlAttribute* ">"
744
+ HtmlBlockCloseTd = "<" Spnl "/" ("td" | "TD") Spnl ">"
745
+ HtmlBlockTd = HtmlBlockOpenTd (HtmlBlockTd | !HtmlBlockCloseTd .)* HtmlBlockCloseTd
746
+
747
+ HtmlBlockOpenTfoot = "<" Spnl ("tfoot" | "TFOOT") Spnl HtmlAttribute* ">"
748
+ HtmlBlockCloseTfoot = "<" Spnl "/" ("tfoot" | "TFOOT") Spnl ">"
749
+ HtmlBlockTfoot = HtmlBlockOpenTfoot (HtmlBlockTfoot | !HtmlBlockCloseTfoot .)* HtmlBlockCloseTfoot
750
+
751
+ HtmlBlockOpenTh = "<" Spnl ("th" | "TH") Spnl HtmlAttribute* ">"
752
+ HtmlBlockCloseTh = "<" Spnl "/" ("th" | "TH") Spnl ">"
753
+ HtmlBlockTh = HtmlBlockOpenTh (HtmlBlockTh | !HtmlBlockCloseTh .)* HtmlBlockCloseTh
754
+
755
+ HtmlBlockOpenThead = "<" Spnl ("thead" | "THEAD") Spnl HtmlAttribute* ">"
756
+ HtmlBlockCloseThead = "<" Spnl "/" ("thead" | "THEAD") Spnl ">"
757
+ HtmlBlockThead = HtmlBlockOpenThead (HtmlBlockThead | !HtmlBlockCloseThead .)* HtmlBlockCloseThead
758
+
759
+ HtmlBlockOpenTr = "<" Spnl ("tr" | "TR") Spnl HtmlAttribute* ">"
760
+ HtmlBlockCloseTr = "<" Spnl "/" ("tr" | "TR") Spnl ">"
761
+ HtmlBlockTr = HtmlBlockOpenTr (HtmlBlockTr | !HtmlBlockCloseTr .)* HtmlBlockCloseTr
762
+
763
+ HtmlBlockOpenScript = "<" Spnl ("script" | "SCRIPT") Spnl HtmlAttribute* ">"
764
+ HtmlBlockCloseScript = "<" Spnl "/" ("script" | "SCRIPT") Spnl ">"
765
+ HtmlBlockScript = HtmlBlockOpenScript (!HtmlBlockCloseScript .)* HtmlBlockCloseScript
766
+
767
+ HtmlBlockOpenHead = "<" Spnl ("head" | "HEAD") Spnl HtmlAttribute* ">"
768
+ HtmlBlockCloseHead = "<" Spnl "/" ("head" | "HEAD") Spnl ">"
769
+ HtmlBlockHead = HtmlBlockOpenHead (!HtmlBlockCloseHead .)* HtmlBlockCloseHead
770
+
771
+ HtmlBlockInTags = HtmlAnchor
772
+ | HtmlBlockAddress
773
+ | HtmlBlockBlockquote
774
+ | HtmlBlockCenter
775
+ | HtmlBlockDir
776
+ | HtmlBlockDiv
777
+ | HtmlBlockDl
778
+ | HtmlBlockFieldset
779
+ | HtmlBlockForm
780
+ | HtmlBlockH1
781
+ | HtmlBlockH2
782
+ | HtmlBlockH3
783
+ | HtmlBlockH4
784
+ | HtmlBlockH5
785
+ | HtmlBlockH6
786
+ | HtmlBlockMenu
787
+ | HtmlBlockNoframes
788
+ | HtmlBlockNoscript
789
+ | HtmlBlockOl
790
+ | HtmlBlockP
791
+ | HtmlBlockPre
792
+ | HtmlBlockTable
793
+ | HtmlBlockUl
794
+ | HtmlBlockDd
795
+ | HtmlBlockDt
796
+ | HtmlBlockFrameset
797
+ | HtmlBlockLi
798
+ | HtmlBlockTbody
799
+ | HtmlBlockTd
800
+ | HtmlBlockTfoot
801
+ | HtmlBlockTh
802
+ | HtmlBlockThead
803
+ | HtmlBlockTr
804
+ | HtmlBlockScript
805
+ | HtmlBlockHead
806
+
807
+ HtmlBlock = < ( HtmlBlockInTags | HtmlComment | HtmlBlockSelfClosing | HtmlUnclosed) >
808
+ @BlankLine+
809
+ { if html? then
810
+ RDoc::Markup::Raw.new text
811
+ end }
812
+
813
+ HtmlUnclosed = "<" Spnl HtmlUnclosedType Spnl HtmlAttribute* Spnl ">"
814
+
815
+ HtmlUnclosedType = "HR" | "hr"
816
+
817
+ HtmlBlockSelfClosing = "<" Spnl HtmlBlockType Spnl HtmlAttribute* "/" Spnl ">"
818
+
819
+ HtmlBlockType = "ADDRESS" |
820
+ "BLOCKQUOTE" |
821
+ "CENTER" |
822
+ "DD" |
823
+ "DIR" |
824
+ "DIV" |
825
+ "DL" |
826
+ "DT" |
827
+ "FIELDSET" |
828
+ "FORM" |
829
+ "FRAMESET" |
830
+ "H1" |
831
+ "H2" |
832
+ "H3" |
833
+ "H4" |
834
+ "H5" |
835
+ "H6" |
836
+ "HR" |
837
+ "ISINDEX" |
838
+ "LI" |
839
+ "MENU" |
840
+ "NOFRAMES" |
841
+ "NOSCRIPT" |
842
+ "OL" |
843
+ "P" |
844
+ "PRE" |
845
+ "SCRIPT" |
846
+ "TABLE" |
847
+ "TBODY" |
848
+ "TD" |
849
+ "TFOOT" |
850
+ "TH" |
851
+ "THEAD" |
852
+ "TR" |
853
+ "UL" |
854
+ "address" |
855
+ "blockquote" |
856
+ "center" |
857
+ "dd" |
858
+ "dir" |
859
+ "div" |
860
+ "dl" |
861
+ "dt" |
862
+ "fieldset" |
863
+ "form" |
864
+ "frameset" |
865
+ "h1" |
866
+ "h2" |
867
+ "h3" |
868
+ "h4" |
869
+ "h5" |
870
+ "h6" |
871
+ "hr" |
872
+ "isindex" |
873
+ "li" |
874
+ "menu" |
875
+ "noframes" |
876
+ "noscript" |
877
+ "ol" |
878
+ "p" |
879
+ "pre" |
880
+ "script" |
881
+ "table" |
882
+ "tbody" |
883
+ "td" |
884
+ "tfoot" |
885
+ "th" |
886
+ "thead" |
887
+ "tr" |
888
+ "ul"
889
+
890
+ StyleOpen = "<" Spnl ("style" | "STYLE") Spnl HtmlAttribute* ">"
891
+ StyleClose = "<" Spnl "/" ("style" | "STYLE") Spnl ">"
892
+ InStyleTags = StyleOpen (!StyleClose .)* StyleClose
893
+ StyleBlock = < InStyleTags >
894
+ @BlankLine*
895
+ { if css? then
896
+ RDoc::Markup::Raw.new text
897
+ end }
898
+
899
+ Inlines = ( !@Endline Inline:i { i }
900
+ | @Endline:c !( &{ github? } Ticks3 /[^`\n]*$/ )
901
+ &Inline { c } )+:chunks @Endline?
902
+ { chunks }
903
+
904
+ Inline = Str
905
+ | @Endline
906
+ | UlOrStarLine
907
+ | @Space
908
+ | Strong
909
+ | Emph
910
+ | Strike
911
+ | Image
912
+ | Link
913
+ | NoteReference
914
+ | InlineNote
915
+ | Code
916
+ | RawHtml
917
+ | Entity
918
+ | EscapedChar
919
+ | Symbol
920
+
921
+ Space = @Spacechar+ { " " }
922
+
923
+ Str = @StartList:a
924
+ < @NormalChar+ > { a = text }
925
+ ( StrChunk:c { a << c } )* { a }
926
+
927
+ StrChunk = < (@NormalChar | /_+/ &Alphanumeric)+ > { text }
928
+
929
+ EscapedChar = "\\" !@Newline < /[:\\`|*_{}\[\]()#+.!><-]/ > { text }
930
+
931
+ Entity = ( HexEntity | DecEntity | CharEntity ):a { a }
932
+
933
+ Endline = @LineBreak | @TerminalEndline | @NormalEndline
934
+
935
+ NormalEndline = @Sp @Newline !@BlankLine !">" !AtxStart
936
+ !(Line /={1,}|-{1,}/ @Newline)
937
+ { "\n" }
938
+
939
+ TerminalEndline = @Sp @Newline @Eof
940
+
941
+ LineBreak = " " @NormalEndline { RDoc::Markup::HardBreak.new }
942
+
943
+ Symbol = < @SpecialChar >
944
+ { text }
945
+
946
+ # This keeps the parser from getting bogged down on long strings of '*' or '_',
947
+ # or strings of '*' or '_' with space on each side:
948
+ UlOrStarLine = (UlLine | StarLine):a { a }
949
+ StarLine = < /\*{4,}/ > { text } |
950
+ < @Spacechar /\*+/ &@Spacechar > { text }
951
+ UlLine = < /_{4,}/ > { text } |
952
+ < @Spacechar /_+/ &@Spacechar > { text }
953
+
954
+ Emph = EmphStar | EmphUl
955
+
956
+ Whitespace = @Spacechar | @Newline
957
+
958
+ EmphStar = "*" !@Whitespace
959
+ @StartList:a
960
+ ( !"*" Inline:b { a << b }
961
+ | StrongStar:b { a << b }
962
+ )+
963
+ "*"
964
+ { emphasis a.join }
965
+
966
+ EmphUl = "_" !@Whitespace
967
+ @StartList:a
968
+ ( !"_" Inline:b { a << b }
969
+ | StrongUl:b { a << b }
970
+ )+
971
+ "_"
972
+ { emphasis a.join }
973
+
974
+ Strong = StrongStar | StrongUl
975
+
976
+ StrongStar = "**" !@Whitespace
977
+ @StartList:a
978
+ ( !"**" Inline:b { a << b } )+
979
+ "**"
980
+ { strong a.join }
981
+
982
+ StrongUl = "__" !@Whitespace
983
+ @StartList:a
984
+ ( !"__" Inline:b { a << b } )+
985
+ "__"
986
+ { strong a.join }
987
+
988
+ Strike = &{ strike? }
989
+ "~~" !@Whitespace
990
+ @StartList:a
991
+ ( !"~~" Inline:b { a << b } )+
992
+ "~~"
993
+ { strike a.join }
994
+
995
+ # TODO alt text support
996
+ Image = "!" ( ExplicitLink | ReferenceLink ):a
997
+ { "rdoc-image:#{a[/\[(.*)\]/, 1]}" }
998
+
999
+ Link = ExplicitLink | ReferenceLink | AutoLink
1000
+
1001
+ ReferenceLink = ReferenceLinkDouble | ReferenceLinkSingle
1002
+
1003
+ ReferenceLinkDouble = Label:content < Spnl > !"[]" Label:label
1004
+ { link_to content, label, text }
1005
+
1006
+ ReferenceLinkSingle = Label:content < (Spnl "[]")? >
1007
+ { link_to content, content, text }
1008
+
1009
+ ExplicitLink = Label:l "(" @Sp Source:s Spnl Title @Sp ")"
1010
+ { "{#{l}}[#{s}]" }
1011
+
1012
+ Source = ( "<" < SourceContents > ">" | < SourceContents > )
1013
+ { text }
1014
+
1015
+ SourceContents = ( ( !"(" !")" !">" Nonspacechar )+ | "(" SourceContents ")")*
1016
+
1017
+ Title = ( TitleSingle | TitleDouble | "" ):a
1018
+ { a }
1019
+
1020
+ TitleSingle = "'" ( !( "'" @Sp ( ")" | @Newline ) ) . )* "'"
1021
+
1022
+ TitleDouble = "\"" ( !( "\"" @Sp ( ")" | @Newline ) ) . )* "\""
1023
+
1024
+ AutoLink = AutoLinkUrl | AutoLinkEmail
1025
+
1026
+ AutoLinkUrl = "<" < /[A-Za-z]+/ "://" ( !@Newline !">" . )+ > ">"
1027
+ { text }
1028
+
1029
+ AutoLinkEmail = "<" ("mailto:")? < /[\w+.\/!%~$-]+/i "@" ( !@Newline !">" . )+ > ">"
1030
+ { "mailto:#{text}" }
1031
+
1032
+ Reference = @NonindentSpace !"[]"
1033
+ Label:label ":" Spnl RefSrc:link RefTitle @BlankLine+
1034
+ { # TODO use title
1035
+ reference label, link
1036
+ nil
1037
+ }
1038
+
1039
+ Label = "[" ( !"^" &{ notes? } | &. &{ !notes? } )
1040
+ @StartList:a
1041
+ ( !"]" Inline:l { a << l } )*
1042
+ "]"
1043
+ { a.join.gsub(/\s+/, ' ') }
1044
+
1045
+ RefSrc = < Nonspacechar+ > { text }
1046
+
1047
+ RefTitle = ( RefTitleSingle | RefTitleDouble | RefTitleParens | EmptyTitle )
1048
+
1049
+ EmptyTitle = ""
1050
+
1051
+ RefTitleSingle = Spnl "'" < ( !( "'" @Sp @Newline | @Newline ) . )* > "'" { text }
1052
+
1053
+ RefTitleDouble = Spnl "\"" < ( !("\"" @Sp @Newline | @Newline) . )* > "\"" { text }
1054
+
1055
+ RefTitleParens = Spnl "(" < ( !(")" @Sp @Newline | @Newline) . )* > ")" { text }
1056
+
1057
+ References = ( Reference | SkipBlock )*
1058
+
1059
+ Ticks1 = "`" !"`"
1060
+ Ticks2 = "``" !"`"
1061
+ Ticks3 = "```" !"`"
1062
+ Ticks4 = "````" !"`"
1063
+ Ticks5 = "`````" !"`"
1064
+
1065
+ Code = ( Ticks1 @Sp < (
1066
+ ( !"`" Nonspacechar )+ | !Ticks1 /`+/ |
1067
+ !( @Sp Ticks1 ) ( @Spacechar | @Newline !@BlankLine )
1068
+ )+ > @Sp Ticks1 |
1069
+ Ticks2 @Sp < (
1070
+ ( !"`" Nonspacechar )+ |
1071
+ !Ticks2 /`+/ |
1072
+ !( @Sp Ticks2 ) ( @Spacechar | @Newline !@BlankLine )
1073
+ )+ > @Sp Ticks2 |
1074
+ Ticks3 @Sp < (
1075
+ ( !"`" Nonspacechar )+ |
1076
+ !Ticks3 /`+/ |
1077
+ !( @Sp Ticks3 ) ( @Spacechar | @Newline !@BlankLine )
1078
+ )+ > @Sp Ticks3 |
1079
+ Ticks4 @Sp < (
1080
+ ( !"`" Nonspacechar )+ |
1081
+ !Ticks4 /`+/ |
1082
+ !( @Sp Ticks4 ) ( @Spacechar | @Newline !@BlankLine )
1083
+ )+ > @Sp Ticks4 |
1084
+ Ticks5 @Sp < (
1085
+ ( !"`" Nonspacechar )+ |
1086
+ !Ticks5 /`+/ |
1087
+ !( @Sp Ticks5 ) ( @Spacechar | @Newline !@BlankLine )
1088
+ )+ > @Sp Ticks5
1089
+ )
1090
+ { "<code>#{text}</code>" }
1091
+
1092
+ RawHtml = < (HtmlComment | HtmlBlockScript | HtmlTag) >
1093
+ { if html? then text else '' end }
1094
+
1095
+ BlankLine = @Sp @Newline { "\n" }
1096
+
1097
+ Quoted = "\"" (!"\"" .)* "\"" | "'" (!"'" .)* "'"
1098
+ HtmlAttribute = (AlphanumericAscii | "-")+ Spnl ("=" Spnl (Quoted | (!">" Nonspacechar)+))? Spnl
1099
+ HtmlComment = "<!--" (!"-->" .)* "-->"
1100
+ HtmlTag = "<" Spnl "/"? AlphanumericAscii+ Spnl HtmlAttribute* "/"? Spnl ">"
1101
+ Eof = !.
1102
+ Nonspacechar = !@Spacechar !@Newline .
1103
+ Sp = @Spacechar*
1104
+ Spnl = @Sp (@Newline @Sp)?
1105
+ SpecialChar = /[~*_`&\[\]()<!#\\'"]/ | @ExtendedSpecialChar
1106
+ NormalChar = !( @SpecialChar | @Spacechar | @Newline ) .
1107
+ Digit = [0-9]
1108
+
1109
+ %literals = RDoc::Markdown::Literals
1110
+ Alphanumeric = %literals.Alphanumeric
1111
+ AlphanumericAscii = %literals.AlphanumericAscii
1112
+ BOM = %literals.BOM
1113
+ Newline = %literals.Newline
1114
+ Spacechar = %literals.Spacechar
1115
+
1116
+ HexEntity = /&#x/i < /[0-9a-fA-F]+/ > ";"
1117
+ { [text.to_i(16)].pack 'U' }
1118
+ DecEntity = "&#" < /[0-9]+/ > ";"
1119
+ { [text.to_i].pack 'U' }
1120
+ CharEntity = "&" </[A-Za-z0-9]+/ > ";"
1121
+ { if entity = HTML_ENTITIES[text] then
1122
+ entity.pack 'U*'
1123
+ else
1124
+ "&#{text};"
1125
+ end
1126
+ }
1127
+
1128
+ NonindentSpace = / {0,3}/
1129
+ Indent = /\t| /
1130
+ IndentedLine = Indent Line
1131
+ OptionallyIndentedLine = Indent? Line
1132
+
1133
+ # StartList starts a list data structure that can be added to with cons:
1134
+ StartList = &.
1135
+ { [] }
1136
+
1137
+ Line = @RawLine:a { a }
1138
+ RawLine = ( < (!"\r" !"\n" .)* @Newline >
1139
+ | < .+ > @Eof ) { text }
1140
+
1141
+ SkipBlock = HtmlBlock
1142
+ | ( !"#" !SetextBottom1 !SetextBottom2 !@BlankLine @RawLine )+
1143
+ @BlankLine*
1144
+ | @BlankLine+
1145
+ | @RawLine
1146
+
1147
+ # Syntax extensions
1148
+
1149
+ ExtendedSpecialChar = &{ notes? } ( "^" )
1150
+
1151
+ NoteReference = &{ notes? }
1152
+ RawNoteReference:ref
1153
+ { note_for ref }
1154
+
1155
+ RawNoteReference = "[^" < ( !@Newline !"]" . )+ > "]" { text }
1156
+
1157
+ # TODO multiple paragraphs for a footnote
1158
+ Note = &{ notes? }
1159
+ @NonindentSpace RawNoteReference:ref ":" @Sp
1160
+ @StartList:a
1161
+ RawNoteBlock:i { a.concat i }
1162
+ ( &Indent RawNoteBlock:i { a.concat i } )*
1163
+ { @footnotes[ref] = paragraph a
1164
+
1165
+ nil
1166
+ }
1167
+
1168
+ InlineNote = &{ notes? }
1169
+ "^["
1170
+ @StartList:a
1171
+ ( !"]" Inline:l { a << l } )+
1172
+ "]"
1173
+ { ref = [:inline, @note_order.length]
1174
+ @footnotes[ref] = paragraph a
1175
+
1176
+ note_for ref
1177
+ }
1178
+
1179
+ Notes = ( Note | SkipBlock )*
1180
+
1181
+ RawNoteBlock = @StartList:a
1182
+ ( !@BlankLine OptionallyIndentedLine:l { a << l } )+
1183
+ ( < @BlankLine* > { a << text } )
1184
+ { a }
1185
+
1186
+ # Markdown extensions added by RDoc follow
1187
+
1188
+ CodeFence = &{ github? }
1189
+ Ticks3 (@Sp StrChunk:format)? Spnl < (
1190
+ ( !"`" Nonspacechar )+ |
1191
+ !Ticks3 /`+/ |
1192
+ Spacechar |
1193
+ @Newline
1194
+ )+ > Ticks3 @Sp @Newline*
1195
+ { verbatim = RDoc::Markup::Verbatim.new text
1196
+ verbatim.format = format.intern if format.instance_of?(String)
1197
+ verbatim
1198
+ }
1199
+
1200
+ Table = &{ github? }
1201
+ TableRow:header TableLine:line TableRow+:body
1202
+ { table = RDoc::Markup::Table.new(header, line, body) }
1203
+
1204
+ TableRow = TableItem+:row "|" @Newline
1205
+ { row }
1206
+ TableItem = "|" < (!"|" !@Newline .)+ >
1207
+ { text.strip }
1208
+
1209
+ TableLine = TableColumn+:line "|" @Newline
1210
+ { line }
1211
+ TableColumn = "|" < ( "-"+ ":"? | ":" "-"* ) >
1212
+ { text.start_with?(":") ? :left :
1213
+ text.end_with?(":") ? :right : nil
1214
+ }
1215
+
1216
+ DefinitionList = &{ definition_lists? }
1217
+ ( DefinitionListItem+:list )
1218
+ { RDoc::Markup::List.new :NOTE, *list.flatten }
1219
+
1220
+ DefinitionListItem = ( DefinitionListLabel+ ):label
1221
+ ( DefinitionListDefinition+ ):defns
1222
+ { list_items = []
1223
+ list_items <<
1224
+ RDoc::Markup::ListItem.new(label, defns.shift)
1225
+
1226
+ list_items.concat defns.map { |defn|
1227
+ RDoc::Markup::ListItem.new nil, defn
1228
+ } unless list_items.empty?
1229
+
1230
+ list_items
1231
+ }
1232
+
1233
+ DefinitionListLabel = StrChunk:label @Sp @Newline
1234
+ { label }
1235
+
1236
+ DefinitionListDefinition = @NonindentSpace ":" @Space Inlines:a @BlankLine+
1237
+ { paragraph a }