rdoc 3.1 → 6.3.3

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 (247) 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 +129 -0
  11. data/RI.rdoc +57 -0
  12. data/Rakefile +84 -81
  13. data/TODO.rdoc +59 -0
  14. data/bin/console +7 -0
  15. data/bin/setup +6 -0
  16. data/{bin → exe}/rdoc +11 -2
  17. data/exe/ri +12 -0
  18. data/lib/rdoc/alias.rb +1 -2
  19. data/lib/rdoc/anon_class.rb +3 -2
  20. data/lib/rdoc/any_method.rb +234 -40
  21. data/lib/rdoc/attr.rb +79 -11
  22. data/lib/rdoc/class_module.rb +443 -71
  23. data/lib/rdoc/code_object.rb +216 -20
  24. data/lib/rdoc/code_objects.rb +4 -21
  25. data/lib/rdoc/comment.rb +250 -0
  26. data/lib/rdoc/constant.rb +110 -9
  27. data/lib/rdoc/context/section.rb +232 -0
  28. data/lib/rdoc/context.rb +392 -172
  29. data/lib/rdoc/cross_reference.rb +202 -0
  30. data/lib/rdoc/encoding.rb +83 -28
  31. data/lib/rdoc/erb_partial.rb +19 -0
  32. data/lib/rdoc/erbio.rb +8 -3
  33. data/lib/rdoc/extend.rb +10 -0
  34. data/lib/rdoc/generator/darkfish.rb +507 -84
  35. data/lib/rdoc/generator/json_index.rb +300 -0
  36. data/lib/rdoc/generator/markup.rb +27 -74
  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 +8 -62
  42. data/lib/rdoc/generator/template/darkfish/_footer.rhtml +5 -0
  43. data/lib/rdoc/generator/template/darkfish/_head.rhtml +22 -0
  44. data/lib/rdoc/generator/template/darkfish/_sidebar_VCS_info.rhtml +19 -0
  45. data/lib/rdoc/generator/template/darkfish/_sidebar_classes.rhtml +9 -0
  46. data/lib/rdoc/generator/template/darkfish/_sidebar_extends.rhtml +15 -0
  47. data/lib/rdoc/generator/template/darkfish/_sidebar_in_files.rhtml +9 -0
  48. data/lib/rdoc/generator/template/darkfish/_sidebar_includes.rhtml +15 -0
  49. data/lib/rdoc/generator/template/darkfish/_sidebar_installed.rhtml +15 -0
  50. data/lib/rdoc/generator/template/darkfish/_sidebar_methods.rhtml +12 -0
  51. data/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +11 -0
  52. data/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +12 -0
  53. data/lib/rdoc/generator/template/darkfish/_sidebar_parent.rhtml +11 -0
  54. data/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +14 -0
  55. data/lib/rdoc/generator/template/darkfish/_sidebar_sections.rhtml +11 -0
  56. data/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +18 -0
  57. data/lib/rdoc/generator/template/darkfish/class.rhtml +172 -0
  58. data/lib/rdoc/generator/template/darkfish/css/fonts.css +167 -0
  59. data/lib/rdoc/generator/template/darkfish/css/rdoc.css +639 -0
  60. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Light.ttf +0 -0
  61. data/lib/rdoc/generator/template/darkfish/fonts/Lato-LightItalic.ttf +0 -0
  62. data/lib/rdoc/generator/template/darkfish/fonts/Lato-Regular.ttf +0 -0
  63. data/lib/rdoc/generator/template/darkfish/fonts/Lato-RegularItalic.ttf +0 -0
  64. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Bold.ttf +0 -0
  65. data/lib/rdoc/generator/template/darkfish/fonts/SourceCodePro-Regular.ttf +0 -0
  66. data/lib/rdoc/generator/template/darkfish/images/add.png +0 -0
  67. data/lib/rdoc/generator/template/darkfish/images/arrow_up.png +0 -0
  68. data/lib/rdoc/generator/template/darkfish/images/delete.png +0 -0
  69. data/lib/rdoc/generator/template/darkfish/images/tag_blue.png +0 -0
  70. data/lib/rdoc/generator/template/darkfish/images/transparent.png +0 -0
  71. data/lib/rdoc/generator/template/darkfish/index.rhtml +18 -60
  72. data/lib/rdoc/generator/template/darkfish/js/darkfish.js +51 -83
  73. data/lib/rdoc/generator/template/darkfish/js/search.js +110 -0
  74. data/lib/rdoc/generator/template/darkfish/page.rhtml +18 -0
  75. data/lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml +18 -0
  76. data/lib/rdoc/generator/template/darkfish/servlet_root.rhtml +62 -0
  77. data/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +58 -0
  78. data/lib/rdoc/generator/template/json_index/.document +1 -0
  79. data/lib/rdoc/generator/template/json_index/js/navigation.js +105 -0
  80. data/lib/rdoc/generator/template/json_index/js/searcher.js +229 -0
  81. data/lib/rdoc/generator.rb +24 -13
  82. data/lib/rdoc/ghost_method.rb +1 -2
  83. data/lib/rdoc/i18n/locale.rb +102 -0
  84. data/lib/rdoc/i18n/text.rb +126 -0
  85. data/lib/rdoc/i18n.rb +10 -0
  86. data/lib/rdoc/include.rb +5 -95
  87. data/lib/rdoc/known_classes.rb +5 -2
  88. data/lib/rdoc/markdown/entities.rb +2132 -0
  89. data/lib/rdoc/markdown/literals.kpeg +23 -0
  90. data/lib/rdoc/markdown/literals.rb +416 -0
  91. data/lib/rdoc/markdown.kpeg +1237 -0
  92. data/lib/rdoc/markdown.rb +16684 -0
  93. data/lib/rdoc/markup/attr_changer.rb +23 -0
  94. data/lib/rdoc/markup/attr_span.rb +36 -0
  95. data/lib/rdoc/markup/attribute_manager.rb +135 -62
  96. data/lib/rdoc/markup/attributes.rb +71 -0
  97. data/lib/rdoc/markup/blank_line.rb +1 -0
  98. data/lib/rdoc/markup/block_quote.rb +15 -0
  99. data/lib/rdoc/markup/document.rb +96 -9
  100. data/lib/rdoc/markup/formatter.rb +138 -25
  101. data/lib/rdoc/markup/hard_break.rb +32 -0
  102. data/lib/rdoc/markup/heading.rb +61 -2
  103. data/lib/rdoc/markup/include.rb +43 -0
  104. data/lib/rdoc/markup/indented_paragraph.rb +48 -0
  105. data/lib/rdoc/markup/list.rb +25 -4
  106. data/lib/rdoc/markup/list_item.rb +18 -4
  107. data/lib/rdoc/markup/paragraph.rb +15 -0
  108. data/lib/rdoc/markup/parser.rb +180 -88
  109. data/lib/rdoc/markup/pre_process.rb +183 -38
  110. data/lib/rdoc/markup/raw.rb +6 -5
  111. data/lib/rdoc/markup/regexp_handling.rb +41 -0
  112. data/lib/rdoc/markup/rule.rb +1 -0
  113. data/lib/rdoc/markup/table.rb +47 -0
  114. data/lib/rdoc/markup/to_ansi.rb +17 -7
  115. data/lib/rdoc/markup/to_bs.rb +5 -8
  116. data/lib/rdoc/markup/to_html.rb +238 -137
  117. data/lib/rdoc/markup/to_html_crossref.rb +125 -152
  118. data/lib/rdoc/markup/to_html_snippet.rb +285 -0
  119. data/lib/rdoc/markup/to_joined_paragraph.rb +47 -0
  120. data/lib/rdoc/markup/to_label.rb +75 -0
  121. data/lib/rdoc/markup/to_markdown.rb +192 -0
  122. data/lib/rdoc/markup/to_rdoc.rb +85 -15
  123. data/lib/rdoc/markup/to_table_of_contents.rb +89 -0
  124. data/lib/rdoc/markup/to_test.rb +2 -4
  125. data/lib/rdoc/markup/to_tt_only.rb +121 -0
  126. data/lib/rdoc/markup/verbatim.rb +39 -0
  127. data/lib/rdoc/markup.rb +388 -110
  128. data/lib/rdoc/meta_method.rb +1 -2
  129. data/lib/rdoc/method_attr.rb +87 -21
  130. data/lib/rdoc/mixin.rb +121 -0
  131. data/lib/rdoc/normal_class.rb +39 -10
  132. data/lib/rdoc/normal_module.rb +22 -7
  133. data/lib/rdoc/options.rb +613 -73
  134. data/lib/rdoc/parser/c.rb +621 -287
  135. data/lib/rdoc/parser/changelog.rb +335 -0
  136. data/lib/rdoc/parser/markdown.rb +24 -0
  137. data/lib/rdoc/parser/rd.rb +23 -0
  138. data/lib/rdoc/parser/ripper_state_lex.rb +590 -0
  139. data/lib/rdoc/parser/ruby.rb +1368 -762
  140. data/lib/rdoc/parser/ruby_tools.rb +42 -35
  141. data/lib/rdoc/parser/simple.rb +23 -11
  142. data/lib/rdoc/parser/text.rb +12 -0
  143. data/lib/rdoc/parser.rb +162 -89
  144. data/lib/rdoc/rd/block_parser.rb +1056 -0
  145. data/lib/rdoc/rd/block_parser.ry +639 -0
  146. data/lib/rdoc/rd/inline.rb +72 -0
  147. data/lib/rdoc/rd/inline_parser.rb +1208 -0
  148. data/lib/rdoc/rd/inline_parser.ry +593 -0
  149. data/lib/rdoc/rd.rb +100 -0
  150. data/lib/rdoc/rdoc.rb +208 -115
  151. data/lib/rdoc/require.rb +1 -2
  152. data/lib/rdoc/ri/driver.rb +734 -239
  153. data/lib/rdoc/ri/formatter.rb +1 -0
  154. data/lib/rdoc/ri/paths.rb +91 -48
  155. data/lib/rdoc/ri/store.rb +3 -261
  156. data/lib/rdoc/ri/task.rb +71 -0
  157. data/lib/rdoc/ri.rb +5 -2
  158. data/lib/rdoc/rubygems_hook.rb +246 -0
  159. data/lib/rdoc/servlet.rb +451 -0
  160. data/lib/rdoc/single_class.rb +14 -2
  161. data/lib/rdoc/stats/normal.rb +19 -12
  162. data/lib/rdoc/stats/quiet.rb +1 -0
  163. data/lib/rdoc/stats/verbose.rb +1 -0
  164. data/lib/rdoc/stats.rb +262 -104
  165. data/lib/rdoc/store.rb +979 -0
  166. data/lib/rdoc/task.rb +84 -44
  167. data/lib/rdoc/text.rb +117 -72
  168. data/lib/rdoc/token_stream.rb +73 -4
  169. data/lib/rdoc/tom_doc.rb +263 -0
  170. data/lib/rdoc/top_level.rb +111 -261
  171. data/lib/rdoc/version.rb +8 -0
  172. data/lib/rdoc.rb +127 -64
  173. data/man/ri.1 +247 -0
  174. data/rdoc.gemspec +249 -0
  175. metadata +171 -291
  176. data/.autotest +0 -16
  177. data/.document +0 -5
  178. data/History.txt +0 -594
  179. data/LICENSE.txt +0 -57
  180. data/Manifest.txt +0 -158
  181. data/README.txt +0 -45
  182. data/RI.txt +0 -58
  183. data/bin/ri +0 -5
  184. data/lib/rdoc/gauntlet.rb +0 -52
  185. data/lib/rdoc/generator/template/darkfish/classpage.rhtml +0 -296
  186. data/lib/rdoc/generator/template/darkfish/filepage.rhtml +0 -124
  187. data/lib/rdoc/generator/template/darkfish/js/jquery.js +0 -32
  188. data/lib/rdoc/generator/template/darkfish/js/quicksearch.js +0 -114
  189. data/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +0 -10
  190. data/lib/rdoc/generator/template/darkfish/rdoc.css +0 -706
  191. data/lib/rdoc/markup/formatter_test_case.rb +0 -689
  192. data/lib/rdoc/markup/inline.rb +0 -137
  193. data/lib/rdoc/markup/text_formatter_test_case.rb +0 -116
  194. data/lib/rdoc/ruby_lex.rb +0 -1291
  195. data/lib/rdoc/ruby_token.rb +0 -416
  196. data/test/README +0 -1
  197. data/test/binary.dat +0 -0
  198. data/test/hidden.zip.txt +0 -1
  199. data/test/test.ja.rdoc +0 -10
  200. data/test/test.ja.txt +0 -8
  201. data/test/test.txt +0 -1
  202. data/test/test_attribute_manager.rb +0 -120
  203. data/test/test_rdoc_alias.rb +0 -13
  204. data/test/test_rdoc_any_method.rb +0 -126
  205. data/test/test_rdoc_attr.rb +0 -61
  206. data/test/test_rdoc_class_module.rb +0 -233
  207. data/test/test_rdoc_code_object.rb +0 -165
  208. data/test/test_rdoc_constant.rb +0 -15
  209. data/test/test_rdoc_context.rb +0 -370
  210. data/test/test_rdoc_encoding.rb +0 -166
  211. data/test/test_rdoc_generator_darkfish.rb +0 -119
  212. data/test/test_rdoc_generator_ri.rb +0 -76
  213. data/test/test_rdoc_include.rb +0 -96
  214. data/test/test_rdoc_markup.rb +0 -37
  215. data/test/test_rdoc_markup_attribute_manager.rb +0 -240
  216. data/test/test_rdoc_markup_document.rb +0 -51
  217. data/test/test_rdoc_markup_paragraph.rb +0 -9
  218. data/test/test_rdoc_markup_parser.rb +0 -1395
  219. data/test/test_rdoc_markup_pre_process.rb +0 -185
  220. data/test/test_rdoc_markup_raw.rb +0 -27
  221. data/test/test_rdoc_markup_to_ansi.rb +0 -328
  222. data/test/test_rdoc_markup_to_bs.rb +0 -341
  223. data/test/test_rdoc_markup_to_html.rb +0 -335
  224. data/test/test_rdoc_markup_to_html_crossref.rb +0 -169
  225. data/test/test_rdoc_markup_to_rdoc.rb +0 -327
  226. data/test/test_rdoc_method_attr.rb +0 -122
  227. data/test/test_rdoc_normal_class.rb +0 -17
  228. data/test/test_rdoc_normal_module.rb +0 -31
  229. data/test/test_rdoc_options.rb +0 -342
  230. data/test/test_rdoc_parser.rb +0 -83
  231. data/test/test_rdoc_parser_c.rb +0 -912
  232. data/test/test_rdoc_parser_ruby.rb +0 -1754
  233. data/test/test_rdoc_parser_simple.rb +0 -99
  234. data/test/test_rdoc_rdoc.rb +0 -164
  235. data/test/test_rdoc_require.rb +0 -25
  236. data/test/test_rdoc_ri_driver.rb +0 -846
  237. data/test/test_rdoc_ri_paths.rb +0 -43
  238. data/test/test_rdoc_ri_store.rb +0 -352
  239. data/test/test_rdoc_ruby_lex.rb +0 -23
  240. data/test/test_rdoc_stats.rb +0 -38
  241. data/test/test_rdoc_task.rb +0 -92
  242. data/test/test_rdoc_text.rb +0 -251
  243. data/test/test_rdoc_top_level.rb +0 -120
  244. data/test/xref_data.rb +0 -62
  245. data/test/xref_test_case.rb +0 -61
  246. data.tar.gz.sig +0 -3
  247. metadata.gz.sig +0 -0
