Skip to content

Commit 6b53aa6

Browse files
committed
Don't treat asterisks in list items as italic in Markdown
Fixes an issue where asterisks used for list items were converted to underscores.
1 parent f37c511 commit 6b53aa6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/slack/messages/formatting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def url_link(text, url)
7575
#
7676
def markdown(text)
7777
text
78-
.gsub(/(?<!\*)\*([^*]+)\*(?!\*)/, '_\1_') # italic
78+
.gsub(/(?<!\*)\*([^*\n]+)\*(?!\*)/, '_\1_') # italic
7979
.gsub(/\*\*\*(.*?)\*\*\*/, '*_\1_*') # bold & italic
8080
.gsub(/\*\*(.*?)\*\*/, '*\1*') # bold
8181
.gsub(/~~(.*?)~~/, '~\1~') # strikethrough

spec/slack/messages/formatting_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@
149149
)
150150
end
151151

152+
it "doesn't treat list items as text formatting" do
153+
msg = <<~MSG
154+
Une liste:
155+
156+
* Article 1
157+
* Article 2
158+
* Article 3
159+
MSG
160+
161+
expect(formatting.markdown(msg)).to eq msg
162+
end
163+
152164
it "doesn't format other markdown" do
153165
expect(formatting.markdown('## A heading\n_Italics_\n`code`')).to eq '## A heading\n_Italics_\n`code`'
154166
end

0 commit comments

Comments
 (0)