mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Fixed leading/trailing HR removal when rendering email content
refs https://github.com/TryGhost/Team/issues/1007 - `:root` selector wasn't working as expected and ended up matching HRs within content - switched to wrapping the post html inside a `<body>` element before parsing so that we have a proper top-level element for direct child selectors to match against
This commit is contained in:
parent
946ae43a15
commit
413b06d1b5
1 changed files with 9 additions and 4 deletions
|
@ -220,11 +220,16 @@ 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);
|
||||
// body wrapper is required so we can get proper top-level selections
|
||||
let _cheerio = cheerio.load(`<body>${post.html}</body>`);
|
||||
// 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();
|
||||
_cheerio(`
|
||||
body > hr:first-child,
|
||||
body > hr:last-child,
|
||||
body > div:first-child > hr:first-child,
|
||||
body > div:last-child > hr:last-child
|
||||
`).remove();
|
||||
post.html = _cheerio('body').html();
|
||||
|
||||
post.plaintext = htmlToPlaintext(post.html);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue