Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/ts/components/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const htmlInsertFormatting = (str: string): string => {
return str
.replace(/^(.*:)\s/, "<strong>$1</strong>\n")
.replace(/\n(.*:)\s/, "<br /><strong>$1</strong>\n")
.replace(/\s*\n/g, "<br />");
.replace(/\s*\n/g, " <br />");
};

// Strips off trailing periods of URLs (i guess the regex above matches the period if the URL is at the end of the sentence.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ exports[`it renders 1`] = `
<div
dangerouslySetInnerHTML={
Object {
"__html": "<strong>Affected direction:</strong><br />Inbound<br />
<br /><strong>Affected stops:</strong><br />Meridian St @ West Eagle St",
"__html": "<strong>Affected direction:</strong> <br />Inbound <br />
<br /><strong>Affected stops:</strong> <br />Meridian St @ West Eagle St",
}
}
/>
Expand Down
4 changes: 2 additions & 2 deletions lib/dotcom_web/views/alert_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ defmodule DotcomWeb.AlertView do
# an initial header
|> String.replace(~r/^(.*:)(\r\n|\r|\n)/, "<strong>\\1</strong>\n")
# all other start with a line break
|> String.replace(~r/\n(.*:)(\r\n|\r|\n)/, "<br /><strong>\\1</strong>\n")
|> String.replace(~r/\s*\n/s, "<br />")
|> String.replace(~r/\n(.*:)(\r\n|\r|\n)/, " <br /><strong>\\1</strong>\n")
|> String.replace(~r/\s*\n/s, " <br />")
|> replace_urls_with_links
end

Expand Down
10 changes: 5 additions & 5 deletions test/dotcom_web/views/alert_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,35 @@ defmodule DotcomWeb.AlertViewTest do
end

test "replaces newlines with breaks" do
expected = {:safe, "hi<br />there"}
expected = {:safe, "hi <br />there"}
actual = format_alert_description("hi\nthere")

assert expected == actual
end

test "combines multiple newlines" do
expected = {:safe, "hi<br />there"}
expected = {:safe, "hi <br />there"}
actual = format_alert_description("hi\n\n\nthere")

assert expected == actual
end

test "combines multiple Windows newlines" do
expected = {:safe, "hi<br />there"}
expected = {:safe, "hi <br />there"}
actual = format_alert_description("hi\r\n\r\nthere")

assert expected == actual
end

test "<strong>ifies a header" do
expected = {:safe, "hi<br /><strong>Header:</strong><br />7:30"}
expected = {:safe, "hi <br /><strong>Header:</strong> <br />7:30"}
actual = format_alert_description("hi\nHeader:\n7:30")

assert expected == actual
end

test "<strong>ifies a starting long header" do
expected = {:safe, "<strong>Long Header:</strong><br />7:30"}
expected = {:safe, "<strong>Long Header:</strong> <br />7:30"}
actual = format_alert_description("Long Header:\n7:30")

assert expected == actual
Expand Down
Loading