rdoc 4.2.1 → 6.3.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rdoc might be problematic. Click here for more details.

Files changed (277) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.rdoc +8 -7
  3. data/Gemfile +12 -0
  4. data/History.rdoc +48 -4
  5. data/LEGAL.rdoc +2 -2
  6. data/README.rdoc +5 -5
  7. data/Rakefile +73 -155
  8. data/bin/console +7 -0
  9. data/bin/setup +6 -0
  10. data/{bin → exe}/rdoc +0 -0
  11. data/{bin → exe}/ri +0 -0
  12. data/lib/rdoc/alias.rb +1 -0
  13. data/lib/rdoc/anon_class.rb +1 -0
  14. data/lib/rdoc/any_method.rb +59 -14
  15. data/lib/rdoc/attr.rb +1 -0
  16. data/lib/rdoc/class_module.rb +5 -2
  17. data/lib/rdoc/code_object.rb +3 -11
  18. data/lib/rdoc/code_objects.rb +1 -0
  19. data/lib/rdoc/comment.rb +32 -11
  20. data/lib/rdoc/constant.rb +3 -2
  21. data/lib/rdoc/context/section.rb +7 -13
  22. data/lib/rdoc/context.rb +78 -23
  23. data/lib/rdoc/cross_reference.rb +33 -14
  24. data/lib/rdoc/encoding.rb +92 -55
  25. data/lib/rdoc/erb_partial.rb +2 -1
  26. data/lib/rdoc/erbio.rb +8 -3
  27. data/lib/rdoc/extend.rb +1 -0
  28. data/lib/rdoc/generator/darkfish.rb +62 -32
  29. data/lib/rdoc/generator/json_index.rb +8 -5
  30. data/lib/rdoc/generator/markup.rb +3 -12
  31. data/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  32. data/lib/rdoc/generator/pot/po.rb +84 -0
  33. data/lib/rdoc/generator/pot/po_entry.rb +141 -0
  34. data/lib/rdoc/generator/pot.rb +4 -3
  35. data/lib/rdoc/generator/ri.rb +1 -0
  36. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +2 -2
  37. data/lib/rdoc/generator/template/darkfish/_head.rhtml +11 -8
  38. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +2 -2
  39. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +2 -2
  40. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +7 -7
  41. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +2 -2
  42. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +7 -7
  43. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +6 -6
  44. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +5 -5
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +5 -5
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +5 -5
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +4 -4
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +4 -4
  49. data/lib/rdoc/generator/template/darkfish/class.rhtml +45 -47
  50. data/lib/rdoc/generator/template/darkfish/css/fonts.css +6 -6
  51. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +55 -6
  52. data/lib/rdoc/generator/template/darkfish/index.rhtml +3 -4
  53. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +23 -100
  54. data/lib/rdoc/generator/template/darkfish/js/search.js +32 -31
  55. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +15 -16
  56. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +16 -16
  57. data/lib/rdoc/generator/template/json_index/js/navigation.js +4 -41
  58. data/lib/rdoc/generator/template/json_index/js/searcher.js +7 -6
  59. data/lib/rdoc/generator.rb +1 -1
  60. data/lib/rdoc/ghost_method.rb +1 -0
  61. data/lib/rdoc/i18n/locale.rb +2 -1
  62. data/lib/rdoc/i18n/text.rb +5 -4
  63. data/lib/rdoc/i18n.rb +3 -2
  64. data/lib/rdoc/include.rb +1 -0
  65. data/lib/rdoc/known_classes.rb +1 -0
  66. data/lib/rdoc/markdown/entities.rb +1 -0
  67. data/lib/rdoc/markdown/{literals_1_9.kpeg → literals.kpeg} +1 -0
  68. data/lib/rdoc/markdown/{literals_1_9.rb → literals.rb} +1 -4
  69. data/lib/rdoc/markdown.kpeg +94 -51
  70. data/lib/rdoc/markdown.rb +1171 -619
  71. data/lib/rdoc/markup/attr_changer.rb +1 -0
  72. data/lib/rdoc/markup/attr_span.rb +9 -2
  73. data/lib/rdoc/markup/attribute_manager.rb +115 -49
  74. data/lib/rdoc/markup/attributes.rb +7 -6
  75. data/lib/rdoc/markup/blank_line.rb +1 -0
  76. data/lib/rdoc/markup/block_quote.rb +1 -0
  77. data/lib/rdoc/markup/document.rb +1 -0
  78. data/lib/rdoc/markup/formatter.rb +25 -23
  79. data/lib/rdoc/markup/hard_break.rb +1 -0
  80. data/lib/rdoc/markup/heading.rb +4 -3
  81. data/lib/rdoc/markup/include.rb +1 -0
  82. data/lib/rdoc/markup/indented_paragraph.rb +1 -0
  83. data/lib/rdoc/markup/list.rb +1 -0
  84. data/lib/rdoc/markup/list_item.rb +1 -0
  85. data/lib/rdoc/markup/paragraph.rb +1 -0
  86. data/lib/rdoc/markup/parser.rb +78 -61
  87. data/lib/rdoc/markup/pre_process.rb +12 -9
  88. data/lib/rdoc/markup/raw.rb +1 -0
  89. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  90. data/lib/rdoc/markup/rule.rb +1 -0
  91. data/lib/rdoc/markup/to_ansi.rb +1 -0
  92. data/lib/rdoc/markup/to_bs.rb +4 -5
  93. data/lib/rdoc/markup/to_html.rb +71 -25
  94. data/lib/rdoc/markup/to_html_crossref.rb +41 -25
  95. data/lib/rdoc/markup/to_html_snippet.rb +10 -9
  96. data/lib/rdoc/markup/to_joined_paragraph.rb +7 -31
  97. data/lib/rdoc/markup/to_label.rb +10 -9
  98. data/lib/rdoc/markup/to_markdown.rb +9 -8
  99. data/lib/rdoc/markup/to_rdoc.rb +35 -6
  100. data/lib/rdoc/markup/to_table_of_contents.rb +2 -0
  101. data/lib/rdoc/markup/to_test.rb +1 -0
  102. data/lib/rdoc/markup/to_tt_only.rb +3 -2
  103. data/lib/rdoc/markup/verbatim.rb +1 -0
  104. data/lib/rdoc/markup.rb +14 -16
  105. data/lib/rdoc/meta_method.rb +1 -0
  106. data/lib/rdoc/method_attr.rb +2 -1
  107. data/lib/rdoc/mixin.rb +1 -0
  108. data/lib/rdoc/normal_class.rb +3 -2
  109. data/lib/rdoc/normal_module.rb +1 -0
  110. data/lib/rdoc/options.rb +92 -58
  111. data/lib/rdoc/parser/c.rb +219 -223
  112. data/lib/rdoc/parser/changelog.rb +155 -18
  113. data/lib/rdoc/parser/markdown.rb +1 -0
  114. data/lib/rdoc/parser/rd.rb +1 -0
  115. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  116. data/lib/rdoc/parser/ruby.rb +635 -468
  117. data/lib/rdoc/parser/ruby_tools.rb +33 -33
  118. data/lib/rdoc/parser/simple.rb +3 -3
  119. data/lib/rdoc/parser/text.rb +1 -0
  120. data/lib/rdoc/parser.rb +17 -50
  121. data/lib/rdoc/rd/block_parser.rb +66 -65
  122. data/lib/rdoc/rd/block_parser.ry +3 -3
  123. data/lib/rdoc/rd/inline.rb +5 -4
  124. data/lib/rdoc/rd/inline_parser.rb +52 -51
  125. data/lib/rdoc/rd/inline_parser.ry +1 -1
  126. data/lib/rdoc/rd.rb +1 -0
  127. data/lib/rdoc/rdoc.rb +68 -63
  128. data/lib/rdoc/require.rb +1 -0
  129. data/lib/rdoc/ri/driver.rb +133 -58
  130. data/lib/rdoc/ri/formatter.rb +1 -0
  131. data/lib/rdoc/ri/paths.rb +4 -20
  132. data/lib/rdoc/ri/store.rb +1 -0
  133. data/lib/rdoc/ri/task.rb +71 -0
  134. data/lib/rdoc/ri.rb +1 -0
  135. data/lib/rdoc/rubygems_hook.rb +5 -12
  136. data/lib/rdoc/servlet.rb +24 -14
  137. data/lib/rdoc/single_class.rb +1 -0
  138. data/lib/rdoc/stats/normal.rb +20 -21
  139. data/lib/rdoc/stats/quiet.rb +1 -0
  140. data/lib/rdoc/stats/verbose.rb +1 -0
  141. data/lib/rdoc/stats.rb +1 -0
  142. data/lib/rdoc/store.rb +41 -41
  143. data/lib/rdoc/task.rb +2 -3
  144. data/lib/rdoc/text.rb +19 -38
  145. data/lib/rdoc/token_stream.rb +56 -32
  146. data/lib/rdoc/tom_doc.rb +17 -11
  147. data/lib/rdoc/top_level.rb +9 -2
  148. data/lib/rdoc/version.rb +8 -0
  149. data/lib/rdoc.rb +24 -10
  150. data/man/ri.1 +247 -0
  151. data/rdoc.gemspec +248 -0
  152. metadata +43 -236
  153. data/.autotest +0 -24
  154. data/.document +0 -5
  155. data/Manifest.txt +0 -306
  156. data/lib/gauntlet_rdoc.rb +0 -84
  157. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -4
  158. data/lib/rdoc/markdown/literals_1_8.kpeg +0 -18
  159. data/lib/rdoc/markdown/literals_1_8.rb +0 -416
  160. data/lib/rdoc/markup/formatter_test_case.rb +0 -767
  161. data/lib/rdoc/markup/inline.rb +0 -1
  162. data/lib/rdoc/markup/special.rb +0 -40
  163. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -114
  164. data/lib/rdoc/ruby_lex.rb +0 -1377
  165. data/lib/rdoc/ruby_token.rb +0 -460
  166. data/lib/rdoc/test_case.rb +0 -217
  167. data/test/MarkdownTest_1.0.3/Amps and angle encoding.text +0 -21
  168. data/test/MarkdownTest_1.0.3/Auto links.text +0 -13
  169. data/test/MarkdownTest_1.0.3/Backslash escapes.text +0 -120
  170. data/test/MarkdownTest_1.0.3/Blockquotes with code blocks.text +0 -11
  171. data/test/MarkdownTest_1.0.3/Code Blocks.text +0 -14
  172. data/test/MarkdownTest_1.0.3/Code Spans.text +0 -6
  173. data/test/MarkdownTest_1.0.3/Hard-wrapped paragraphs with list-like lines.text +0 -8
  174. data/test/MarkdownTest_1.0.3/Horizontal rules.text +0 -67
  175. data/test/MarkdownTest_1.0.3/Inline HTML (Advanced).text +0 -15
  176. data/test/MarkdownTest_1.0.3/Inline HTML (Simple).text +0 -69
  177. data/test/MarkdownTest_1.0.3/Inline HTML comments.text +0 -13
  178. data/test/MarkdownTest_1.0.3/Links, inline style.text +0 -12
  179. data/test/MarkdownTest_1.0.3/Links, reference style.text +0 -71
  180. data/test/MarkdownTest_1.0.3/Links, shortcut references.text +0 -20
  181. data/test/MarkdownTest_1.0.3/Literal quotes in titles.text +0 -7
  182. data/test/MarkdownTest_1.0.3/Markdown Documentation - Basics.text +0 -306
  183. data/test/MarkdownTest_1.0.3/Markdown Documentation - Syntax.text +0 -888
  184. data/test/MarkdownTest_1.0.3/Nested blockquotes.text +0 -5
  185. data/test/MarkdownTest_1.0.3/Ordered and unordered lists.text +0 -131
  186. data/test/MarkdownTest_1.0.3/Strong and em together.text +0 -7
  187. data/test/MarkdownTest_1.0.3/Tabs.text +0 -21
  188. data/test/MarkdownTest_1.0.3/Tidyness.text +0 -5
  189. data/test/README +0 -1
  190. data/test/binary.dat +0 -0
  191. data/test/hidden.zip.txt +0 -1
  192. data/test/test.ja.largedoc +0 -3
  193. data/test/test.ja.rdoc +0 -10
  194. data/test/test.ja.txt +0 -8
  195. data/test/test.txt +0 -1
  196. data/test/test_rdoc_alias.rb +0 -13
  197. data/test/test_rdoc_any_method.rb +0 -460
  198. data/test/test_rdoc_attr.rb +0 -190
  199. data/test/test_rdoc_class_module.rb +0 -1492
  200. data/test/test_rdoc_code_object.rb +0 -450
  201. data/test/test_rdoc_comment.rb +0 -504
  202. data/test/test_rdoc_constant.rb +0 -181
  203. data/test/test_rdoc_context.rb +0 -901
  204. data/test/test_rdoc_context_section.rb +0 -130
  205. data/test/test_rdoc_cross_reference.rb +0 -192
  206. data/test/test_rdoc_encoding.rb +0 -227
  207. data/test/test_rdoc_extend.rb +0 -94
  208. data/test/test_rdoc_generator_darkfish.rb +0 -229
  209. data/test/test_rdoc_generator_json_index.rb +0 -324
  210. data/test/test_rdoc_generator_markup.rb +0 -59
  211. data/test/test_rdoc_generator_pot.rb +0 -91
  212. data/test/test_rdoc_generator_pot_po.rb +0 -51
  213. data/test/test_rdoc_generator_pot_po_entry.rb +0 -139
  214. data/test/test_rdoc_generator_ri.rb +0 -78
  215. data/test/test_rdoc_i18n_locale.rb +0 -73
  216. data/test/test_rdoc_i18n_text.rb +0 -123
  217. data/test/test_rdoc_include.rb +0 -108
  218. data/test/test_rdoc_markdown.rb +0 -980
  219. data/test/test_rdoc_markdown_test.rb +0 -1884
  220. data/test/test_rdoc_markup.rb +0 -95
  221. data/test/test_rdoc_markup_attribute_manager.rb +0 -364
  222. data/test/test_rdoc_markup_attributes.rb +0 -39
  223. data/test/test_rdoc_markup_document.rb +0 -207
  224. data/test/test_rdoc_markup_formatter.rb +0 -175
  225. data/test/test_rdoc_markup_hard_break.rb +0 -31
  226. data/test/test_rdoc_markup_heading.rb +0 -29
  227. data/test/test_rdoc_markup_include.rb +0 -19
  228. data/test/test_rdoc_markup_indented_paragraph.rb +0 -53
  229. data/test/test_rdoc_markup_paragraph.rb +0 -32
  230. data/test/test_rdoc_markup_parser.rb +0 -1680
  231. data/test/test_rdoc_markup_pre_process.rb +0 -473
  232. data/test/test_rdoc_markup_raw.rb +0 -22
  233. data/test/test_rdoc_markup_to_ansi.rb +0 -369
  234. data/test/test_rdoc_markup_to_bs.rb +0 -366
  235. data/test/test_rdoc_markup_to_html.rb +0 -662
  236. data/test/test_rdoc_markup_to_html_crossref.rb +0 -225
  237. data/test/test_rdoc_markup_to_html_snippet.rb +0 -711
  238. data/test/test_rdoc_markup_to_joined_paragraph.rb +0 -32
  239. data/test/test_rdoc_markup_to_label.rb +0 -112
  240. data/test/test_rdoc_markup_to_markdown.rb +0 -389
  241. data/test/test_rdoc_markup_to_rdoc.rb +0 -377
  242. data/test/test_rdoc_markup_to_table_of_contents.rb +0 -126
  243. data/test/test_rdoc_markup_to_tt_only.rb +0 -246
  244. data/test/test_rdoc_markup_verbatim.rb +0 -29
  245. data/test/test_rdoc_method_attr.rb +0 -193
  246. data/test/test_rdoc_normal_class.rb +0 -47
  247. data/test/test_rdoc_normal_module.rb +0 -42
  248. data/test/test_rdoc_options.rb +0 -766
  249. data/test/test_rdoc_parser.rb +0 -327
  250. data/test/test_rdoc_parser_c.rb +0 -1896
  251. data/test/test_rdoc_parser_changelog.rb +0 -315
  252. data/test/test_rdoc_parser_markdown.rb +0 -61
  253. data/test/test_rdoc_parser_rd.rb +0 -55
  254. data/test/test_rdoc_parser_ruby.rb +0 -3322
  255. data/test/test_rdoc_parser_simple.rb +0 -115
  256. data/test/test_rdoc_rd.rb +0 -30
  257. data/test/test_rdoc_rd_block_parser.rb +0 -535
  258. data/test/test_rdoc_rd_inline.rb +0 -63
  259. data/test/test_rdoc_rd_inline_parser.rb +0 -177
  260. data/test/test_rdoc_rdoc.rb +0 -455
  261. data/test/test_rdoc_require.rb +0 -25
  262. data/test/test_rdoc_ri_driver.rb +0 -1436
  263. data/test/test_rdoc_ri_paths.rb +0 -155
  264. data/test/test_rdoc_ruby_lex.rb +0 -421
  265. data/test/test_rdoc_ruby_token.rb +0 -19
  266. data/test/test_rdoc_rubygems_hook.rb +0 -251
  267. data/test/test_rdoc_servlet.rb +0 -534
  268. data/test/test_rdoc_single_class.rb +0 -20
  269. data/test/test_rdoc_stats.rb +0 -722
  270. data/test/test_rdoc_store.rb +0 -993
  271. data/test/test_rdoc_task.rb +0 -173
  272. data/test/test_rdoc_text.rb +0 -557
  273. data/test/test_rdoc_token_stream.rb +0 -42
  274. data/test/test_rdoc_tom_doc.rb +0 -520
  275. data/test/test_rdoc_top_level.rb +0 -287
  276. data/test/xref_data.rb +0 -76
  277. data/test/xref_test_case.rb +0 -67
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'strscan'
2
3
 