@@ -1,92 +1,17 @@
1
- require 'rdoc/markup/to_html'
2
-
1
+ # frozen_string_literal: true
3
2
  ##
4
- # Subclass of the RDoc::Markup::ToHtml class that supports looking up words
5
- # from a context. Those that are found will be hyperlinked.
3
+ # Subclass of the RDoc::Markup::ToHtml class that supports looking up method
4
+ # names, classes, etc to create links. RDoc::CrossReference is used to
5
+ # generate those links based on the current context.
6
6
 
7
7
  class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
8
8
 
9
- ##
10
- # Regular expression to match class references
11
- #
12
- # 1. There can be a '\\' in front of text to suppress the cross-reference
13
- # 2. There can be a '::' in front of class names to reference from the
14
- # top-level namespace.
15
- # 3. The method can be followed by parenthesis (not recommended)
16
-
17
- CLASS_REGEXP_STR = '\\\\?((?:\:{2})?[A-Z]\w*(?:\:\:\w+)*)'
18
-
19
- ##
20
- # Regular expression to match method references.
21
- #
22
- # See CLASS_REGEXP_STR
23
-
24
- METHOD_REGEXP_STR = '([a-z]\w*[!?=]?)(?:\([\w.+*/=<>-]*\))?'
25
-
26
- ##
27
- # Regular expressions matching text that should potentially have
28
- # cross-reference links generated are passed to add_special. Note that
29
- # these expressions are meant to pick up text for which cross-references
30
- # have been suppressed, since the suppression characters are removed by the
31
- # code that is triggered.
32
-
33
- CROSSREF_REGEXP = /(
34
- # A::B::C.meth
35
- #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
36
-
37
- # Stand-alone method (preceeded by a #)
38
- | \\?\##{METHOD_REGEXP_STR}
39
-
40
- # Stand-alone method (preceeded by ::)
41
- | ::#{METHOD_REGEXP_STR}
42
-
43
- # A::B::C
44
- # The stuff after CLASS_REGEXP_STR is a
45
- # nasty hack. CLASS_REGEXP_STR unfortunately matches
46
- # words like dog and cat (these are legal "class"
47
- # names in Fortran 95). When a word is flagged as a
48
- # potential cross-reference, limitations in the markup
49
- # engine suppress other processing, such as typesetting.
50
- # This is particularly noticeable for contractions.
51
- # In order that words like "can't" not
52
- # be flagged as potential cross-references, only
53
- # flag potential class cross-references if the character
54
- # after the cross-referece is a space, sentence
55
- # punctuation, tag start character, or attribute
56
- # marker.
57
- | #{CLASS_REGEXP_STR}(?=[\s\)\.\?\!\,\;<\000]|\z)
58
-
59
- # Things that look like filenames
60
- # The key thing is that there must be at least
61
- # one special character (period, slash, or
62
- # underscore).
63
- | (?:\.\.\/)*[-\/\w]+[_\/\.][-\w\/\.]+
64
-
65
- # Things that have markup suppressed
66
- # Don't process things like '\<' in \<tt>, though.
67
- # TODO: including < is a hack, not very satisfying.
68
- | \\[^\s<]
69
- )/x
70
-
71
- ##
72
- # Version of CROSSREF_REGEXP used when <tt>--hyperlink-all</tt> is specified.
73
-
74
- ALL_CROSSREF_REGEXP = /(
75
- # A::B::C.meth
76
- #{CLASS_REGEXP_STR}(?:[.#]|::)#{METHOD_REGEXP_STR}
77
-
78
- # Stand-alone method
79
- | \\?#{METHOD_REGEXP_STR}
80
-
81
- # A::B::C
82
- | #{CLASS_REGEXP_STR}(?=[\s\)\.\?\!\,\;<\000]|\z)
83
-
84
- # Things that look like filenames
85
- | (?:\.\.\/)*[-\/\w]+[_\/\.][-\w\/\.]+
86
-
87
- # Things that have markup suppressed
88
- | \\[^\s<]
89
- )/x
9
+ # :stopdoc:
10
+ ALL_CROSSREF_REGEXP = RDoc::CrossReference::ALL_CROSSREF_REGEXP
11
+ CLASS_REGEXP_STR = RDoc::CrossReference::CLASS_REGEXP_STR
12
+ CROSSREF_REGEXP = RDoc::CrossReference::CROSSREF_REGEXP
13
+ METHOD_REGEXP_STR = RDoc::CrossReference::METHOD_REGEXP_STR
14
+ # :startdoc:
90
15
 
