Permalink
Browse files

Highlight code in comments as ruby regardless

Before this change, ? Array.try_convert would highlight the code
snippets as C, but because it's actually a ruby method all the code in
the comment is ruby.
  • Loading branch information...
1 parent bd0df7b commit 4bcabfad5d1a3ec309fed60629eb95c178065aba @ConradIrwin ConradIrwin committed Jul 9, 2012
@@ -366,7 +366,7 @@ def options(opt)
opt.on :d, :doc, "Play a method's documentation.", :argument => true do |meth_name|
meth = get_method_or_raise(meth_name, target, {})
text.no_color do
- self.content << process_comment_markup(meth.doc, :ruby)
+ self.content << process_comment_markup(meth.doc)
end
end
opt.on :c, :command, "Play a command's source.", :argument => true do |command_name|
@@ -40,7 +40,7 @@ def options(opt)
opt.on :d, :doc, "Gist a method's documentation.", :argument => true do |meth_name|
meth = get_method_or_raise(meth_name, target, {})
text.no_color do
- self.content << process_comment_markup(meth.doc, :plain) << "\n"
+ self.content << process_comment_markup(meth.doc) << "\n"
end
self.filename = meth.source_file + ".doc"
end
@@ -143,7 +143,7 @@ def all_modules
def process_method
raise Pry::CommandError, "No documentation found." if method_object.doc.nil? || method_object.doc.empty?
- doc = process_comment_markup(method_object.doc, method_object.source_type)
+ doc = process_comment_markup(method_object.doc)
output.puts make_header(method_object, doc)
output.puts "#{text.bold("Owner:")} #{method_object.owner || "N/A"}"
output.puts "#{text.bold("Visibility:")} #{method_object.visibility}"
@@ -4,14 +4,14 @@ module Helpers
# This class contains methods useful for extracting
# documentation from methods and classes.
module DocumentationHelpers
- def process_rdoc(comment, code_type)
+ def process_rdoc(comment)
comment = comment.dup
- comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
+ comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { Pry.color ? CodeRay.scan($1, :ruby).term : $1 }.
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { Pry.color ? "\e[1m#{$1}\e[0m": $1 }.
gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { Pry.color ? "\e[1m#{$1}\e[0m" : $1 }.
gsub(/\B\+(\w*?)\+\B/) { Pry.color ? "\e[32m#{$1}\e[0m": $1 }.
- gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { Pry.color ? CodeRay.scan($1, code_type).term : $1 }.
- gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{Pry.color ? CodeRay.scan($1, code_type).term : $1}`" }
+ gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { Pry.color ? CodeRay.scan($1, :ruby).term : $1 }.
+ gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{Pry.color ? CodeRay.scan($1, :ruby).term : $1}`" }
end
def process_yardoc_tag(comment, tag)
@@ -36,8 +36,8 @@ def process_yardoc(comment)
gsub(/^@(#{yard_tags.join("|")})/) { Pry.color ? "\e[33m#{$1}\e[0m": $1 }
end
- def process_comment_markup(comment, code_type)
- process_yardoc process_rdoc(comment, code_type)
+ def process_comment_markup(comment)
+ process_yardoc process_rdoc(comment)
end
# @param [String] code
@@ -280,8 +280,7 @@ def safe_send(obj, method, *args, &block)
# @param [String] doc The raw docstring to process.
# @return [String] Process docstring markup and strip leading white space.
def process_doc(doc)
- process_comment_markup(strip_leading_hash_and_whitespace_from_ruby_comments(doc),
- :ruby)
+ process_comment_markup(strip_leading_hash_and_whitespace_from_ruby_comments(doc))
end
end

0 comments on commit 4bcabfa

Please sign in to comment.