3
4
  ##
@@ -8,8 +9,9 @@ require 'strscan'
8
9
  # RDoc::Markup::ToHTML.
9
10
  #
10
11
  # The parser only handles the block-level constructs Paragraph, List,
11
- # ListItem, Heading, Verbatim, BlankLine and Rule. Inline markup such as
12
- # <tt>\+blah\+</tt> is handled separately by RDoc::Markup::AttributeManager.
12
+ # ListItem, Heading, Verbatim, BlankLine, Rule and BlockQuote.
13
+ # Inline markup such as <tt>\+blah\+</tt> is handled separately by
14
+ # RDoc::Markup::AttributeManager.
13
15
  #
14
16
  # To see what markup the Parser implements read RDoc. To see how to use
15
17
  # RDoc markup to format text in your program read RDoc::Markup.
@@ -78,12 +80,6 @@ class RDoc::Markup::Parser
78
80
  @binary_input = nil
79
81
  @current_token = nil
80
82
  @debug = false
81
- @have_encoding = Object.const_defined? :Encoding
82
- @have_byteslice = ''.respond_to? :byteslice
83
- @input = nil
84
- @input_encoding = nil
85
- @line = 0
86
- @line_pos = 0
87
83
  @s = nil
88
84
  @tokens = []
89
85
  end