91
16
  ##
92
17
  # RDoc::CodeObject for generating references
@@ -102,33 +27,62 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
102
27
  # Creates a new crossref resolver that generates links relative to +context+
103
28
  # which lives at +from_path+ in the generated files. '#' characters on
104
29
  # references are removed unless +show_hash+ is true. Only method names
105
- # preceded by '#' or '::' are hyperlinked, unless +hyperlink_all+ is true.
30
+ # preceded by '#' or '::' are linked, unless +hyperlink_all+ is true.
106
31
 
107
- def initialize(from_path, context, show_hash, hyperlink_all = false)
32
+ def initialize(options, from_path, context, markup = nil)
108
33
  raise ArgumentError, 'from_path cannot be nil' if from_path.nil?
109
- super()
110
34
 
111
- crossref_re = hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
35
+ super options, markup
36
+
37
+ @context = context
38
+ @from_path = from_path
39
+ @hyperlink_all = @options.hyperlink_all
40
+ @show_hash = @options.show_hash
41
+
42
+ @cross_reference = RDoc::CrossReference.new @context
43
+ end
44
+
45
+ def init_link_notation_regexp_handlings
46
+ add_regexp_handling_RDOCLINK
47
+
48
+ # The crossref must be linked before tidylink because Klass.method[:sym]
49
+ # will be processed as a tidylink first and will be broken.
50
+ crossref_re = @options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
51
+ @markup.add_regexp_handling crossref_re, :CROSSREF
52
+
53
+ add_regexp_handling_TIDYLINK
54
+ end
55
+
56
+ ##
57
+ # Creates a link to the reference +name+ if the name exists. If +text+ is
58
+ # given it is used as the link text, otherwise +name+ is used.
59
+
60
+ def cross_reference name, text = nil, code = true
61
+ lookup = name
112
62
 
