summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2021-04-11 01:03:12 +0300
committerGitHub <noreply@github.com>2021-04-11 01:03:12 +0300
commit732a93074ad7a53cc7edd4eebb037acf8a9ef9d2 (patch)
tree51e833efde32201dceb2d037303aa6ae1f6db90c
parent033f69b3afcce57ed8d8b68f297457d1a80b1e6c (diff)
parent54617a7de471e009eadd0189d88913c205c2c365 (diff)
downloadpry-732a93074ad7a53cc7edd4eebb037acf8a9ef9d2.tar.gz
Merge pull request #2182 from pry/2181-doc-formatting-fix
helpers/documentation: don't colorize twice
-rw-r--r--CHANGELOG.md5
-rw-r--r--lib/pry/helpers/documentation_helpers.rb3
-rw-r--r--spec/documentation_helper_spec.rb4
3 files changed, 11 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f3d6e4c5..1abf18ac 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 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
diff --git a/spec/documentation_helper_spec.rb b/spec/documentation_helper_spec.rb
index 8da62a29..715e101d 100644
--- a/spec/documentation_helper_spec.rb
+++ b/spec/documentation_helper_spec.rb
@@ -72,5 +72,9 @@ describe Pry::Helpers::DocumentationHelpers do
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