@@ -250,7 +246,7 @@ class RDoc::Markup::Parser
250
246
 
251
247
  min_indent = nil
252
248
  generate_leading_spaces = true
253
- line = ''
249
+ line = ''.dup
254
250
 
255
251
  until @tokens.empty? do
256
252
  type, data, column, = get
@@ -258,7 +254,7 @@ class RDoc::Markup::Parser
258
254
  if type == :NEWLINE then
259
255
  line << data
260
256
  verbatim << line
261
- line = ''
257
+ line = ''.dup
262
258
  generate_leading_spaces = true
263
259
  next
264
260
  end
@@ -319,21 +315,6 @@ class RDoc::Markup::Parser
319
315
  verbatim
320
316
  end
321
317
 
322
- ##
323
- # The character offset for the input string at the given +byte_offset+
324
-
325
- def char_pos byte_offset
326
- if @have_byteslice then
327
- @input.byteslice(0, byte_offset).length
328
- elsif @have_encoding then
329
- matched = @binary_input[0, byte_offset]
330
- matched.force_encoding @input_encoding
331
- matched.length
332
- else
333
- byte_offset
334
- end
335
- end
336
-
337
318
  ##
338
319
  # Pulls the next token from the stream.
339
320
 
@@ -390,6 +371,17 @@ class RDoc::Markup::Parser
390
371
  when :TEXT then
