Skip to content

Commit

Permalink
Merge pull request #528 from rspeicher/rs-asterisk-lists
Browse files Browse the repository at this point in the history
Don't treat asterisks in list items as italic in Markdown
  • Loading branch information
dblock authored Nov 7, 2024
2 parents f37c511 + 168382b commit 4d5d8da
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 4d5d8da

Please sign in to comment.