Skip to content

Commit

Permalink
Highlight code in comments as ruby regardless
Browse files Browse the repository at this point in the history
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
ConradIrwin committed Jul 9, 2012
1 parent bd0df7b commit 4bcabfa
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/pry/default_commands/editing.rb
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/default_commands/gist.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/default_commands/introspection.rb
Expand Up @@ -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}"
Expand Down
12 changes: 6 additions & 6 deletions lib/pry/helpers/documentation_helpers.rb
Expand Up @@ -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)
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/pry/wrapped_module.rb
Expand Up @@ -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
Expand Down

0 comments on commit 4bcabfa

Please sign in to comment.