391
372
  unget
392
373
  parse_text parent, indent
374
+ when :BLOCKQUOTE then
375
+ type, _, column = get
376
+ if type == :NEWLINE
377
+ type, _, column = get
378
+ end
379
+ unget if type
380
+ bq = RDoc::Markup::BlockQuote.new
381
+ p :blockquote_start => [data, column] if @debug
382
+ parse bq, column
383
+ p :blockquote_end => indent if @debug
384
+ parent << bq
393
385
  when *LIST_TOKENS then
394
386
  unget
395
387
  parent << build_list(indent)
@@ -422,19 +414,52 @@ class RDoc::Markup::Parser
422
414
  end
423
415
 
424
416
  ##
425
- # Creates the StringScanner
417
+ # A simple wrapper of StringScanner that is aware of the current column and lineno
426
418
 
427
- def setup_scanner input
428
- @line = 0
429
- @line_pos = 0
430
- @input = input.dup
419
+ class MyStringScanner
420
+ def initialize(input)
421
+ @line = @column = 0
422
+ @s = StringScanner.new input
423
+ end
424
+
425
+ def scan(re)
426
+ ret = @s.scan(re)
427
+ @column += ret.length if ret
428
+ ret
429
+ end
430
+
431
+ def unscan(s)
432
+ @s.pos -= s.bytesize
433
+ @column -= s.length
434
+ end
435
+
436
+ def pos
437
+ [@column, @line]
438
+ end
439
+
440
+ def newline!
441
+ @column = 0
442
+ @line += 1
443
+ end
431
444
 
