Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions lib/yard/templates/helpers/markup/rdoc_markdown.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# frozen_string_literal: true
gem 'rdoc', '>= 6.0'
require 'rdoc'
require 'rdoc/markdown'

module YARD
module Templates
module Helpers
module Markup
begin require 'rdoc'; rescue LoadError; nil end
begin
require 'rdoc/markdown'
rescue LoadError
raise NameError, "could not load RDoc Markdown support (rdoc is too old)"
end

class RDocMarkdown < RDocMarkup
def initialize(text)
super RDoc::Markdown.new.parse(text)
Expand Down
54 changes: 21 additions & 33 deletions lib/yard/templates/helpers/markup/rdoc_markup.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
# frozen_string_literal: true
require 'thread'

gem 'rdoc', '>= 6.0'
require 'rdoc'
require 'rdoc/markup'
require 'rdoc/markup/to_html'

module YARD
module Templates
module Helpers
module Markup
begin require 'rdoc'; rescue LoadError; nil end
begin
require 'rdoc/markup'
require 'rdoc/markup/to_html'
class RDocMarkup; MARKUP = RDoc::Markup end
class RDocMarkupToHtml < RDoc::Markup::ToHtml
if defined?(RDoc::VERSION) && RDoc::VERSION >= '4.0.0' &&
defined?(RDoc::Options)
def initialize
options = RDoc::Options.new
options.pipe = true
super(options)
end
end
end
rescue LoadError
begin
require 'rdoc/markup/simple_markup'
require 'rdoc/markup/simple_markup/to_html'
class RDocMarkup; MARKUP = SM::SimpleMarkup end
class RDocMarkupToHtml < SM::ToHtml; end
rescue LoadError
raise NameError, "could not load RDocMarkup (rdoc is not installed)"
end
end

class RDocMarkup
MARKUP = RDoc::Markup

attr_accessor :from_path

@@mutex = Mutex.new
Expand Down Expand Up @@ -63,8 +44,6 @@ def to_html
private

# Fixes RDoc behaviour with ++ only supporting alphanumeric text.
#
# @todo Refactor into own SimpleMarkup subclass
def fix_typewriter(text)
code_tags = 0
text.gsub(%r{<(/)?(pre|code|tt)|(\s|^|>)\+(?! )([^\n\+]{1,900})(?! )\+}) do |str|
Expand All @@ -82,18 +61,27 @@ def fix_typewriter(text)
end
end

# Don't allow -- to turn into &#8212; element. The chances of this being
# some --option is far more likely than the typographical meaning.
#
# @todo Refactor into own SimpleMarkup subclass
# Don't allow -- to turn into &#8212; element (em dash)
def fix_dash_dash(text)
text.gsub(/&#8212;(?=\S)/, '--')
end
end

class RDocMarkupToHtml
# Specialized ToHtml formatter for YARD
#
# @todo Refactor into own SimpleMarkup subclass
class RDocMarkupToHtml < RDoc::Markup::ToHtml
attr_accessor :from_path

def initialize
options = RDoc::Options.new
options.pipe = true
super(options)

# The hyperlink detection state
@hyperlink = false
end

# Disable auto-link of URLs
def handle_special_HYPERLINK(special) # rubocop:disable Style/MethodName
@hyperlink ? special.text : super
Expand Down
2 changes: 1 addition & 1 deletion yard.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.version = YARD::VERSION
s.author = "Loren Segal"
s.email = "[email protected]"
s.homepage = "http://yardoc.org"
s.homepage = "https://yardoc.org"
s.platform = Gem::Platform::RUBY
s.files = Dir['{lib,docs,po,templates}/**/*', '.yardopts*', 'CHANGELOG.md', 'LICENSE', 'LEGAL', 'README.md']
s.require_paths = ['lib']
Expand Down
Loading