113
- @markup.add_special crossref_re, :CROSSREF
63
+ name = name[1..-1] unless @show_hash if name[0, 1] == '#'
114
64
 
115
- @from_path = from_path
116
- @context = context
117
- @show_hash = show_hash
118
- @hyperlink_all = hyperlink_all
65
+ if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/
66
+ text ||= "#{CGI.unescape $'} at <code>#{$1}</code>"
67
+ code = false
68
+ else
69
+ text ||= name
70
+ end
119
71
 
120
- @seen = {}
72
+ link lookup, text, code
121
73
  end
122
74
 
123
75
  ##
124
76
  # We're invoked when any text matches the CROSSREF pattern. If we find the
125
- # corresponding reference, generate a hyperlink. If the name we're looking
126
- # for contains no punctuation, we look for it up the module/class chain.
127
- # For example, ToHtml is found, even without the <tt>RDoc::Markup::</tt>
128
- # prefix, because we look for it in module Markup first.
77
+ # corresponding reference, generate a link. If the name we're looking for
78
+ # contains no punctuation, we look for it up the module/class chain. For
79
+ # example, ToHtml is found, even without the <tt>RDoc::Markup::</tt> prefix,
80
+ # because we look for it in module Markup first.
81
+
82
+ def handle_regexp_CROSSREF(target)
83
+ name = target.text
129
84
 
