Created
March 15, 2011 00:18
-
-
Save bil-bas/870117 to your computer and use it in GitHub Desktop.
pry highlighting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process_comment_markup = lambda do |comment, code_type| | |
if Pry.color | |
comment.gsub!(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { CodeRay.scan($1, code_type).term } | |
{"(?:em|i)" => 32, "(?:strong|b)" => 34}.each_pair do |tag, color| | |
comment.gsub!(/<#{tag}>(?:\s*\n)?(.*?)\s*<\/#{tag}>/m) { console_colorize($1, color) } | |
end | |
{"\\+" => 34, "_" => 32}.each_pair do |tag, color| | |
comment.gsub!(/\B#{tag}[^\s]+?#{tag}\B/) { console_colorize($1, color) } | |
end | |
comment.gsub!(/((?:^[ \t]+.+(?:\n+|\Z)/) { CodeRay.scan($1, code_type).term } | |
end | |
comment | |
end | |
def console_colorize(string, color) | |
"\e[#{color}m#{string}\e[0m" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
irb(main):083:0> str = "--
irb(main):084:0" From Ruby Core (C Method):
irb(main):085:0" --
irb(main):086:0" Passes each entry in enum to block. Returns the
irb(main):087:0" first for which block is not false. If no
irb(main):088:0" object matches, calls ifnone and returns its result when it
irb(main):089:0" is specified, or returns nil
irb(main):090:0"
<.detect {|i| i % 5 == 0 and i % 7 == 0 } #=> nil
irb(main):092:0" (1..100).detect {|i| i % 5 == 0 and i % 7 == 0 } #=> 35
irb(main):093:0" "
=> "--\nFrom Ruby Core (C Method):\n--\nPasses each entry in enum to block. Retu
rns the\nfirst for which block is not false. If no\nobject matches, calls ifnon
e and returns its result when it\nis specified, or returns nil\n\n (1..10).det
ect {|i| i % 5 == 0 and i % 7 == 0 } #=> nil\n (1..100).detect {|i| i % 5 =
= 0 and i % 7 == 0 } #=> 35\n"
irb(main):094:0> str.gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { "[[#{$1}]]" }
=> "--\nFrom Ruby Core (C Method):\n--\nPasses each entry in enum to block. Retu
rns the\nfirst for which block is not false. If no\nobject matches, calls ifnon
e and returns its result when it\nis specified, or returns nil\n\n[[ (1..10).d
etect {|i| i % 5 == 0 and i % 7 == 0 } #=> nil\n (1..100).detect {|i| i % 5
== 0 and i % 7 == 0 } #=> 35\n]]"