432
- if @have_encoding and not @have_byteslice then
433
- @input_encoding = @input.encoding
434
- @binary_input = @input.force_encoding Encoding::BINARY
445
+ def eos?
446
+ @s.eos?
435
447
  end
436
448
 
437
- @s = StringScanner.new input
449
+ def matched
450
+ @s.matched
451
+ end
452
+
453
+ def [](i)
454
+ @s[i]
455
+ end
456
+ end
457
+
458
+ ##
459
+ # Creates the StringScanner
460
+
461
+ def setup_scanner input
462
+ @s = MyStringScanner.new input
438
463
  end
439
464
 
440
465
  ##
@@ -469,31 +494,30 @@ class RDoc::Markup::Parser
469
494
  @tokens << case
470
495
  # [CR]LF => :NEWLINE
471
496
  when @s.scan(/\r?\n/) then
472
- token = [:NEWLINE, @s.matched, *token_pos(pos)]
473
- @line_pos = char_pos @s.pos
474
- @line += 1
497
+ token = [:NEWLINE, @s.matched, *pos]
498
+ @s.newline!
475
499
  token
476
500
  # === text => :HEADER then :TEXT
477
501
  when @s.scan(/(=+)(\s*)/) then
478
502
  level = @s[1].length
479
- header = [:HEADER, level, *token_pos(pos)]
503
+ header = [:HEADER, level, *pos]
480
504
 
481
505
  if @s[2] =~ /^\r?\n/ then
482
- @s.pos -= @s[2].length
506
+ @s.unscan(@s[2])
483
507
  header
484
508
  else
485
509
  pos = @s.pos
486
510
  @s.scan(/.*/)
487
511
  @tokens << header
488
- [:TEXT, @s.matched.sub(/\r$/, ''), *token_pos(pos)]
512
+ [:TEXT, @s.matched.sub(/\r$/, ''), *pos]
489
513
  end
490
514
  # --- (at least 3) and nothing else on the line => :RULE
491
515
  when @s.scan(/(-{3,}) *\r?$/) then
492
- [:RULE, @s[1].length - 2, *token_pos(pos)]
516
+ [:RULE, @s[1].length - 2, *pos]
493
517
  # * or - followed by white space and text => :BULLET
494
518
  when @s.scan(/([*-]) +(\S)/) then
495
- @s.pos -= @s[2].bytesize # unget \S
496
- [:BULLET, @s[1], *token_pos(pos)]
519
+ @s.unscan(@s[2])
520
+ [:BULLET, @s[1], *pos]
497
521
  # A. text, a. text, 12. text => :UALPHA, :LALPHA, :NUMBER
498
522
  when @s.scan(/([a-z]|\d+)\. +(\S)/i) then
499
523
  # FIXME if tab(s), the column will be wrong
@@ -502,7 +526,7 @@ class RDoc::Markup::Parser
502
526
  # before (and provide a check for that at least in debug
503
527
  # mode)
504
528
  list_label = @s[1]
505
- @s.pos -= @s[2].bytesize # unget \S
529
+ @s.unscan(@s[2])
506
530
  list_type =
507
531
  case list_label
508
532
  when /[a-z]/ then :LALPHA
@@ -511,20 +535,24 @@ class RDoc::Markup::Parser
511
535
  else