130
- def handle_special_CROSSREF(special)
131
- name = special.text
85
+ return name if name =~ /@[\w-]+\.[\w-]/ # labels that look like emails
132
86
 
133
87
  unless @hyperlink_all then
134
88
  # This ensures that words entirely consisting of lowercase letters will
@@ -137,66 +91,85 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
137
91
  return name if name =~ /\A[a-z]*\z/
138
92
  end
139
93
 
140
- return @seen[name] if @seen.include? name
94
+ cross_reference name
95
+ end
141
96
 
142
- lookup = name
97
+ ##
98
+ # Handles <tt>rdoc-ref:</tt> scheme links and allows RDoc::Markup::ToHtml to
99
+ # handle other schemes.
143
100
 
144
- name = name[1..-1] unless @show_hash if name[0, 1] == '#'
101
+ def handle_regexp_HYPERLINK target
102
+ return cross_reference $' if target.text =~ /\Ardoc-ref:/
103
+
104
+ super
105
+ end
106
+
107
+ ##
108
+ # +target+ is an rdoc-schemed link that will be converted into a hyperlink.
109
+ # For the rdoc-ref scheme the cross-reference will be looked up and the
110
+ # given name will be used.
111
+ #
112
+ # All other contents are handled by
113
+ # {the superclass}[rdoc-ref:RDoc::Markup::ToHtml#handle_regexp_RDOCLINK]
114
+
115
+ def handle_regexp_RDOCLINK target
116
+ url = target.text
145
117
 
