Skip to content

Commit 732a930

Browse files
authored
Merge pull request #2182 from pry/2181-doc-formatting-fix
helpers/documentation: don't colorize twice
2 parents 033f69b + 54617a7 commit 732a930

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
### master
22

3+
#### Bug fixes
4+
5+
* Fixed bad coloring of some RDoc-style docs
6+
(([#2182](https://github.com/pry/pry/pull/2182))
7+
38
### [v0.14.0][v0.14.0] (February 8, 2021)
49

510
#### Features

lib/pry/helpers/documentation_helpers.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ def process_rdoc(comment)
1717
last_match_ruby = proc do
1818
SyntaxHighlighter.highlight(Regexp.last_match(1))
1919
end
20+
2021
comment.gsub(%r{<code>(?:\s*\n)?(.*?)\s*</code>}m, &last_match_ruby)
2122
.gsub(%r{<em>(?:\s*\n)?(.*?)\s*</em>}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
2223
.gsub(%r{<i>(?:\s*\n)?(.*?)\s*</i>}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
2324
.gsub(%r{<tt>(?:\s*\n)?(.*?)\s*</tt>}m, &last_match_ruby)
2425
.gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{Regexp.last_match(1)}\e[0m" }
25-
.gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/, &last_match_ruby)
26+
.gsub(/((?:^[ \t]+(?:(?!.+\e\[)).+(?:\n+|\Z))+)/, &last_match_ruby)
2627
.gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{last_match_ruby.call}`" }
2728
end
2829

spec/documentation_helper_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,9 @@
7272
it "should not remove ++" do
7373
expect(@helper.process_rdoc("--\n comment in a bubble\n++")).to match(/\+\+/)
7474
end
75+
76+
it "should not syntax highlight already highlighted code" do
77+
expect(@helper.process_rdoc(" \e\[31mFOO\e\[0m")).to match(/ \e\[31mFOO\e\[0m/)
78+
end
7579
end
7680
end

0 commit comments

Comments
 (0)