-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block vs Inline level elements and br tags #409
Comments
Just a quick update. I monkey patched Edit: If this would be valuable for others, I could look at doing a formal PR for this. |
If you dig deeper, people should NOT paste HTML. |
Yeah I understand that, but teach that to customers who want to add fancy email footers. I'd like to find a better solution for stripping/cleaning pasted HTML, but right now the best thing we've found is to put it into google docs and copy it from there. I haven't looked too hard at any 3rd party cleansing libraries just yet. |
You could start with: HTML = HTML
// Remove Microsoft Office styling
.replace(/(<[^>]+[;"'])\s*mso-[a-z-]+\s*:[^;"']+/gi, '$1')
// Remove hubspot data-hs- attributes
.replace(/(<[^>]+)\s+data-hs-[a-z-]+=("[^"]+"|'[^']+')/gi, '$1'); or // Drop Microsoft Office style properties
const rgbRE = /rgb\((\d+),\s*(\d+),\s*(\d+)\)/g,
hex = n => ('0' + parseInt(n).toString(16)).slice(-2);
body.querySelectorAll('[style*=mso]').forEach(el =>
el.setAttribute('style', el.style.cssText.replace(rgbRE, (m,r,g,b) => '#' + hex(r) + hex(g) + hex(b)))
); |
We've been using your editor for some time now. About a year ago, I even compared it to other HTML editors, and in terms of ease of use, consistency and maintainability, it still seemed to be better than the competition. So this issue/discussion below really pales in comparison to how well this has worked over the years.
Block vs Inline level elements and br tags
One issue we've had for quite some time though, has been with sometimes Squire adds spaces when pasting in HTML. I have looked through most of this repo's issues, but in case I missed a duplicate question feel free to let me know.
Our customer issue:
They often want fancy emails, so they copy/paste in HTML into the editor. At times, their HTML is setup so that
<img />
or<span>
tags (or other normally inline level elements) havedisplay:block
styles on them. I get it, email HTML is hard. Old legacy vs new shiny.Here is an example boiled down:
becomes
As you'd expect, there is an empty line between between Hello and world. Really, world should just be on the next line down.
Attempt at Patching
In particular, the
getNodeCategory
function here is not checking to see if it has astyle="display: block"
or something similar. I did quickly test this out:The immediate issue with this is with
<img />
, so I wasn't super impressed by this initial test. Not to mention this would change the entire behavior for anything that uses this function. However, it did seem to help in some scenarios, so maybe it's worth further discussion.Changing our usage
Rather than attempting to change how Squire works, maybe the better solution would be to change how we are using it?
display
styles when paste/setHTML?The text was updated successfully, but these errors were encountered: