Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helpers/documentation: don't colorize twice #2182

Merged
merged 1 commit into from Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions 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
Expand Down
3 changes: 2 additions & 1 deletion lib/pry/helpers/documentation_helpers.rb
Expand Up @@ -17,12 +17,13 @@ def process_rdoc(comment)
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

Expand Down
4 changes: 4 additions & 0 deletions spec/documentation_helper_spec.rb
Expand Up @@ -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