146
- # Find class, module, or method in class or module.
147
- #
148
- # Do not, however, use an if/elsif/else chain to do so. Instead, test
149
- # each possible pattern until one matches. The reason for this is that a
150
- # string like "YAML.txt" could be the txt() class method of class YAML (in
151
- # which case it would match the first pattern, which splits the string
152
- # into container and method components and looks up both) or a filename
153
- # (in which case it would match the last pattern, which just checks
154
- # whether the string as a whole is a known symbol).
155
-
156
- if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/ =~ lookup then
157
- type = $2
158
- type = '' if type == '.' # will find either #method or ::method
159
- method = "#{type}#{$3}"
160
- container = @context.find_symbol_module($1)
161
- elsif /^([.#]|::)#{METHOD_REGEXP_STR}/ =~ lookup then
162
- type = $1
163
- type = '' if type == '.'
164
- method = "#{type}#{$2}"
165
- container = @context
118
+ case url
119
+ when /\Ardoc-ref:/ then
120
+ cross_reference $'
166
121
  else
167
- container = nil
122
+ super
168
123
  end
124
+ end
125
+
126
+ ##
127
+ # Generates links for <tt>rdoc-ref:</tt> scheme URLs and allows
128
+ # RDoc::Markup::ToHtml to handle other schemes.
169
129
 
170
- if container then
171
- ref = container.find_local_symbol method
130
+ def gen_url url, text
131
+ return super unless url =~ /\Ardoc-ref:/
172
132
 
173
- unless ref || RDoc::TopLevel === container then
174
- ref = container.find_ancestor_local_symbol method
175
- end
133
+ name = $'
134
+ cross_reference name, text, name == text
135
+ end
136
+
137
+ ##
138
+ # Creates an HTML link to +name+ with the given +text+.
139
+
140
+ def link name, text, code = true
141
+ if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])@/
142
+ name = $1
143
+ label = $'
176
144
  end
177
145
 
178
- ref = @context.find_symbol lookup unless ref
179
- ref = nil if RDoc::Alias === ref # external alias: can't link to it
180
-
181
- out = if lookup == '\\' then
182
- lookup
183
- elsif lookup =~ /^\\/ then
184
- # we remove the \ only in front of what we know:
185
- # other backslashes are treated later, only outside of <tt>
186
- ref ? $' : lookup
187
- elsif ref then
188
- if ref.document_self then
189
- "<a href=\"#{ref.as_href @from_path}\">#{name}</a>"
190
- else
191
- name
192
- end
193
- else
194
- lookup
195
- end
196
-
197
- @seen[lookup] = out
198
-
199
- out
146
+ ref = @cross_reference.resolve name, text
147
+
148
+ case ref
149
+ when String then
150
+ ref
151
+ else
152
+ path = ref.as_href @from_path
153
+
154
+ if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref)
155
+ text = "<code>#{CGI.escapeHTML text}</code>"
156
+ end
157
+
158
+ if path =~ /#/ then
159
+ path << "-label-#{label}"
160
+ elsif ref.sections and
161
+ ref.sections.any? { |section| label == section.title } then
162
+ path << "##{label}"
163
+ else
164
+ if ref.respond_to?(:aref)
165
+ path << "##{ref.aref}-label-#{label}"
166
+ else
167
+ path << "#label-#{label}"
168
+ end
169
+ end if label
170
+
171
+ "<a href=\"#{path}\">#{text}</a>"
172
+ end
200
173
  end
