mega-max-hub 0.0.1

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 (218) hide show
  1. checksums.yaml +7 -0
  2. data/mega-max-hub.gemspec +11 -0
  3. data/rdoc-8.0.0/CONTRIBUTING.md +195 -0
  4. data/rdoc-8.0.0/CVE-2013-0256.rdoc +49 -0
  5. data/rdoc-8.0.0/History.rdoc +1668 -0
  6. data/rdoc-8.0.0/LEGAL.rdoc +56 -0
  7. data/rdoc-8.0.0/LICENSE.rdoc +63 -0
  8. data/rdoc-8.0.0/README.md +236 -0
  9. data/rdoc-8.0.0/RI.md +842 -0
  10. data/rdoc-8.0.0/TODO.rdoc +60 -0
  11. data/rdoc-8.0.0/doc/markup_reference/markdown.md +659 -0
  12. data/rdoc-8.0.0/doc/markup_reference/rdoc.rdoc +1169 -0
  13. data/rdoc-8.0.0/exe/rdoc +43 -0
  14. data/rdoc-8.0.0/exe/ri +12 -0
  15. data/rdoc-8.0.0/lib/rdoc/code_object/alias.rb +98 -0
  16. data/rdoc-8.0.0/lib/rdoc/code_object/any_method.rb +387 -0
  17. data/rdoc-8.0.0/lib/rdoc/code_object/attr.rb +178 -0
  18. data/rdoc-8.0.0/lib/rdoc/code_object/class_module.rb +969 -0
  19. data/rdoc-8.0.0/lib/rdoc/code_object/constant.rb +221 -0
  20. data/rdoc-8.0.0/lib/rdoc/code_object/context/section.rb +182 -0
  21. data/rdoc-8.0.0/lib/rdoc/code_object/context.rb +1238 -0
  22. data/rdoc-8.0.0/lib/rdoc/code_object/extend.rb +9 -0
  23. data/rdoc-8.0.0/lib/rdoc/code_object/include.rb +9 -0
  24. data/rdoc-8.0.0/lib/rdoc/code_object/method_attr.rb +417 -0
  25. data/rdoc-8.0.0/lib/rdoc/code_object/mixin.rb +123 -0
  26. data/rdoc-8.0.0/lib/rdoc/code_object/normal_class.rb +92 -0
  27. data/rdoc-8.0.0/lib/rdoc/code_object/normal_module.rb +73 -0
  28. data/rdoc-8.0.0/lib/rdoc/code_object/require.rb +51 -0
  29. data/rdoc-8.0.0/lib/rdoc/code_object/single_class.rb +30 -0
  30. data/rdoc-8.0.0/lib/rdoc/code_object/top_level.rb +286 -0
  31. data/rdoc-8.0.0/lib/rdoc/code_object.rb +393 -0
  32. data/rdoc-8.0.0/lib/rdoc/code_objects.rb +5 -0
  33. data/rdoc-8.0.0/lib/rdoc/comment.rb +353 -0
  34. data/rdoc-8.0.0/lib/rdoc/cross_reference.rb +215 -0
  35. data/rdoc-8.0.0/lib/rdoc/encoding.rb +120 -0
  36. data/rdoc-8.0.0/lib/rdoc/erb_partial.rb +18 -0
  37. data/rdoc-8.0.0/lib/rdoc/erbio.rb +37 -0
  38. data/rdoc-8.0.0/lib/rdoc/generator/aliki.rb +200 -0
  39. data/rdoc-8.0.0/lib/rdoc/generator/darkfish.rb +824 -0
  40. data/rdoc-8.0.0/lib/rdoc/generator/json_index.rb +284 -0
  41. data/rdoc-8.0.0/lib/rdoc/generator/markup.rb +196 -0
  42. data/rdoc-8.0.0/lib/rdoc/generator/pot/message_extractor.rb +68 -0
  43. data/rdoc-8.0.0/lib/rdoc/generator/pot/po.rb +84 -0
  44. data/rdoc-8.0.0/lib/rdoc/generator/pot/po_entry.rb +141 -0
  45. data/rdoc-8.0.0/lib/rdoc/generator/pot.rb +94 -0
  46. data/rdoc-8.0.0/lib/rdoc/generator/ri.rb +30 -0
  47. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/DESIGN.md +536 -0
  48. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_aside_toc.rhtml +8 -0
  49. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_footer.rhtml +23 -0
  50. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_head.rhtml +163 -0
  51. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_header.rhtml +56 -0
  52. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_icons.rhtml +208 -0
  53. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_ancestors.rhtml +16 -0
  54. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_classes.rhtml +15 -0
  55. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_extends.rhtml +27 -0
  56. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_includes.rhtml +27 -0
  57. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_installed.rhtml +16 -0
  58. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_methods.rhtml +41 -0
  59. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_pages.rhtml +67 -0
  60. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_search.rhtml +15 -0
  61. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_sections.rhtml +21 -0
  62. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/_sidebar_toggle.rhtml +3 -0
  63. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/class.rhtml +230 -0
  64. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/css/rdoc.css +2181 -0
  65. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/index.rhtml +22 -0
  66. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/aliki.js +513 -0
  67. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
  68. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/c_highlighter.js +299 -0
  69. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/search_controller.js +129 -0
  70. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/search_navigation.js +105 -0
  71. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/search_ranker.js +239 -0
  72. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/js/theme-toggle.js +112 -0
  73. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/page.rhtml +18 -0
  74. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/servlet_not_found.rhtml +14 -0
  75. data/rdoc-8.0.0/lib/rdoc/generator/template/aliki/servlet_root.rhtml +65 -0
  76. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  77. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_head.rhtml +43 -0
  78. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +5 -0
  79. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +17 -0
  80. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +17 -0
  81. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +16 -0
  82. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +21 -0
  83. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  84. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +32 -0
  85. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +6 -0
  86. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +15 -0
  87. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  88. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +39 -0
  89. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml +3 -0
  90. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/class.rhtml +220 -0
  91. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  92. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/css/rdoc.css +701 -0
  93. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  94. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  95. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  96. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  97. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  98. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  99. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  100. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  101. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
  102. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
  103. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
  104. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
  105. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
  106. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
  107. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
  108. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  109. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
  110. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
  111. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
  112. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
  113. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
  114. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
  115. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
  116. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
  117. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
  118. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  119. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
  120. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  121. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
  122. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
  123. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
  124. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/index.rhtml +24 -0
  125. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/js/darkfish.js +140 -0
  126. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/js/search.js +120 -0
  127. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/page.rhtml +19 -0
  128. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +21 -0
  129. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +65 -0
  130. data/rdoc-8.0.0/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +72 -0
  131. data/rdoc-8.0.0/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  132. data/rdoc-8.0.0/lib/rdoc/generator/template/json_index/js/searcher.js +271 -0
  133. data/rdoc-8.0.0/lib/rdoc/generator.rb +52 -0
  134. data/rdoc-8.0.0/lib/rdoc/i18n/locale.rb +102 -0
  135. data/rdoc-8.0.0/lib/rdoc/i18n/text.rb +126 -0
  136. data/rdoc-8.0.0/lib/rdoc/i18n.rb +10 -0
  137. data/rdoc-8.0.0/lib/rdoc/known_classes.rb +74 -0
  138. data/rdoc-8.0.0/lib/rdoc/markdown/entities.rb +2131 -0
  139. data/rdoc-8.0.0/lib/rdoc/markdown/literals.kpeg +21 -0
  140. data/rdoc-8.0.0/lib/rdoc/markdown/literals.rb +454 -0
  141. data/rdoc-8.0.0/lib/rdoc/markdown.kpeg +1315 -0
  142. data/rdoc-8.0.0/lib/rdoc/markdown.rb +16865 -0
  143. data/rdoc-8.0.0/lib/rdoc/markup/blank_line.rb +29 -0
  144. data/rdoc-8.0.0/lib/rdoc/markup/block_quote.rb +14 -0
  145. data/rdoc-8.0.0/lib/rdoc/markup/document.rb +164 -0
  146. data/rdoc-8.0.0/lib/rdoc/markup/element.rb +21 -0
  147. data/rdoc-8.0.0/lib/rdoc/markup/formatter.rb +285 -0
  148. data/rdoc-8.0.0/lib/rdoc/markup/hard_break.rb +34 -0
  149. data/rdoc-8.0.0/lib/rdoc/markup/heading.rb +170 -0
  150. data/rdoc-8.0.0/lib/rdoc/markup/include.rb +42 -0
  151. data/rdoc-8.0.0/lib/rdoc/markup/indented_paragraph.rb +47 -0
  152. data/rdoc-8.0.0/lib/rdoc/markup/inline_parser.rb +312 -0
  153. data/rdoc-8.0.0/lib/rdoc/markup/list.rb +101 -0
  154. data/rdoc-8.0.0/lib/rdoc/markup/list_item.rb +99 -0
  155. data/rdoc-8.0.0/lib/rdoc/markup/paragraph.rb +28 -0
  156. data/rdoc-8.0.0/lib/rdoc/markup/parser.rb +585 -0
  157. data/rdoc-8.0.0/lib/rdoc/markup/pre_process.rb +317 -0
  158. data/rdoc-8.0.0/lib/rdoc/markup/raw.rb +66 -0
  159. data/rdoc-8.0.0/lib/rdoc/markup/rule.rb +20 -0
  160. data/rdoc-8.0.0/lib/rdoc/markup/table.rb +64 -0
  161. data/rdoc-8.0.0/lib/rdoc/markup/to_ansi.rb +144 -0
  162. data/rdoc-8.0.0/lib/rdoc/markup/to_bs.rb +86 -0
  163. data/rdoc-8.0.0/lib/rdoc/markup/to_html.rb +682 -0
  164. data/rdoc-8.0.0/lib/rdoc/markup/to_html_crossref.rb +261 -0
  165. data/rdoc-8.0.0/lib/rdoc/markup/to_html_snippet.rb +287 -0
  166. data/rdoc-8.0.0/lib/rdoc/markup/to_joined_paragraph.rb +41 -0
  167. data/rdoc-8.0.0/lib/rdoc/markup/to_label.rb +84 -0
  168. data/rdoc-8.0.0/lib/rdoc/markup/to_markdown.rb +215 -0
  169. data/rdoc-8.0.0/lib/rdoc/markup/to_rdoc.rb +421 -0
  170. data/rdoc-8.0.0/lib/rdoc/markup/to_table_of_contents.rb +88 -0
  171. data/rdoc-8.0.0/lib/rdoc/markup/to_test.rb +77 -0
  172. data/rdoc-8.0.0/lib/rdoc/markup/to_tt_only.rb +107 -0
  173. data/rdoc-8.0.0/lib/rdoc/markup/verbatim.rb +83 -0
  174. data/rdoc-8.0.0/lib/rdoc/markup.rb +219 -0
  175. data/rdoc-8.0.0/lib/rdoc/options.rb +1412 -0
  176. data/rdoc-8.0.0/lib/rdoc/parser/c.rb +1227 -0
  177. data/rdoc-8.0.0/lib/rdoc/parser/changelog.rb +379 -0
  178. data/rdoc-8.0.0/lib/rdoc/parser/markdown.rb +22 -0
  179. data/rdoc-8.0.0/lib/rdoc/parser/rbs.rb +275 -0
  180. data/rdoc-8.0.0/lib/rdoc/parser/rd.rb +22 -0
  181. data/rdoc-8.0.0/lib/rdoc/parser/ruby.rb +1266 -0
  182. data/rdoc-8.0.0/lib/rdoc/parser/ruby_colorizer.rb +253 -0
  183. data/rdoc-8.0.0/lib/rdoc/parser/simple.rb +44 -0
  184. data/rdoc-8.0.0/lib/rdoc/parser/text.rb +11 -0
  185. data/rdoc-8.0.0/lib/rdoc/parser.rb +298 -0
  186. data/rdoc-8.0.0/lib/rdoc/rbs_helper.rb +186 -0
  187. data/rdoc-8.0.0/lib/rdoc/rd/block_parser.rb +1706 -0
  188. data/rdoc-8.0.0/lib/rdoc/rd/block_parser.ry +643 -0
  189. data/rdoc-8.0.0/lib/rdoc/rd/inline.rb +71 -0
  190. data/rdoc-8.0.0/lib/rdoc/rd/inline_parser.rb +1854 -0
  191. data/rdoc-8.0.0/lib/rdoc/rd/inline_parser.ry +593 -0
  192. data/rdoc-8.0.0/lib/rdoc/rd.rb +99 -0
  193. data/rdoc-8.0.0/lib/rdoc/rdoc.rb +724 -0
  194. data/rdoc-8.0.0/lib/rdoc/ri/driver.rb +1572 -0
  195. data/rdoc-8.0.0/lib/rdoc/ri/formatter.rb +6 -0
  196. data/rdoc-8.0.0/lib/rdoc/ri/paths.rb +171 -0
  197. data/rdoc-8.0.0/lib/rdoc/ri/servlet.rb +452 -0
  198. data/rdoc-8.0.0/lib/rdoc/ri/store.rb +6 -0
  199. data/rdoc-8.0.0/lib/rdoc/ri/task.rb +71 -0
  200. data/rdoc-8.0.0/lib/rdoc/ri.rb +21 -0
  201. data/rdoc-8.0.0/lib/rdoc/rubygems_hook.rb +327 -0
  202. data/rdoc-8.0.0/lib/rdoc/server.rb +460 -0
  203. data/rdoc-8.0.0/lib/rdoc/stats/normal.rb +58 -0
  204. data/rdoc-8.0.0/lib/rdoc/stats/quiet.rb +59 -0
  205. data/rdoc-8.0.0/lib/rdoc/stats/verbose.rb +44 -0
  206. data/rdoc-8.0.0/lib/rdoc/stats.rb +484 -0
  207. data/rdoc-8.0.0/lib/rdoc/store.rb +1205 -0
  208. data/rdoc-8.0.0/lib/rdoc/task.rb +355 -0
  209. data/rdoc-8.0.0/lib/rdoc/text.rb +244 -0
  210. data/rdoc-8.0.0/lib/rdoc/token_stream.rb +104 -0
  211. data/rdoc-8.0.0/lib/rdoc/tom_doc.rb +257 -0
  212. data/rdoc-8.0.0/lib/rdoc/version.rb +10 -0
  213. data/rdoc-8.0.0/lib/rdoc.rb +239 -0
  214. data/rdoc-8.0.0/lib/rubygems_plugin.rb +14 -0
  215. data/rdoc-8.0.0/man/ri.1 +249 -0
  216. data/rdoc-8.0.0/rdoc-logo.svg +43 -0
  217. data/rdoc-8.0.0/rdoc.gemspec +74 -0
  218. metadata +256 -0