512
536
  raise ParseError, "BUG token #{list_label}"
513
537
  end
514
- [list_type, list_label, *token_pos(pos)]
538
+ [list_type, list_label, *pos]
515
539
  # [text] followed by spaces or end of line => :LABEL
516
540
  when @s.scan(/\[(.*?)\]( +|\r?$)/) then
517
- [:LABEL, @s[1], *token_pos(pos)]
541
+ [:LABEL, @s[1], *pos]
518
542
  # text:: followed by spaces or end of line => :NOTE
519
543
  when @s.scan(/(.*?)::( +|\r?$)/) then
520
- [:NOTE, @s[1], *token_pos(pos)]
544
+ [:NOTE, @s[1], *pos]
545
+ # >>> followed by end of line => :BLOCKQUOTE
546
+ when @s.scan(/>>> *(\w+)?$/) then
547
+ [:BLOCKQUOTE, @s[1], *pos]
521
548
  # anything else: :TEXT
522
- else @s.scan(/(.*?)( )?\r?$/)
523
- token = [:TEXT, @s[1], *token_pos(pos)]
549
+ else
550
+ @s.scan(/(.*?)( )?\r?$/)
551
+ token = [:TEXT, @s[1], *pos]
524
552
 
525
553
  if @s[2] then
526
554
  @tokens << token
527
- [:BREAK, @s[2], *token_pos(pos + @s[1].length)]
555
+ [:BREAK, @s[2], pos[0] + @s[1].length, pos[1]]
528
556
  else
529
557
  token
530
558
  end
@@ -534,16 +562,6 @@ class RDoc::Markup::Parser
534
562
  self
535
563
  end
536
564
 
537
- ##
538
- # Calculates the column (by character) and line of the current token based
539
- # on +byte_offset+.
540
-
541
- def token_pos byte_offset
542
- offset = char_pos byte_offset
543
-
544
- [offset - @line_pos, @line]
545
- end
546
-
547
565
  ##
548
566
  # Returns the current token to the token stream
549
567
 
@@ -555,4 +573,3 @@ class RDoc::Markup::Parser
555
573
  end
556
574
 
557
575
  end
558
-
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ##
2
3
  # Handle common directives that can occur in a block of text:
3
4
  #
@@ -101,12 +102,10 @@ class RDoc::Markup::PreProcess
101
102
  text = text.text
102
103
  end
103
104
 
104
- encoding = text.encoding if defined?(Encoding)
105
-
106
105
  # regexp helper (square brackets for optional)
107
106
  # $1 $2 $3 $4 $5
108
107
  # [prefix][\]:directive:[spaces][param]newline