201
174
 
202
175
  end
@@ -0,0 +1,285 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # Outputs RDoc markup as paragraphs with inline markup only.
4
+
5
+ class RDoc::Markup::ToHtmlSnippet < RDoc::Markup::ToHtml
6
+
7
+ ##
8
+ # After this many characters the input will be cut off.
9
+
10
+ attr_reader :character_limit
11
+
12
+ ##
13
+ # The number of characters seen so far.
14
+
15
+ attr_reader :characters # :nodoc:
16
+
17
+ ##
18
+ # The attribute bitmask
19
+
20
+ attr_reader :mask
21
+
22
+ ##
23
+ # After this many paragraphs the input will be cut off.
24
+
25
+ attr_reader :paragraph_limit
26
+
27
+ ##
28
+ # Count of paragraphs found
29
+
30
+ attr_reader :paragraphs
31
+
32
+ ##
33
+ # Creates a new ToHtmlSnippet formatter that will cut off the input on the
34
+ # next word boundary after the given number of +characters+ or +paragraphs+
35
+ # of text have been encountered.
36
+
37
+ def initialize options, characters = 100, paragraphs = 3, markup = nil
38
+ super options, markup
39
+
40
+ @character_limit = characters
41
+ @paragraph_limit = paragraphs
42
+
43
+ @characters = 0
44
+ @mask = 0
45
+ @paragraphs = 0
46
+
47
+ @markup.add_regexp_handling RDoc::CrossReference::CROSSREF_REGEXP, :CROSSREF
48
+ end
49
+
50
+ ##
51
+ # Adds +heading+ to the output as a paragraph
52
+
53
+ def accept_heading heading
54
+ @res << "<p>#{to_html heading.text}\n"
55
+
56
+ add_paragraph
57
+ end
58
+
59
+ ##
60
+ # Raw sections are untrusted and ignored
61
+
62
+ alias accept_raw ignore
63
+
64
+ ##
65
+ # Rules are ignored
66
+
67
+ alias accept_rule ignore
68
+
69
+ def accept_paragraph paragraph
70
+ para = @in_list_entry.last || "<p>"
71
+
72
+ text = paragraph.text @hard_break
73
+
74
+ @res << "#{para}#{to_html text}\n"
75
+
76
+ add_paragraph
77
+ end
78
+
79
+ ##
80
+ # Finishes consumption of +list_item+
81
+
82
+ def accept_list_item_end list_item
83
+ end
84
+
85
+ ##
86
+ # Prepares the visitor for consuming +list_item+
87
+
88
+ def accept_list_item_start list_item
89
+ @res << list_item_start(list_item, @list.last)
90
+ end
91
+
92
+ ##
93
+ # Prepares the visitor for consuming +list+
94
+
95
+ def accept_list_start list
96
+ @list << list.type
97
+ @res << html_list_name(list.type, true)
98
+ @in_list_entry.push ''
99
+ end
100
+
101
+ ##
102
+ # Adds +verbatim+ to the output
103
+
104
+ def accept_verbatim verbatim
105
+ throw :done if @characters >= @character_limit
106
+ input = verbatim.text.rstrip
107
+
108
+ text = truncate input
109
+ text << ' ...' unless text == input
110
+
111
+ super RDoc::Markup::Verbatim.new text
112
+
113
+ add_paragraph
114
+ end
115
+
116
+ ##
117
+ # Prepares the visitor for HTML snippet generation
118
+
119
+ def start_accepting
120
+ super
121
+
122
+ @characters = 0
123
+ end
124
+
125
+ ##
126
+ # Removes escaping from the cross-references in +target+
127
+
128
+ def handle_regexp_CROSSREF target
129
+ target.text.sub(/\A\\/, '')
130
+ end
131
+
132
+ ##
133
+ # +target+ is a <code><br></code>
134
+
135
+ def handle_regexp_HARD_BREAK target
136
+ @characters -= 4
137
+ '<br>'
138
+ end
139
+
140
+ ##
141
+ # Lists are paragraphs, but notes and labels have a separator
142
+
143
+ def list_item_start list_item, list_type
144
+ throw :done if @characters >= @character_limit
145
+
146
+ case list_type
147
+ when :BULLET, :LALPHA, :NUMBER, :UALPHA then
148
+ "<p>"
149
+ when :LABEL, :NOTE then
150
+ labels = Array(list_item.label).map do |label|
151
+ to_html label
152
+ end.join ', '
153
+
154
+ labels << " &mdash; " unless labels.empty?
155
+
156
+ start = "<p>#{labels}"
157
+ @characters += 1 # try to include the label
158
+ start
159
+ else
160
+ raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
161
+ end
162
+ end
163
+
164
+ ##
165
+ # Returns just the text of +link+, +url+ is only used to determine the link
166
+ # type.
167
+
168
+ def gen_url url, text
169
+ if url =~ /^rdoc-label:([^:]*)(?::(.*))?/ then
170
+ type = "link"
171
+ elsif url =~ /([A-Za-z]+):(.*)/ then
172
+ type = $1
173
+ else
174
+ type = "http"
175
+ end
176
+
177
+ if (type == "http" or type == "https" or type == "link") and
178
+ url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
179
+ ''
180
+ else
181
+ text.sub(%r%^#{type}:/*%, '')
182
+ end
183
+ end
184
+
185
+ ##
186
+ # In snippets, there are no lists
187
+
188
+ def html_list_name list_type, open_tag
189
+ ''
190
+ end
191
+
192
+ ##
193
+ # Throws +:done+ when paragraph_limit paragraphs have been encountered
194
+
195
+ def add_paragraph
196
+ @paragraphs += 1
197
+
198
+ throw :done if @paragraphs >= @paragraph_limit
199
+ end
200
+
201
+ ##
202
+ # Marks up +content+
203
+
204
+ def convert content
205
+ catch :done do
206
+ return super
207
+ end
208
+
209
+ end_accepting
210
+ end
211
+
212
+ ##
213
+ # Converts flow items +flow+
214
+
215
+ def convert_flow flow
216
+ throw :done if @characters >= @character_limit
217
+
218
+ res = []
219
+ @mask = 0
220
+
221
+ flow.each do |item|
222
+ case item
223
+ when RDoc::Markup::AttrChanger then
224
+ off_tags res, item
225
+ on_tags res, item
226
+ when String then
227
+ text = convert_string item
228
+ res << truncate(text)
229
+ when RDoc::Markup::RegexpHandling then
230
+ text = convert_regexp_handling item
231
+ res << truncate(text)
232
+ else
233
+ raise "Unknown flow element: #{item.inspect}"
234
+ end
235
+
236
+ if @characters >= @character_limit then
237
+ off_tags res, RDoc::Markup::AttrChanger.new(0, @mask)
238
+ break
239
+ end
240
+ end
241
+
242
+ res << ' ...' if @characters >= @character_limit
243
+
244
+ res.join
245
+ end
246
+
247
+ ##
248
+ # Maintains a bitmask to allow HTML elements to be closed properly. See
249
+ # RDoc::Markup::Formatter.
250
+
251
+ def on_tags res, item
252
+ @mask ^= item.turn_on
253
+
254
+ super
255
+ end
256
+
257
+ ##
258
+ # Maintains a bitmask to allow HTML elements to be closed properly. See
259
+ # RDoc::Markup::Formatter.
260
+
261
+ def off_tags res, item
262
+ @mask ^= item.turn_off
263
+
264
+ super
265
+ end
266
+
267
+ ##
268
+ # Truncates +text+ at the end of the first word after the character_limit.
269
+
270
+ def truncate text
271
+ length = text.length
272
+ characters = @characters
273
+ @characters += length
274
+
275
+ return text if @characters < @character_limit
276
+
277
+ remaining = @character_limit - characters
278
+
279
+ text =~ /\A(.{#{remaining},}?)(\s|$)/m # TODO word-break instead of \s?
280
+
281
+ $1
282
+ end
283
+
284
+ end
285
+
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+ ##
3
+ # Joins the parts of an RDoc::Markup::Paragraph into a single String.
4
+ #
5
+ # This allows for easier maintenance and testing of Markdown support.
6
+ #
7
+ # This formatter only works on Paragraph instances. Attempting to process
8
+ # other markup syntax items will not work.
9
+
10
+ class RDoc::Markup::ToJoinedParagraph < RDoc::Markup::Formatter
11
+
12
+ def initialize # :nodoc:
13
+ super nil
14
+ end
15
+
16
+ def start_accepting # :nodoc:
17
+ end
18
+
19
+ def end_accepting # :nodoc:
20
+ end
21
+
22
+ ##
23
+ # Converts the parts of +paragraph+ to a single entry.
24
+
25
+ def accept_paragraph paragraph
26
+ parts = paragraph.parts.chunk do |part|
27
+ String === part
28
+ end.map do |string, chunk|
29
+ string ? chunk.join.rstrip : chunk
30
+ end.flatten
31
+
32
+ paragraph.parts.replace parts
33
+ end
34
+
35
+ alias accept_block_quote ignore
36
+ alias accept_heading ignore
37
+ alias accept_list_end ignore
38
+ alias accept_list_item_end ignore
39
+ alias accept_list_item_start ignore
40
+ alias accept_list_start ignore
41
+ alias accept_raw ignore
42
+ alias accept_rule ignore
43
+ alias accept_verbatim ignore
44
+ alias accept_table ignore
45
+
46
+ end
47
+