@@ -0,0 +1,682 @@
1
+ # frozen_string_literal: true
2
+ require 'cgi/escape'
3
+ require 'cgi/util' unless defined?(CGI::EscapeExt)
4
+ require 'prism'
5
+
6
+ ##
7
+ # Outputs RDoc markup as HTML.
8
+
9
+ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
10
+
11
+ include RDoc::Text
12
+
13
+ # :section: Utilities
14
+
15
+ ##
16
+ # Maps RDoc::Markup::Parser::LIST_TOKENS types to HTML tags
17
+
18
+ LIST_TYPE_TO_HTML = {
19
+ :BULLET => ['<ul>', '</ul>'],
20
+ :LABEL => ['<dl class="rdoc-list label-list">', '</dl>'],
21
+ :LALPHA => ['<ol style="list-style-type: lower-alpha">', '</ol>'],
22
+ :NOTE => ['<dl class="rdoc-list note-list">', '</dl>'],
23
+ :NUMBER => ['<ol>', '</ol>'],
24
+ :UALPHA => ['<ol style="list-style-type: upper-alpha">', '</ol>'],
25
+ }
26
+
27
+ attr_reader :res # :nodoc:
28
+ attr_reader :in_list_entry # :nodoc:
29
+ attr_reader :list # :nodoc:
30
+
31
+ ##
32
+ # The RDoc::CodeObject HTML is being generated for. This is used to
33
+ # generate namespaced URI fragments
34
+
35
+ attr_accessor :code_object
36
+
37
+ ##
38
+ # Path to this document for relative links
39
+
40
+ attr_accessor :from_path
41
+
42
+ # :section:
43
+
44
+ # Maps an encoding to a Hash of characters properly transcoded for that
45
+ # encoding.
46
+ #
47
+ # See also encode_fallback.
48
+
49
+ TO_HTML_CHARACTERS = Hash.new do |h, encoding|
50
+ h[encoding] = {
51
+ close_dquote: encode_fallback('”', encoding, '"'),
52
+ close_squote: encode_fallback('’', encoding, '\''),
53
+ copyright: encode_fallback('©', encoding, '(c)'),
54
+ ellipsis: encode_fallback('…', encoding, '...'),
55
+ dot_ellipsis: encode_fallback('.…', encoding, '....'),
56
+ em_dash: encode_fallback('—', encoding, '---'),
57
+ en_dash: encode_fallback('–', encoding, '--'),
58
+ open_dquote: encode_fallback('“', encoding, '"'),
59
+ open_squote: encode_fallback('‘', encoding, '\''),
60
+ trademark: encode_fallback('®', encoding, '(r)'),
61
+ }
62
+ end
63
+
64
+ HTML_CHARACTER_ALIASES = {
65
+ '(c)' => :copyright,
66
+ '(C)' => :copyright,
67
+ '(r)' => :trademark,
68
+ '(R)' => :trademark,
69
+ '---' => :em_dash,
70
+ '--' => :en_dash,
71
+ '....' => :dot_ellipsis,
72
+ '...' => :ellipsis,
73
+ '``' => :open_dquote,
74
+ "''" => :close_dquote,
75
+ }
76
+
77
+ # Transcodes +character+ to +encoding+ with a +fallback+ character.
78
+
79
+ def self.encode_fallback(character, encoding, fallback)
80
+ character.encode(
81
+ encoding,
82
+ fallback: { character => fallback },
83
+ undef: :replace,
84
+ replace: fallback
85
+ )
86
+ end
87
+
88
+ # Converts ascii quote pairs to multibyte quote characters
89
+ class QuoteConverter
90
+
91
+ def initialize
92
+ @in_dquote = false
93
+ @in_squote = false
94
+ end
95
+
96
+ def convert(quote, after_word:)
97
+ case quote
98
+ when '"'
99
+ type = @in_dquote ? :close_dquote : :open_dquote
100
+ @in_dquote = !@in_dquote
101
+ when "'"
102
+ if @in_squote
103
+ type = :close_squote
104
+ @in_squote = false
105
+ elsif after_word
106
+ # Mary's dog, my parents' house: do not start paired quotes
107
+ type = :close_squote
108
+ else
109
+ type = :open_squote
110
+ @in_squote = true
111
+ end
112
+ when '`'
113
+ # Opening quote of <tt>`quoted sentence'</tt>.
114
+ # This will conflict with code blocks <tt>`puts('hello')`</tt> in the future.
115
+ if !@in_squote && !after_word
116
+ type = :open_squote
117
+ @in_squote = true
118
+ end
119
+ end
120
+ TO_HTML_CHARACTERS[quote.encoding][type] if type
121
+ end
122
+ end
123
+
124
+ ##
125
+ # Creates a new formatter that will output HTML
126
+
127
+ def initialize(pipe: false, output_decoration: true)
128
+ super()
129
+
130
+ @pipe = pipe
131
+ @output_decoration = output_decoration
132
+ @code_object = nil
133
+ @from_path = ''
134
+ @in_list_entry = nil
135
+ @list = nil
136
+ @th = nil
137
+ @quote_converter = nil
138
+ @in_tidylink_label = false
139
+ @hard_break = "<br>\n"
140
+
141
+ init_regexp_handlings
142
+ end
143
+
144
+ # :section: Regexp Handling
145
+ #
146
+ # These methods are used by regexp handling markup added by RDoc::Markup#add_regexp_handling.
147
+
148
+ # :nodoc:
149
+ URL_CHARACTERS_REGEXP_STR = /[A-Za-z0-9\-._~:\/\?#\[\]@!$&'\(\)*+,;%=]/.source
150
+
151
+ ##
152
+ # Adds regexp handlings.
153
+
154
+ def init_regexp_handlings
155
+ # external links
156
+ @markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)#{URL_CHARACTERS_REGEXP_STR}+\w/,
157
+ :HYPERLINK)
158
+
159
+ # suppress crossref: \#method \::method \ClassName \method_with_underscores
160
+ @markup.add_regexp_handling(/\\(?:[#:A-Z]|[a-z]+_[a-z0-9])/, :SUPPRESSED_CROSSREF)
161
+
162
+ @markup.add_regexp_handling(Regexp.union(HTML_CHARACTER_ALIASES.keys), :HTML_CHARACTERS)
163
+
164
+ @markup.add_regexp_handling(/\b['"`]/, :QUOTE_AFTER_WORD)
165
+ @markup.add_regexp_handling(/\B['"`]/, :QUOTE_NOT_AFTER_WORD)
166
+
167
+ init_link_notation_regexp_handlings
168
+ end
169
+
170
+ ##
171
+ # Adds regexp handlings about link notations.
172
+
173
+ def init_link_notation_regexp_handlings
174
+ add_regexp_handling_RDOCLINK
175
+ end
176
+
177
+ def handle_RDOCLINK(url) # :nodoc:
178
+ case url
179
+ when /^rdoc-ref:/
180
+ CGI.escapeHTML($')
181
+ when /^rdoc-label:/
182
+ return CGI.escapeHTML(url) if in_tidylink_label?
183
+ text = $'
184
+
185
+ text = case text
186
+ when /\Alabel-/ then $'
187
+ when /\Afootmark-/ then $'
188
+ when /\Afoottext-/ then $'
189
+ else text
190
+ end
191
+
192
+ gen_url CGI.escapeHTML(url), CGI.escapeHTML(text)
193
+ when /^rdoc-image:/
194
+ # Split the string after "rdoc-image:" into url and alt.
195
+ # "path/to/image.jpg:alt text" => ["path/to/image.jpg", "alt text"]
196
+ # "http://example.com/path/to/image.jpg:alt text" => ["http://example.com/path/to/image.jpg", "alt text"]
197
+ url, alt = $'.split(/:(?!\/)/, 2)
198
+ if alt && !alt.empty?
199
+ %[<img src="#{CGI.escapeHTML(url)}" alt="#{CGI.escapeHTML(alt)}">]
200
+ else
201
+ %[<img src="#{CGI.escapeHTML(url)}">]
202
+ end
203
+ when /\Ardoc-[a-z]+:/
204
+ CGI.escapeHTML($')
205
+ end
206
+ end
207
+
208
+ def handle_PLAIN_TEXT(text)
209
+ emit_inline(convert_string(text))
210
+ end
211
+
212
+ def handle_REGEXP_HANDLING_TEXT(text)
213
+ emit_inline(text)
214
+ end
215
+
216
+ def handle_BOLD(nodes)
217
+ emit_inline('<strong>')
218
+ super
219
+ emit_inline('</strong>')
220
+ end
221
+
222
+ def handle_EM(nodes)
223
+ emit_inline('<em>')
224
+ super
225
+ emit_inline('</em>')
226
+ end
227
+
228
+ def handle_BOLD_WORD(word)
229
+ emit_inline('<strong>')
230
+ super
231
+ emit_inline('</strong>')
232
+ end
233
+
234
+ def handle_EM_WORD(word)
235
+ emit_inline('<em>')
236
+ super
237
+ emit_inline('</em>')
238
+ end
239
+
240
+ def handle_TT(code)
241
+ emit_inline('<code>')
242
+ super
243
+ emit_inline('</code>')
244
+ end
245
+
246
+ def handle_STRIKE(nodes)
247
+ emit_inline('<del>')
248
+ super
249
+ emit_inline('</del>')
250
+ end
251
+
252
+ def handle_HARD_BREAK
253
+ emit_inline('<br>')
254
+ end
255
+
256
+ def emit_inline(text)
257
+ @inline_output << text
258
+ end
259
+
260
+ # Returns true if we are processing inside a tidy link label.
261
+
262
+ def in_tidylink_label?
263
+ @in_tidylink_label
264
+ end
265
+
266
+ # Special handling for tidy link labels.
267
+ # When a tidy link is <tt>{rdoc-image:path/to/image.jpg:alt text}[http://example.com]</tt>,
268
+ # label part is normally considered RDOCLINK <tt>rdoc-image:path/to/image.jpg:alt</tt> and a text <tt>" text"</tt>
269
+ # but RDoc's test code expects the whole label part to be treated as RDOCLINK only in tidy link label.
270
+ # When a tidy link is <tt>{^1}[url]</tt> or <tt>{*1}[url]</tt>, the label part needs to drop leading * or ^.
271
+ # TODO: reconsider this workaround.
272
+
273
+ def apply_tidylink_label_special_handling(label, url)
274
+ # ^1 *1 will be converted to just 1 in tidy link label.
275
+ return label[1..] if label.match?(/\A[*^]\d+\z/)
276
+
277
+ # rdoc-image in label specially allows spaces in alt text.
278
+ return handle_RDOCLINK(label) if label.start_with?('rdoc-image:')
279
+ end
280
+
281
+ def handle_TIDYLINK(label_part, url)
282
+ # When url is an image, ignore label part (maybe bug?) and just generate img tag.
283
+ if url.match?(/\Ahttps?:\/\/.+\.(png|gif|jpg|jpeg|bmp)\z/)
284
+ emit_inline("<img src=\"#{CGI.escapeHTML(url)}\" />")
285
+ return
286
+ elsif url.match?(/\Ardoc-image:/)
287
+ emit_inline(handle_RDOCLINK(url))
288
+ return
289
+ end
290
+
291
+ if label_part.size == 1 && String === label_part[0]
292
+ raw_label = label_part[0]
293
+
294
+ @in_tidylink_label = true
295
+ special = apply_tidylink_label_special_handling(raw_label, url)
296
+ @in_tidylink_label = false
297
+
298
+ if special
299
+ tag = gen_url(CGI.escapeHTML(url), special)
300
+ unless tag.empty?
301
+ emit_inline(tag)
302
+ return
303
+ end
304
+ end
305
+ end
306
+
307
+ tag = gen_url(CGI.escapeHTML(url), '')
308
+ open_tag, close_tag = tag.split(/(?=<\/a>)/, 2)
309
+ valid_tag = open_tag && close_tag
310
+ emit_inline(open_tag) if valid_tag
311
+ @in_tidylink_label = true
312
+ traverse_inline_nodes(label_part)
313
+ @in_tidylink_label = false
314
+ emit_inline(close_tag) if valid_tag
315
+ end
316
+
317
+ def handle_inline(text) # :nodoc:
318
+ @inline_output = +''
319
+ @quote_converter = QuoteConverter.new
320
+ super
321
+ out = @inline_output
322
+ @inline_output = nil
323
+ @quote_converter = nil
324
+ out
325
+ end
326
+
327
+ # Converts <tt>(c), (r), --, --- , ..., ...., ``, ''</tt> to HTML characters.
328
+ def handle_regexp_HTML_CHARACTERS(text)
329
+ name = HTML_CHARACTER_ALIASES[text]
330
+ TO_HTML_CHARACTERS[text.encoding][name] if name
331
+ end
332
+
333
+ def handle_regexp_QUOTE_NOT_AFTER_WORD(text)
334
+ @quote_converter.convert(text, after_word: false) || convert_string(text)
335
+ end
336
+
337
+ def handle_regexp_QUOTE_AFTER_WORD(text)
338
+ @quote_converter.convert(text, after_word: true) || convert_string(text)
339
+ end
340
+
341
+ # Converts suppressed cross-reference +text+ to HTML by removing the leading backslash.
342
+
343
+ def handle_regexp_SUPPRESSED_CROSSREF(text)
344
+ convert_string(text.delete_prefix('\\'))
345
+ end
346
+
347
+ ##
348
+ # +target+ is a potential link. The following schemes are handled:
349
+ #
350
+ # <tt>mailto:</tt>::
351
+ # Inserted as-is.
352
+ # <tt>http:</tt>::
353
+ # Links are checked to see if they reference an image. If so, that image
354
+ # gets inserted using an <tt><img></tt> tag. Otherwise a conventional
355
+ # <tt><a href></tt> is used.
356
+ # <tt>link:</tt>::
357
+ # Reference to a local file relative to the output directory.
358
+
359
+ def handle_regexp_HYPERLINK(text)
360
+ return convert_string(text) if in_tidylink_label?
361
+
362
+ url = CGI.escapeHTML(text)
363
+ gen_url url, url
364
+ end
365
+
366
+ ##
367
+ # +target+ is an rdoc-schemed link that will be converted into a hyperlink.
368
+ #
369
+ # For the +rdoc-ref+ scheme the named reference will be returned without
370
+ # creating a link.
371
+ #
372
+ # For the +rdoc-label+ scheme the footnote and label prefixes are stripped
373
+ # when creating a link. All other contents will be linked verbatim.
374
+
375
+ def handle_regexp_RDOCLINK(text)
376
+ handle_RDOCLINK text
377
+ end
378
+
379
+ # :section: Visitor
380
+ #
381
+ # These methods implement the HTML visitor.
382
+
383
+ ##
384
+ # Prepares the visitor for HTML generation
385
+
386
+ def start_accepting
387
+ @res = []
388
+ @in_list_entry = []
389
+ @list = []
390
+ @heading_ids = {}
391
+ end
392
+
393
+ ##
394
+ # Returns the generated output
395
+
396
+ def end_accepting
397
+ @res.join
398
+ end
399
+
400
+ ##
401
+ # Adds +block_quote+ to the output
402
+
403
+ def accept_block_quote(block_quote)
404
+ @res << "\n<blockquote>"
405
+
406
+ block_quote.parts.each do |part|
407
+ part.accept self
408
+ end
409
+
410
+ @res << "</blockquote>\n"
411
+ end
412
+
413
+ ##
414
+ # Adds +paragraph+ to the output
415
+
416
+ def accept_paragraph(paragraph)
417
+ @res << "\n<p>"
418
+ text = paragraph.text @hard_break
419
+ text = text.gsub(/(#{SPACE_SEPARATED_LETTER_CLASS})?\K(?:\r?\n)+(?=(?(1)(#{SPACE_SEPARATED_LETTER_CLASS})?))/o) {
420
+ defined?($2) && ' '
421
+ }
422
+ @res << to_html(text)
423
+ @res << "</p>\n"
424
+ end
425
+
426
+ # Generate syntax highlighted html for ruby-like text.
427
+
428
+ def parsable_text_to_html(text)
429
+ tokens = RDoc::Parser::RubyColorizer.colorize(text)
430
+ result = RDoc::TokenStream.to_html tokens
431
+ result = result + "\n" unless result.end_with?("\n")
432
+ result
433
+ end
434
+
435
+ ##
436
+ # Adds +verbatim+ to the output
437
+
438
+ def accept_verbatim(verbatim)
439
+ text = verbatim.text.rstrip
440
+ format = verbatim.format
441
+
442
+ # Apply Ruby syntax highlighting if
443
+ # - explicitly marked as Ruby (via ruby? which accepts :ruby or :rb)
444
+ # - no format specified but the text is parseable as Ruby
445
+ # Otherwise, add language class when applicable and skip Ruby highlighting
446
+ if verbatim.ruby? || (format.nil? && parseable?(text))
447
+ content = parsable_text_to_html(text)
448
+ klass = ' class="ruby"'
449
+ else
450
+ content = CGI.escapeHTML text
451
+ klass = " class=\"#{format}\"" if format
452
+ end
453
+
454
+ if @pipe
455
+ @res << "\n<pre><code>#{CGI.escapeHTML text}\n</code></pre>\n"
456
+ else
457
+ @res << "\n<pre#{klass}>#{content}</pre>\n"
458
+ end
459
+ end
460
+
461
+ ##
462
+ # Adds +rule+ to the output
463
+
464
+ def accept_rule(rule)
465
+ @res << "<hr>\n"
466
+ end
467
+
468
+ ##
469
+ # Prepares the visitor for consuming +list+
470
+
471
+ def accept_list_start(list)
472
+ @list << list.type
473
+ @res << html_list_name(list.type, true)
474
+ @in_list_entry.push false
475
+ end
476
+
477
+ ##
478
+ # Finishes consumption of +list+
479
+
480
+ def accept_list_end(list)
481
+ @list.pop
482
+ if tag = @in_list_entry.pop
483
+ @res << tag
484
+ end
485
+ @res << html_list_name(list.type, false) << "\n"
486
+ end
487
+
488
+ ##
489
+ # Prepares the visitor for consuming +list_item+
490
+
491
+ def accept_list_item_start(list_item)
492
+ if tag = @in_list_entry.last
493
+ @res << tag
494
+ end
495
+
496
+ @res << list_item_start(list_item, @list.last)
497
+ end
498
+
499
+ ##
500
+ # Finishes consumption of +list_item+
501
+
502
+ def accept_list_item_end(list_item)
503
+ @in_list_entry[-1] = list_end_for(@list.last)
504
+ end
505
+
506
+ ##
507
+ # Adds +blank_line+ to the output
508
+
509
+ def accept_blank_line(blank_line)
510
+ # @res << annotate("<p />") << "\n"
511
+ end
512
+
513
+ ##
514
+ # Adds +heading+ to the output. The headings greater than 6 are trimmed to
515
+ # level 6.
516
+
517
+ def accept_heading(heading)
518
+ level = [6, heading.level].min
519
+
520
+ label = deduplicate_heading_id(heading.label(@code_object))
521
+ legacy_label = deduplicate_heading_id(heading.legacy_label(@code_object))
522
+
523
+ # Add legacy anchor before the heading for backward compatibility.
524
+ # This allows old links with label- prefix to still work.
525
+ if @output_decoration && !@pipe
526
+ @res << "\n<span id=\"#{legacy_label}\" class=\"legacy-anchor\"></span>"
527
+ end
528
+
529
+ @res << if @output_decoration
530
+ "\n<h#{level} id=\"#{label}\">"
531
+ else
532
+ "\n<h#{level}>"
533
+ end
534
+
535
+ if @pipe
536
+ @res << to_html(heading.text)
537
+ else
538
+ @res << "<a href=\"##{label}\">#{to_html(heading.text)}</a>"
539
+ end
540
+
541
+ @res << "</h#{level}>\n"
542
+ end
543
+
544
+ ##
545
+ # Adds +raw+ to the output
546
+
547
+ def accept_raw(raw)
548
+ @res << raw.parts.join("\n")
549
+ end
550
+
551
+ ##
552
+ # Adds +table+ to the output
553
+
554
+ def accept_table(header, body, aligns)
555
+ @res << "\n<table role=\"table\">\n<thead>\n<tr>\n"
556
+ header.zip(aligns) do |text, align|
557
+ @res << '<th'
558
+ @res << ' align="' << align << '"' if align
559
+ @res << '>' << to_html(text) << "</th>\n"
560
+ end
561
+ @res << "</tr>\n</thead>\n<tbody>\n"
562
+ body.each do |row|
563
+ @res << "<tr>\n"
564
+ row.zip(aligns) do |text, align|
565
+ @res << '<td'
566
+ @res << ' align="' << align << '"' if align
567
+ @res << '>' << to_html(text) << "</td>\n"
568
+ end
569
+ @res << "</tr>\n"
570
+ end
571
+ @res << "</tbody>\n</table>\n"
572
+ end
573
+
574
+ # :section: Utilities
575
+
576
+ ##
577
+ # Returns a unique heading ID, appending -1, -2, etc. for duplicates.
578
+ # Matches GitHub's behavior for duplicate heading anchors.
579
+
580
+ def deduplicate_heading_id(id)
581
+ if @heading_ids.key?(id)
582
+ @heading_ids[id] += 1
583
+ "#{id}-#{@heading_ids[id]}"
584
+ else
585
+ @heading_ids[id] = 0
586
+ id
587
+ end
588
+ end
589
+
590
+ ##
591
+ # CGI-escapes +text+
592
+
593
+ def convert_string(text)
594
+ CGI.escapeHTML text
595
+ end
596
+
597
+ ##
598
+ # Generates an HTML link or image tag for the given +url+ and +text+.
599
+ #
600
+ # - Image URLs (http/https/link ending in .gif, .png, .jpg, .jpeg, .bmp)
601
+ # become <img> tags
602
+ # - File references (.rb, .rdoc, .md) are converted to .html paths
603
+ # - Anchor URLs (#foo) pass through unchanged for GitHub-style header linking
604
+ # - Footnote links get wrapped in <sup> tags
605
+
606
+ def gen_url(url, text)
607
+ scheme, url, id = parse_url url
608
+
609
+ if %w[http https link].include?(scheme) && url =~ /\.(gif|png|jpg|jpeg|bmp)\z/
610
+ "<img src=\"#{url}\" />"
611
+ else
612
+ if scheme != 'link' and %r%\A((?!https?:)(?:[^/#]*/)*+)([^/#]+)\.(rb|rdoc|md)(?=\z|#)%i =~ url
613
+ url = "#$1#{$2.tr('.', '_')}_#$3.html#$'"
614
+ end
615
+
616
+ text = text.sub %r%^#{scheme}:/*%i, ''
617
+ text = text.sub %r%^[*\^](\d+)$%, '\1'
618
+
619
+ link = "<a#{id} href=\"#{url}\">#{text}</a>"
620
+
621
+ if /"foot/.match?(id)
622
+ "<sup>#{link}</sup>"
623
+ else
624
+ link
625
+ end
626
+ end
627
+ end
628
+
629
+ ##
630
+ # Determines the HTML list element for +list_type+ and +open_tag+
631
+
632
+ def html_list_name(list_type, open_tag)
633
+ tags = LIST_TYPE_TO_HTML[list_type]
634
+ raise RDoc::Error, "Invalid list type: #{list_type.inspect}" unless tags
635
+ tags[open_tag ? 0 : 1]
636
+ end
637
+
638
+ ##
639
+ # Returns the HTML tag for +list_type+, possible using a label from
640
+ # +list_item+
641
+
642
+ def list_item_start(list_item, list_type)
643
+ case list_type
644
+ when :BULLET, :LALPHA, :NUMBER, :UALPHA then
645
+ "<li>"
646
+ when :LABEL, :NOTE then
647
+ Array(list_item.label).map do |label|
648
+ "<dt>#{to_html label}</dt>\n"
649
+ end.join << "<dd>"
650
+ else
651
+ raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
652
+ end
653
+ end
654
+
655
+ ##
656
+ # Returns the HTML end-tag for +list_type+
657
+
658
+ def list_end_for(list_type)
659
+ case list_type
660
+ when :BULLET, :LALPHA, :NUMBER, :UALPHA then
661
+ "</li>"
662
+ when :LABEL, :NOTE then
663
+ "</dd>"
664
+ else
665
+ raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
666
+ end
667
+ end
668
+
669
+ ##
670
+ # Returns true if text is valid ruby syntax
671
+
672
+ def parseable?(text)
673
+ Prism.parse_success?(text)
674
+ end
675
+
676
+ ##
677
+ # Converts +item+ to HTML using RDoc::Text#to_html
678
+
679
+ def to_html(item)
680
+ handle_inline(item)
681
+ end
682
+ end