summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2021-04-11 00:54:01 +0300
committerKyrylo Silin <silin@kyrylo.org>2021-04-11 01:02:59 +0300
commit54617a7de471e009eadd0189d88913c205c2c365 (patch)
tree51e833efde32201dceb2d037303aa6ae1f6db90c /lib
parent033f69b3afcce57ed8d8b68f297457d1a80b1e6c (diff)
downloadpry-54617a7de471e009eadd0189d88913c205c2c365.tar.gz
helpers/documentation: don't colorize twice
Fixes #2181 (Bad formatting) One of the regexps matches against string that were already colored. To prevent that I used a negative look-ahead and rejected color sequences.
Diffstat (limited to 'lib')
-rw-r--r--lib/pry/helpers/documentation_helpers.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/pry/helpers/documentation_helpers.rb b/lib/pry/helpers/documentation_helpers.rb
index 1ce6be2b..024e1477 100644
--- a/lib/pry/helpers/documentation_helpers.rb
+++ b/lib/pry/helpers/documentation_helpers.rb
@@ -17,12 +17,13 @@ class Pry
last_match_ruby = proc do
SyntaxHighlighter.highlight(Regexp.last_match(1))
end
+
comment.gsub(%r{<code>(?:\s*\n)?(.*?)\s*</code>}m, &last_match_ruby)
.gsub(%r{<em>(?:\s*\n)?(.*?)\s*</em>}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
.gsub(%r{<i>(?:\s*\n)?(.*?)\s*</i>}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
.gsub(%r{<tt>(?:\s*\n)?(.*?)\s*</tt>}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