diff --git a/CHANGELOG.md b/CHANGELOG.md index f3d6e4c5c..1abf18ac5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ### master +#### Bug fixes + +* Fixed bad coloring of some RDoc-style docs + (([#2182](https://github.com/pry/pry/pull/2182)) + ### [v0.14.0][v0.14.0] (February 8, 2021) #### Features diff --git a/lib/pry/helpers/documentation_helpers.rb b/lib/pry/helpers/documentation_helpers.rb index 1ce6be2b0..024e14776 100644 --- a/lib/pry/helpers/documentation_helpers.rb +++ b/lib/pry/helpers/documentation_helpers.rb @@ -17,12 +17,13 @@ def process_rdoc(comment) last_match_ruby = proc do SyntaxHighlighter.highlight(Regexp.last_match(1)) end + comment.gsub(%r{(?:\s*\n)?(.*?)\s*}m, &last_match_ruby) .gsub(%r{(?:\s*\n)?(.*?)\s*}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" } .gsub(%r{(?:\s*\n)?(.*?)\s*}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" } .gsub(%r{(?:\s*\n)?(.*?)\s*}m, &last_match_ruby) .gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{Regexp.last_match(1)}\e[0m" } - .gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/, &last_match_ruby) + .gsub(/((?:^[ \t]+(?:(?!.+\e\[)).+(?:\n+|\Z))+)/, &last_match_ruby) .gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{last_match_ruby.call}`" } end diff --git a/spec/documentation_helper_spec.rb b/spec/documentation_helper_spec.rb index 8da62a294..715e101dd 100644 --- a/spec/documentation_helper_spec.rb +++ b/spec/documentation_helper_spec.rb @@ -72,5 +72,9 @@ it "should not remove ++" do expect(@helper.process_rdoc("--\n comment in a bubble\n++")).to match(/\+\+/) end + + it "should not syntax highlight already highlighted code" do + expect(@helper.process_rdoc(" \e\[31mFOO\e\[0m")).to match(/ \e\[31mFOO\e\[0m/) + end end end