1
1
# frozen_string_literal: true
2
2
require 'thread'
3
3
4
+ gem 'rdoc' , '>= 6.0'
5
+ require 'rdoc'
6
+ require 'rdoc/markup'
7
+ require 'rdoc/markup/to_html'
8
+
4
9
module YARD
5
10
module Templates
6
11
module Helpers
7
12
module Markup
8
- begin require 'rdoc' ; rescue LoadError ; nil end
9
- begin
10
- require 'rdoc/markup'
11
- require 'rdoc/markup/to_html'
12
- class RDocMarkup ; MARKUP = RDoc ::Markup end
13
- class RDocMarkupToHtml < RDoc ::Markup ::ToHtml
14
- if defined? ( RDoc ::VERSION ) && RDoc ::VERSION >= '4.0.0' &&
15
- defined? ( RDoc ::Options )
16
- def initialize
17
- options = RDoc ::Options . new
18
- options . pipe = true
19
- super ( options )
20
- end
21
- end
22
- end
23
- rescue LoadError
24
- begin
25
- require 'rdoc/markup/simple_markup'
26
- require 'rdoc/markup/simple_markup/to_html'
27
- class RDocMarkup ; MARKUP = SM ::SimpleMarkup end
28
- class RDocMarkupToHtml < SM ::ToHtml ; end
29
- rescue LoadError
30
- raise NameError , "could not load RDocMarkup (rdoc is not installed)"
31
- end
32
- end
33
-
34
13
class RDocMarkup
14
+ MARKUP = RDoc ::Markup
15
+
35
16
attr_accessor :from_path
36
17
37
18
@@mutex = Mutex . new
@@ -63,8 +44,6 @@ def to_html
63
44
private
64
45
65
46
# Fixes RDoc behaviour with ++ only supporting alphanumeric text.
66
- #
67
- # @todo Refactor into own SimpleMarkup subclass
68
47
def fix_typewriter ( text )
69
48
code_tags = 0
70
49
text . gsub ( %r{<(/)?(pre|code|tt)|(\s |^|>)\+ (?! )([^\n \+ ]{1,900})(?! )\+ } ) do |str |
@@ -82,18 +61,27 @@ def fix_typewriter(text)
82
61
end
83
62
end
84
63
85
- # Don't allow -- to turn into — element. The chances of this being
86
- # some --option is far more likely than the typographical meaning.
87
- #
88
- # @todo Refactor into own SimpleMarkup subclass
64
+ # Don't allow -- to turn into — element (em dash)
89
65
def fix_dash_dash ( text )
90
66
text . gsub ( /—(?=\S )/ , '--' )
91
67
end
92
68
end
93
69
94
- class RDocMarkupToHtml
70
+ # Specialized ToHtml formatter for YARD
71
+ #
72
+ # @todo Refactor into own SimpleMarkup subclass
73
+ class RDocMarkupToHtml < RDoc ::Markup ::ToHtml
95
74
attr_accessor :from_path
96
75
76
+ def initialize
77
+ options = RDoc ::Options . new
78
+ options . pipe = true
79
+ super ( options )
80
+
81
+ # The hyperlink detection state
82
+ @hyperlink = false
83
+ end
84
+
97
85
# Disable auto-link of URLs
98
86
def handle_special_HYPERLINK ( special ) # rubocop:disable Style/MethodName
99
87
@hyperlink ? special . text : super
0 commit comments