Skip to content

Commit

Permalink
Don't treat asterisks in list items as italic in Markdown
Browse files Browse the repository at this point in the history
Fixes an issue where asterisks used for list items were converted to
underscores.
  • Loading branch information
rspeicher committed Nov 7, 2024
1 parent f37c511 commit 168382b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* [#525](https://github.com/slack-ruby/slack-ruby-client/pull/525): Exclude spec files from gem package - [@amatsuda](https://github.com/amatsuda).
* [#527](https://github.com/slack-ruby/slack-ruby-client/pull/527): Explicitly require `racc` and `ostruct` - [@dblock](https://github.com/dblock).
* [#528](https://github.com/slack-ruby/slack-ruby-client/pull/528): Don't treat asterisks in list items as italic in markdown - [@rspeicher](https://github.com/rspeicher).
* Your contribution here.

### 2.4.0 (2024/07/14)
Expand Down
2 changes: 1 addition & 1 deletion lib/slack/messages/formatting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def url_link(text, url)
#
def markdown(text)
text
.gsub(/(?<!\*)\*([^*]+)\*(?!\*)/, '_\1_') # italic
.gsub(/(?<!\*)\*([^*\n]+)\*(?!\*)/, '_\1_') # italic
.gsub(/\*\*\*(.*?)\*\*\*/, '*_\1_*') # bold & italic
.gsub(/\*\*(.*?)\*\*/, '*\1*') # bold
.gsub(/~~(.*?)~~/, '~\1~') # strikethrough
Expand Down
12 changes: 12 additions & 0 deletions spec/slack/messages/formatting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@
)
end

it "doesn't treat list items as text formatting" do
msg = <<~MSG
Une liste:
* Article 1
* Article 2
* Article 3
MSG

expect(formatting.markdown(msg)).to eq msg
end

it "doesn't format other markdown" do
expect(formatting.markdown('## A heading\n_Italics_\n`code`')).to eq '## A heading\n_Italics_\n`code`'
end
Expand Down

0 comments on commit 168382b

Please sign in to comment.