From 946ae43a153334cba4c54da8f9d9bf73251d8e1c Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 24 Aug 2021 19:38:29 +0100 Subject: [PATCH] Removed leading/trailing HR's when rendering email content refs https://github.com/TryGhost/Team/issues/1007 - the new `email-cta` card allows surrounding dividers to be added when rendering, however if the card is at the beginning or end of the post then these would double-up with the already existing dividers at the beginning and end of the post content in the email template - not wanting leading/trailing HR's is specific to the email template so it made sense to adjust the renderer output in Ghost's email generating rather than forcing all mobiledoc->html rendering to remove leading/trailing HR's --- core/server/services/mega/post-email-serializer.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/server/services/mega/post-email-serializer.js b/core/server/services/mega/post-email-serializer.js index 2c7bdd01dd..aca097f70d 100644 --- a/core/server/services/mega/post-email-serializer.js +++ b/core/server/services/mega/post-email-serializer.js @@ -218,6 +218,14 @@ const serialize = async (postModel, options = {isBrowserPreview: false, apiVersi } post.html = mobiledocLib.mobiledocHtmlRenderer.render(JSON.parse(post.mobiledoc), {target: 'email'}); + + // perform any email specific adjustments to the mobiledoc->HTML render output + let _cheerio = cheerio.load(post.html); + // remove leading/trailing HRs + _cheerio(':root > hr:first-child, :root > div:first-child > hr:first-child').remove(); + _cheerio(':root > hr:last-child, :root > div:last-child > hr:last-child').remove(); + post.html = _cheerio.html(); + post.plaintext = htmlToPlaintext(post.html); // Outlook will render feature images at full-size breaking the layout. @@ -268,7 +276,7 @@ const serialize = async (postModel, options = {isBrowserPreview: false, apiVersi // convert juiced HTML to a DOM-like interface for further manipulation // happens after inlining of CSS so we can change element types without worrying about styling - let _cheerio = cheerio.load(juicedHtml); + _cheerio = cheerio.load(juicedHtml); // force all links to open in new tab _cheerio('a').attr('target','_blank'); // convert figure and figcaption to div so that Outlook applies margins