File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -25,10 +25,18 @@ def block_format(text)
25
25
} . join ( "\n \n " )
26
26
27
27
# Make list points stand on their own line
28
- formatted . gsub! ( /[ ]*([*]+) ([^*]*)/ ) { " #{ $1} #{ $2. strip } \n " }
29
- formatted . gsub! ( /[ ]*([#]+) ([^#]*)/ ) { " #{ $1} #{ $2. strip } \n " }
28
+ output = +""
29
+ splits = formatted . split ( /(\* +|\# +)/ )
30
+ while line = splits . shift
31
+ if line . start_with? ( "*" , "#" ) && splits . first &.start_with? ( " " )
32
+ output . chomp! ( " " ) while output . end_with? ( " " )
33
+ output << " #{ line } #{ splits . shift . strip } \n "
34
+ else
35
+ output << line
36
+ end
37
+ end
30
38
31
- formatted
39
+ output
32
40
end
33
41
34
42
# Access the mailer instance.
Original file line number Diff line number Diff line change @@ -121,4 +121,17 @@ def test_use_cache
121
121
assert_equal "Greetings from a cache helper block" , mail . body . encoded
122
122
end
123
123
end
124
+
125
+ def helper
126
+ Object . new . extend ( ActionMailer ::MailHelper )
127
+ end
128
+
129
+ def test_block_format
130
+ assert_equal " * foo\n " , helper . block_format ( " * foo" )
131
+ assert_equal " * foo\n " , helper . block_format ( " * foo" )
132
+ assert_equal " * foo\n " , helper . block_format ( "* foo" )
133
+ assert_equal " * foo\n *bar" , helper . block_format ( "* foo*bar" )
134
+ assert_equal " * foo\n * bar\n " , helper . block_format ( "* foo * bar" )
135
+ assert_equal " *" , helper . block_format ( "* " )
136
+ end
124
137
end
You can’t perform that action at this time.
0 commit comments