109
- text.gsub!(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?(\r?\n|$)/) do
108
+ text = text.gsub(/^([ \t]*(?:#|\/?\*)?[ \t]*)(\\?):(\w+):([ \t]*)(.+)?(\r?\n|$)/) do
110
109
  # skip something like ':toto::'
111
110
  next $& if $4.empty? and $5 and $5[0, 1] == ':'
112
111
 
@@ -121,10 +120,14 @@ class RDoc::Markup::PreProcess
121
120
  next "#{$1.strip}\n"
122
121
  end
123
122
 
124
- handle_directive $1, $3, $5, code_object, encoding, &block
123
+ handle_directive $1, $3, $5, code_object, text.encoding, &block
125
124
  end
126
125
 
127
- comment = text unless comment
126
+ if comment then
127
+ comment.text = text
128
+ else
129
+ comment = text
130
+ end
128
131
 
129
132
  self.class.post_processors.each do |handler|
130
133
  handler.call comment, code_object
@@ -151,7 +154,7 @@ class RDoc::Markup::PreProcess
151
154
 
152
155
  case directive
153
156
  when 'arg', 'args' then
154
- return "#{prefix}:#{directive}: #{param}\n" unless code_object
157
+ return "#{prefix}:#{directive}: #{param}\n" unless code_object && code_object.kind_of?(RDoc::AnyMethod)
155
158
 
156
159
  code_object.params = param
157
160
 
@@ -175,7 +178,7 @@ class RDoc::Markup::PreProcess
175
178
 
176
179
  blankline
177
180
  when 'include' then
178
- filename = param.split.first
181
+ filename = param.split(' ', 2).first
179
182
  include_file filename, prefix, encoding
180
183
  when 'main' then
181
184
  @options.main_page = param if @options.respond_to? :main_page
@@ -213,7 +216,7 @@ class RDoc::Markup::PreProcess
213
216
  when 'yield', 'yields' then
214
217
  return blankline unless code_object
215
218
  # remove parameter &block
216
- code_object.params.sub!(/,?\s*&\w+/, '') if code_object.params
219
+ code_object.params = code_object.params.sub(/,?\s*&\w+/, '') if code_object.params
217
220
 
218
221
  code_object.block_params = param
219
222
 
@@ -263,6 +266,7 @@ class RDoc::Markup::PreProcess
263
266
  end
264
267
 
265
268
  content = RDoc::Encoding.read_file full_name, encoding, true
269
+ content = RDoc::Encoding.remove_magic_comment content
266
270
 
267
271
  # strip magic comment
268
272
  content = content.sub(/\A# .*coding[=:].*$/, '').lstrip
@@ -290,4 +294,3 @@ class RDoc::Markup::PreProcess
290
294
  end
291
295
 
292
296
  end
293
-
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ##
2
3
  # A section of text that is added to the output document as-is
3
4
 
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # Hold details of a regexp handling sequence
4
+
5
+ class RDoc::Markup::RegexpHandling
6
+
7
+ ##
8
+ # Regexp handling type
9
+
10
+ attr_reader :type
11
+
12
+ ##
13
+ # Regexp handling text
14
+
15
+ attr_accessor :text
16
+
17
+ ##
18
+ # Creates a new regexp handling sequence of +type+ with +text+
19
+
20
+ def initialize(type, text)
21
+ @type, @text = type, text
22
+ end
23
+
24
+ ##
25
+ # Regexp handlings are equal when the have the same text and type
26
+
27
+ def ==(o)
28
+ self.text == o.text && self.type == o.type
29
+ end
30
+
31
+ def inspect # :nodoc:
32
+ "#<RDoc::Markup::RegexpHandling:0x%x @type=%p, @text=%p>" % [
33
+ object_id, @type, text.dump]
34
+ end
35
+
36
+ def to_s # :nodoc:
37
+ "RegexpHandling: type=#{type} text=#{text.dump}"
38
+ end
39
+
40
+ end
41
+
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ##
2
3
  # A horizontal rule with a weight
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ##
2
3
  # Outputs RDoc markup with vibrant ANSI color!
3
4
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ##
2
3
  # Outputs RDoc markup with hot backspace action! You will probably need a
3
4
  # pager to use this output format.
@@ -40,7 +41,7 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
40
41
  end
41
42
 
42
43
  ##
43
- # Turns on or off special handling for +convert_string+
44
+ # Turns on or off regexp handling for +convert_string+
44
45
 
45
46
  def annotate tag
46
47
  case tag
@@ -53,9 +54,9 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
53
54
  end
54
55
 
55
56
  ##
56
- # Calls convert_string on the result of convert_special
57
+ # Calls convert_string on the result of convert_regexp_handling
57
58
 
58
- def convert_special special
59
+ def convert_regexp_handling target
59
60
  convert_string super
60
61
  end
61
62
 
@@ -63,7 +64,6 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
63
64
  # Adds bold or underline mixed with backspaces
64
65
 
65
66
  def convert_string string
66
- return string unless string.respond_to? :chars # your ruby is lame
67
67
  return string unless @in_b or @in_em
68
68
  chars = if @in_b then
69
69
  string.chars.map do |char| "#{char}\b#{char}" end
@@ -75,4 +75,3 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
75
75
  end
76
76
 
77
77
  end
78
-
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'cgi'
2
3
 
3
4
  ##
@@ -51,19 +52,32 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
51
52
  @th = nil
52
53
  @hard_break = "<br>\n"
53
54
 
54
- # external links
55
- @markup.add_special(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
56
- :HYPERLINK)
57
-
58
- add_special_RDOCLINK
59
- add_special_TIDYLINK
55
+ init_regexp_handlings
60
56
 
61
57
  init_tags
62
58
  end
63
59
 
64
- # :section: Special Handling
60
+ # :section: Regexp Handling
65
61
  #
66
- # These methods handle special markup added by RDoc::Markup#add_special.
62
+ # These methods are used by regexp handling markup added by RDoc::Markup#add_regexp_handling.
63
+
64
+ ##
65
+ # Adds regexp handlings.
66
+
67
+ def init_regexp_handlings
68
+ # external links
69
+ @markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/,
70
+ :HYPERLINK)
71
+ init_link_notation_regexp_handlings
72
+ end
73
+
74
+ ##
75
+ # Adds regexp handlings about link notations.
76
+
77
+ def init_link_notation_regexp_handlings
78
+ add_regexp_handling_RDOCLINK
79
+ add_regexp_handling_TIDYLINK
80
+ end
67
81
 
68
82
  def handle_RDOCLINK url # :nodoc:
69
83
  case url
@@ -90,14 +104,14 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
90
104
  end
91
105
 
92
106
  ##
93
- # +special+ is a <code><br></code>
107
+ # +target+ is a <code><br></code>
94
108
 
95
- def handle_special_HARD_BREAK special
109
+ def handle_regexp_HARD_BREAK target
96
110
  '<br>'
97
111
  end
98
112
 
99
113
  ##
100
- # +special+ is a potential link. The following schemes are handled:
114
+ # +target+ is a potential link. The following schemes are handled:
101
115
  #
102
116
  # <tt>mailto:</tt>::
103
117
  # Inserted as-is.
@@ -108,14 +122,14 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
108
122
  # <tt>link:</tt>::
109
123
  # Reference to a local file relative to the output directory.
110
124
 
111
- def handle_special_HYPERLINK(special)
112
- url = special.text
125
+ def handle_regexp_HYPERLINK(target)
126
+ url = target.text
113
127
 
114
128
  gen_url url, url
115
129
  end
116
130
 
117
131
  ##
118
- # +special+ is an rdoc-schemed link that will be converted into a hyperlink.
132
+ # +target+ is an rdoc-schemed link that will be converted into a hyperlink.
119
133
  #
120
134
  # For the +rdoc-ref+ scheme the named reference will be returned without
121
135
  # creating a link.
@@ -123,16 +137,16 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
123
137
  # For the +rdoc-label+ scheme the footnote and label prefixes are stripped
124
138
  # when creating a link. All other contents will be linked verbatim.
125
139
 
126
- def handle_special_RDOCLINK special
127
- handle_RDOCLINK special.text
140
+ def handle_regexp_RDOCLINK target
141
+ handle_RDOCLINK target.text
128
142
  end
129
143
 
130
144
  ##
131
- # This +special+ is a link where the label is different from the URL
145
+ # This +target+ is a link where the label is different from the URL
132
146
  # <tt>label[url]</tt> or <tt>{long label}[url]</tt>
133
147
 
134
- def handle_special_TIDYLINK(special)
135
- text = special.text
148
+ def handle_regexp_TIDYLINK(target)
149
+ text = target.text
136
150
 
137
151
  return text unless
138
152
  text =~ /^\{(.*)\}\[(.*?)\]$/ or text =~ /^(\S+)\[(.*?)\]$/
@@ -185,7 +199,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
185
199
  @res << "\n<p>"
186
200
  text = paragraph.text @hard_break
187
201
  text = text.gsub(/\r?\n/, ' ')
188
- @res << wrap(to_html(text))
202
+ @res << to_html(text)
189
203
  @res << "</p>\n"
190
204
  end
191
205
 
@@ -199,11 +213,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
199
213
 
200
214
  content = if verbatim.ruby? or parseable? text then
201
215
  begin
202
- tokens = RDoc::RubyLex.tokenize text, @options
216
+ tokens = RDoc::Parser::RipperStateLex.parse text
203
217
  klass = ' class="ruby"'
204
218
 
205
- RDoc::TokenStream.to_html tokens
206
- rescue RDoc::RubyLex::Error
219
+ result = RDoc::TokenStream.to_html tokens
220
+ result = result + "\n" unless "\n" == result[-1]
221
+ result
222
+ rescue
207
223
  CGI.escapeHTML text
208
224
  end
209
225
  else
@@ -211,7 +227,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
211
227
  end
212
228
 
213
229
  if @options.pipe then
214
- @res << "\n<pre><code>#{CGI.escapeHTML text}</code></pre>\n"
230
+ @res << "\n<pre><code>#{CGI.escapeHTML text}\n</code></pre>\n"
215
231
  else
216
232
  @res << "\n<pre#{klass}>#{content}</pre>\n"
217
233
  end
@@ -298,6 +314,29 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
298
314
  @res << raw.parts.join("\n")
299
315
  end
300
316
 
317
+ ##
318
+ # Adds +table+ to the output
319
+
320
+ def accept_table header, body, aligns
321
+ @res << "\n<table role=\"table\">\n<thead>\n<tr>\n"
322
+ header.zip(aligns) do |text, align|
323
+ @res << '<th'
324
+ @res << ' align="' << align << '"' if align
325
+ @res << '>' << CGI.escapeHTML(text) << "</th>\n"
326
+ end
327
+ @res << "</tr>\n</thead>\n<tbody>\n"
328
+ body.each do |row|
329
+ @res << "<tr>\n"
330
+ row.zip(aligns) do |text, align|
331
+ @res << '<td'
332
+ @res << ' align="' << align << '"' if align
333
+ @res << '>' << CGI.escapeHTML(text) << "</td>\n"
334
+ end
335
+ @res << "</tr>\n"
336
+ end
337
+ @res << "</tbody>\n</table>\n"
338
+ end
339
+
301
340
  # :section: Utilities
302
341
 
303
342
  ##
@@ -309,7 +348,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
309
348
 
310
349
  ##
311
350
  # Generate a link to +url+ with content +text+. Handles the special cases
312
- # for img: and link: described under handle_special_HYPERLINK
351
+ # for img: and link: described under handle_regexp_HYPERLINK
313
352
 
314
353
  def gen_url url, text
315
354
  scheme, url, id = parse_url url
@@ -318,6 +357,10 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
318
357
  url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
319
358
  "<img src=\"#{url}\" />"
320
359
  else
360
+ if scheme != 'link' and /\.(?:rb|rdoc|md)\z/i =~ url
361
+ url = url.sub(%r%\A([./]*)(.*)\z%) { "#$1#{$2.tr('.', '_')}.html" }
362
+ end
363
+
321
364
  text = text.sub %r%^#{scheme}:/*%i, ''
322
365
  text = text.sub %r%^[*\^](\d+)$%, '\1'
323
366
 
@@ -382,9 +425,12 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
382
425
  # Returns true if text is valid ruby syntax
383
426
 
384
427
  def parseable? text
428
+ verbose, $VERBOSE = $VERBOSE, nil
385
429
  eval("BEGIN {return true}\n#{text}")
386
430
  rescue SyntaxError
387
431
  false
432
+ ensure
433
+ $VERBOSE = verbose
388
434
  end
389
435
 
390
436
  ##