lib/yard/templates/helpers/html_helper.rb in yard-0.7.2 vs lib/yard/templates/helpers/html_helper.rb in yard-0.7.3
- old
+ new
@@ -42,14 +42,17 @@
if html.respond_to?(:encode)
html = html.force_encoding(text.encoding) # for libs that mess with encoding
html = html.encode(:invalid => :replace, :replace => '?')
end
html = resolve_links(html)
- html = html.gsub(/<pre>(?:\s*<code>)?(.+?)(?:<\/code>\s*)?<\/pre>/m) do
- str = $1
- str = html_syntax_highlight(CGI.unescapeHTML(str)) unless options[:no_highlight]
- %Q{<pre class="code">#{str}</pre>}
+ html = html.gsub(/<pre\s*(?:lang="(.+?)")?>(?:\s*<code>)?(.+?)(?:<\/code>\s*)?<\/pre>/m) do
+ language = $1
+ string = $2
+
+ string = html_syntax_highlight(CGI.unescapeHTML(string), language) unless options[:no_highlight]
+ classes = ['code', language].compact.join(' ')
+ %Q{<pre class="#{classes}">#{string}</pre>}
end unless markup == :text
html
end
# Converts Markdown to HTML
@@ -59,10 +62,12 @@
def html_markup_markdown(text)
# TODO: other libraries might be more complex
provider = markup_class(:markdown)
if provider.to_s == 'RDiscount'
markup_class(:markdown).new(text, :autolink).to_html
+ elsif provider.to_s == 'RedcarpetCompat'
+ provider.new(text, :gh_blockcode, :fenced_code).to_html
else
markup_class(:markdown).new(text).to_html
end
end
@@ -89,11 +94,11 @@
# Converts plaintext to HTML
# @param [String] text the input text
# @return [String] the output HTML
# @since 0.6.0
def html_markup_text(text)
- "<pre>" + text + "</pre>"
+ "<pre>" + h(text) + "</pre>"
end
# @return [String] the same text with no markup
# @since 0.6.6
def html_markup_none(text)
@@ -114,11 +119,11 @@
#
# @param [String] source the Ruby source
# @return [String] the highlighted HTML
# @since 0.7.0
def html_markup_ruby(source)
- '<pre class="code">' + html_syntax_highlight(source, :ruby) + '</pre>'
+ '<pre class="code ruby">' + html_syntax_highlight(source, :ruby) + '</pre>'
end
# @return [String] HTMLified text as a single line (paragraphs removed)
def htmlify_line(*args)
"<div class='inline'>" + htmlify(*args) + "</div>"
@@ -167,11 +172,11 @@
# resolve_links("{A::B::C the C class}") # => "<a href='...'>the c class</a>"
# @param [String] text the text to resolve links in
# @return [String] HTML with linkified references
def resolve_links(text)
code_tags = 0
- text.gsub(/<(\/)?(pre|code|tt)|(\\)?\{(?!\})(\S+?)(?:\s([^\}]*?\S))?\}(?=[\W<]|.+<\/|$)/m) do |str|
+ text.gsub(/<(\/)?(pre|code|tt)|(\\|!)?\{(?!\})(\S+?)(?:\s([^\}]*?\S))?\}(?=[\W<]|.+<\/|$)/m) do |str|
closed, tag, escape, name, title, match = $1, $2, $3, $4, $5, $&
if tag
code_tags += (closed ? -1 : 1)
next str
end
@@ -244,10 +249,10 @@
end
return title unless serializer
return title if obj.is_a?(CodeObjects::Proxy)
link = url_for(obj, anchor, relative)
- link = link ? link_url(link, title, :title => "#{obj.path} (#{obj.type})") : title
+ link = link ? link_url(link, title, :title => h("#{obj.path} (#{obj.type})")) : title
"<span class='object_link'>" + link + "</span>"
end
# (see BaseHelper#link_url)
def link_url(url, title = nil, params = {})