lib/yard/templates/helpers/html_helper.rb in yard-0.6.4 vs lib/yard/templates/helpers/html_helper.rb in yard-0.6.5
- old
+ new
@@ -5,12 +5,10 @@
# The helper module for HTML templates.
module HtmlHelper
include MarkupHelper
include HtmlSyntaxHighlightHelper
- SimpleMarkupHtml = RDoc::Markup::ToHtml.new rescue SM::ToHtml.new
-
# @group Escaping Template Data
# Escapes HTML entities
#
# @param [String] text the text to escape
@@ -78,12 +76,12 @@
# @param [String] text the input RDoc formatted text
# @return [String] output HTML
# @since 0.6.0
def html_markup_rdoc(text)
begin
- SimpleMarkupHtml.instance_variable_set("@from_path", url_for(object))
- html = MarkupHelper::SimpleMarkup.convert(text, SimpleMarkupHtml)
+ simple_markup_html.instance_variable_set("@from_path", url_for(object))
+ html = markup_class(:rdoc).new.convert(text, simple_markup_html)
end
html = fix_dash_dash(html)
html = fix_typewriter(html)
end
@@ -111,15 +109,15 @@
# Fixes RDoc behaviour with ++ only supporting alphanumeric text.
#
# @todo Refactor into own SimpleMarkup subclass
def fix_typewriter(text)
- text.gsub(/\+(?! )([^\n\+]{1,900})(?! )\+/) do
- type_text, pre_text, no_match = $1, $`, $&
- pre_match = pre_text.scan(%r(</?(?:pre|tt|code).*?>))
- if pre_match.last.nil? || pre_match.last.include?('/')
- '<tt>' + h(type_text) + '</tt>'
+ text.gsub(/(\s|^|>)\+(?! )([^\n\+]{1,900})(?! )\+/) do
+ first_text, type_text, pre_text, no_match = $1, $2, $`, $&
+ pre_match = (pre_text+first_text).scan(%r(</?(?:(?:pre|tt|code).*?>|[^>]+)\Z))
+ if pre_match.last.nil? || pre_match.last[1,1] == '/'
+ first_text + '<tt>' + h(type_text) + '</tt>'
else
no_match
end
end
end
@@ -445,9 +443,24 @@
end
# @endgroup
private
+
+ # Gets the SimpleMarkup class for the local thread
+ #
+ # @return [RDoc::Markup::ToHtml] if RDoc 2.x is loaded
+ # @return [SM::ToHtml] if RDoc 1.x is loaded
+ # @since 0.6.5
+ def simple_markup_html
+ begin
+ require 'rdoc/markup/to_html'
+ rescue LoadError
+ require 'rdoc/markup/simple_markup/to_html'
+ end
+ Thread.current[:__yard_simple_markup_html__] ||=
+ (RDoc::Markup::ToHtml.new rescue SM::ToHtml.new)
+ end
# Converts a set of hash options into HTML attributes for a tag
#
# @param [Hash{String => String}] opts the tag options
# @return [String] the tag attributes of an HTML tag