11# frozen_string_literal: true
22require 'thread'
33
4+ gem 'rdoc' , '>= 6.0'
5+ require 'rdoc'
6+ require 'rdoc/markup'
7+ require 'rdoc/markup/to_html'
8+
49module YARD
510 module Templates
611 module Helpers
712 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-
3413 class RDocMarkup
14+ MARKUP = RDoc ::Markup
15+
3516 attr_accessor :from_path
3617
3718 @@mutex = Mutex . new
@@ -63,8 +44,6 @@ def to_html
6344 private
6445
6546 # Fixes RDoc behaviour with ++ only supporting alphanumeric text.
66- #
67- # @todo Refactor into own SimpleMarkup subclass
6847 def fix_typewriter ( text )
6948 code_tags = 0
7049 text . gsub ( %r{<(/)?(pre|code|tt)|(\s |^|>)\+ (?! )([^\n \+ ]{1,900})(?! )\+ } ) do |str |
@@ -82,18 +61,27 @@ def fix_typewriter(text)
8261 end
8362 end
8463
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)
8965 def fix_dash_dash ( text )
9066 text . gsub ( /—(?=\S )/ , '--' )
9167 end
9268 end
9369
94- class RDocMarkupToHtml
70+ # Specialized ToHtml formatter for YARD
71+ #
72+ # @todo Refactor into own SimpleMarkup subclass
73+ class RDocMarkupToHtml < RDoc ::Markup ::ToHtml
9574 attr_accessor :from_path
9675
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+
9785 # Disable auto-link of URLs
9886 def handle_special_HYPERLINK ( special ) # rubocop:disable Style/MethodName
9987 @hyperlink ? special . text : super
0 commit comments