Skip to content

Commit

Permalink
fix(email) insert carriage return at end of pars (#2331)
Browse files Browse the repository at this point in the history
  • Loading branch information
marwoodandrew authored Apr 5, 2022
1 parent 2b2a2f5 commit f3605e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
4 changes: 3 additions & 1 deletion superdesk/publish/formatters/email_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def format(self, article, subscriber, codes=None):
if formatted_article.get("dateline", {}).get("text"):
# If there is a dateline inject it into the body
self._inject_dateline(formatted_article)
doc["message_html"] = render_template("email_article_body.html", article=formatted_article)
doc["message_html"] = render_template("email_article_body.html", article=formatted_article).replace(
"</p>", "</p>\r"
)
else:
doc["message_html"] = None
doc["message_text"] = render_template("email_article_body.txt", article=formatted_article)
Expand Down
30 changes: 26 additions & 4 deletions tests/publish/formatters/email_formatter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_formatter(self):
"</b>&nbsp;take&nbsp;\n"
'<hr>\n<br><font color="red">Very good story</font>'
"<br>\n<i>Can of beans</i>\n<br>joe\n<br>\n"
"<p>BERN, July 13 - The story body of the story so far</p>\n<br>\n"
"<p>BERN, July 13 - The story body of the story so far</p>\r\n<br>\n"
"AAP&nbsp;aa/bb\n\n</body>\n</html>",
)
self.assertEqual(
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_no_place_formatter(self):
"</b>&nbsp;take&nbsp;\n"
'<hr>\n<br><font color="red">Very good story</font>'
"<br>\n<i>Can of beans</i>\n<br>joe\n<br>\n"
"<p>BERN, July 13 - The story body of the story so far</p>\n<br>\n"
"<p>BERN, July 13 - The story body of the story so far</p>\r\n<br>\n"
"AAP&nbsp;aa/bb\n\n</body>\n</html>",
)
self.assertEqual(
Expand Down Expand Up @@ -175,7 +175,7 @@ def test_none_place_formatter(self):
"</b>&nbsp;take&nbsp;\n"
'<hr>\n<br><font color="red">Very good story</font>'
"<br>\n<i>Can of beans</i>\n<br>joe\n<br>\n"
"<p>BERN, July 13 - The story body of the story so far</p>\n<br>\n"
"<p>BERN, July 13 - The story body of the story so far</p>\r\n<br>\n"
"AAP&nbsp;aa/bb\n\n</body>\n</html>",
)
self.assertEqual(
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_none_takekey_ednote(self):
"Published At : Fri Jan 30 03:40:56 2015\n<br>\n<b>slugline"
"</b>&nbsp;\n<hr>\n"
"\n<i>Can of beans</i>\n<br>joe\n<br>\n"
"<p>BERN, July 13 - The story body of the story so far</p>\n<br>\n"
"<p>BERN, July 13 - The story body of the story so far</p>\r\n<br>\n"
"AAP&nbsp;aa/bb\n\n</body>\n</html>",
)
self.assertEqual(
Expand Down Expand Up @@ -313,3 +313,25 @@ def test_featuremedia(self):
seq, doc = self.formatter.format(article, {"name": "Test Subscriber"})[0]
item = json.loads(doc)
self.assertEqual(item["renditions"]["viewImage"]["media"], "5c11ece81d41c89113ed202b")

def test_unbroken_html(self):
article = {
"source": "AAP",
"anpa_take_key": "take",
"subject": [{"qcode": "02011001"}],
"format": "HTML",
"type": "text",
"body_html": "<p>abcdefghijklmnopqrstuvwxyz</p>" * 2,
"word_count": "1",
"priority": 1,
"place": [{"qcode": "VIC", "name": "VIC"}],
"genre": [],
"sign_off": "aa/bb",
}
article["versioncreated"] = datetime.datetime(
year=2017, month=2, day=24, hour=16, minute=40, second=56, tzinfo=utc
)
seq, doc = self.formatter.format(article, {"name": "Test Subscriber"})[0]

item = json.loads(doc)
self.assertIn("<p>abcdefghijklmnopqrstuvwxyz</p>\r\n", item.get("message_html"))

0 comments on commit f3605e3

Please sign in to comment.