pentacent / keila

Open Source Newsletter Tool.
https://keila.io
GNU Affero General Public License v3.0
1.25k stars 61 forks source link

Block editor - Layout breaks - updated with possible solutions #265

Open vzsi opened 5 months ago

vzsi commented 5 months ago

The multi column layout breaks if the DIV-s of the two columns are separeted with a new line.

See the exampes bellow.

Following is a HTML showing different scenarios.

TSZ5.html.txt

Our institue uses Exchange SMTP to send and Outlook/OWA to read emails. Exchange and Outlook seems to be changing the HTML structure, OWA strips out comments, thus displaying improper layout.

I have no idea what's going on, this should not happen, but it does.

Tested with the same results with

2024-01-24_10h20_56

Here are some different scenarios:

Broken layout

                <div style="display:inline-block; max-width: 227px; min-width:227px; vertical-align:top; width:100%;" class="stack-column col-1">
                        <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
                            <tr class="block block--image ">
                                <td style="padding:0 20px;line-height:1;mso-line-height-rule:exactly;padding-right:10px">
                                    <img src="https://keila.torokszilvi.com/r/https%253A%252F%252Fwww.uni-nke.hu%252Fimage%252Funi-nke-hu%252FDepositphotos_36168269_S.jpg/nmr_eLJ23nLY/0SB4adrQgzGiAgPh1zCIbFGGDdRGM8SUYg75RK9iuJ4" width="100%" alt="" title="" border="0" style="display:block; max-width:100%!important; height: auto!important;" class="g-img"/>
                                </td>
                            </tr>
                        </table>
/// PROBLEM AREA START
                </div>
                <div style="display:inline-block; max-width: 453px; min-width:453px; vertical-align:top;" class="stack-column col-2">
/// PROBLEM AREA END
                        <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
                            <tr class="block block--heading">
                                <td style="padding:0 20px;line-height:28px;mso-line-height-rule:exactly;padding-left:10px">
                                    <h2 style="font-size:25px;line-height:33px;font-weight:bold;color:#333333;mso-line-height-rule:exactly;margin:0">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h2>
                                </td>
                            </tr>
                            <tr class="block block--paragraph">
                                <td style="padding:0 20px;line-height:28px;mso-line-height-rule:exactly;padding-top:10px!important;padding-left:10px">
                                    <p style="margin:0">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed iaculis urna interdum elit imperdiet, et rhoncus turpis congue.</p>
                                </td>
                            </tr>
                            <tr class="block block--button">
                                <td style="padding:0 20px;line-height:28px;mso-line-height-rule:exactly;padding-top:20px;padding-left:10px">
                                    <table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" style="margin: auto;width: 100%;">
                                        <tr>
                                            <td class="button-td button-td-primary" style="background-color:#1d4ed8;display:block;cursor:pointer;text-align:center;border-radius:5px;margin:20px 0">
                                                <a class="button-a button-a-primary" href="https://keila.torokszilvi.com/c/https%253A%252F%252Fwww.uni-nke.hu%252F/nmr_eLJ23nLY/ntl_xogqP2V2/ih_uvQcFZpvkiWoPpOxvlhy158WTB0AmNDsbRX-9URE" style="color:#ffffff;text-decoration:none;display:block;padding:13px 17px;font-size:15px;line-height:15px">Tovább</a>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </div>

Working HTML

                <div style="display:inline-block; max-width: 227px; min-width:227px; vertical-align:top; width:100%;" class="stack-column col-1">
                        <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
                            <tr class="block block--image ">
                                <td style="padding:0 20px;line-height:1;mso-line-height-rule:exactly;padding-right:10px">
                                    <img src="https://keila.torokszilvi.com/r/https%253A%252F%252Fwww.uni-nke.hu%252Fimage%252Funi-nke-hu%252FDepositphotos_36168269_S.jpg/nmr_eLJ23nLY/0SB4adrQgzGiAgPh1zCIbFGGDdRGM8SUYg75RK9iuJ4" width="100%" alt="" title="" border="0" style="display:block; max-width:100%!important; height: auto!important;" class="g-img"/>
                                </td>
                            </tr>
                        </table>
/// PROBLEM AREA START
                </div><!--[if mso]>
                            </td>
                            <td valign="top" width="453" style="width: 453px;">
<![endif]--><div style="display:inline-block; max-width: 453px; min-width:453px; vertical-align:top;" class="stack-column col-2">
/// PROBLEM AREA END
                        <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
                            <tr class="block block--heading">
                                <td style="padding:0 20px;line-height:28px;mso-line-height-rule:exactly;padding-left:10px">
                                    <h2 style="font-size:25px;line-height:33px;font-weight:bold;color:#333333;mso-line-height-rule:exactly;margin:0">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h2>
                                </td>
                            </tr>
                            <tr class="block block--paragraph">
                                <td style="padding:0 20px;line-height:28px;mso-line-height-rule:exactly;padding-top:10px!important;padding-left:10px">
                                    <p style="margin:0">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed iaculis urna interdum elit imperdiet, et rhoncus turpis congue.</p>
                                </td>
                            </tr>
                            <tr class="block block--button">
                                <td style="padding:0 20px;line-height:28px;mso-line-height-rule:exactly;padding-top:20px;padding-left:10px">
                                    <table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" style="margin: auto;width: 100%;">
                                        <tr>
                                            <td class="button-td button-td-primary" style="background-color:#1d4ed8;display:block;cursor:pointer;text-align:center;border-radius:5px;margin:20px 0">
                                                <a class="button-a button-a-primary" href="https://keila.torokszilvi.com/c/https%253A%252F%252Fwww.uni-nke.hu%252F/nmr_eLJ23nLY/ntl_xogqP2V2/ih_uvQcFZpvkiWoPpOxvlhy158WTB0AmNDsbRX-9URE" style="color:#ffffff;text-decoration:none;display:block;padding:13px 17px;font-size:15px;line-height:15px">Tovább</a>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </div>

Also working HTML

                <div style="display:inline-block; max-width: 227px; min-width:227px; vertical-align:top; width:100%;" class="stack-column col-1">
                        <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
                            <tr class="block block--image ">
                                <td style="padding:0 20px;line-height:1;mso-line-height-rule:exactly;padding-right:10px">
                                    <img src="https://keila.torokszilvi.com/r/https%253A%252F%252Fwww.uni-nke.hu%252Fimage%252Funi-nke-hu%252FDepositphotos_36168269_S.jpg/nmr_eLJ23nLY/0SB4adrQgzGiAgPh1zCIbFGGDdRGM8SUYg75RK9iuJ4" width="100%" alt="" title="" border="0" style="display:block; max-width:100%!important; height: auto!important;" class="g-img"/>
                                </td>
                            </tr>
                        </table>
/// PROBLEM AREA START
                </div><div style="display:inline-block; max-width: 453px; min-width:453px; vertical-align:top;" class="stack-column col-2">
/// PROBLEM AREA END
                        <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
                            <tr class="block block--heading">
                                <td style="padding:0 20px;line-height:28px;mso-line-height-rule:exactly;padding-left:10px">
                                    <h2 style="font-size:25px;line-height:33px;font-weight:bold;color:#333333;mso-line-height-rule:exactly;margin:0">Lorem ipsum dolor sit amet, consectetur adipiscing elit</h2>
                                </td>
                            </tr>
                            <tr class="block block--paragraph">
                                <td style="padding:0 20px;line-height:28px;mso-line-height-rule:exactly;padding-top:10px!important;padding-left:10px">
                                    <p style="margin:0">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed iaculis urna interdum elit imperdiet, et rhoncus turpis congue.</p>
                                </td>
                            </tr>
                            <tr class="block block--button">
                                <td style="padding:0 20px;line-height:28px;mso-line-height-rule:exactly;padding-top:20px;padding-left:10px">
                                    <table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" style="margin: auto;width: 100%;">
                                        <tr>
                                            <td class="button-td button-td-primary" style="background-color:#1d4ed8;display:block;cursor:pointer;text-align:center;border-radius:5px;margin:20px 0">
                                                <a class="button-a button-a-primary" href="https://keila.torokszilvi.com/c/https%253A%252F%252Fwww.uni-nke.hu%252F/nmr_eLJ23nLY/ntl_xogqP2V2/ih_uvQcFZpvkiWoPpOxvlhy158WTB0AmNDsbRX-9URE" style="color:#ffffff;text-decoration:none;display:block;padding:13px 17px;font-size:15px;line-height:15px">Tovább</a>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </div>
vzsi commented 5 months ago

Me

why are the followings rendering differently:

1.

<div style="display:inline-block">
</div><div style="display:inline-block">
</div>

2.

<div style="display:inline-block">
</div>
<div style="display:inline-block">
</div>

ChatGPT

The difference in rendering between these two HTML snippets is related to the display: inline-block; style and how browsers handle whitespace between inline-level elements.

  1. In the first case:

    <div style="display:inline-block">
    </div><div style="display:inline-block">
    </div>

    The two <div> elements with display: inline-block; are placed directly next to each other without any whitespace or newline characters between them. Inline-block elements are similar to inline elements in that they are laid out in the same line, but they also respect width and height properties like block elements. Since there's no whitespace or newline between these elements, they are rendered adjacent to each other with no space in between.

  2. In the second case:

    phpCopy code

    <div style="display:inline-block">
    </div>
    <div style="display:inline-block">
    </div>

    Here, there is a newline character (and possibly other whitespace) between the two <div> elements. When rendering inline or inline-block elements, most browsers treat whitespace (including newlines) in the HTML source as a single space character in the rendered output. This means that in this second case, there will be a small space between the two <div> elements, similar to the space you would see between words in a paragraph or between inline elements like <span>.

The size of this space can vary based on the font size and other styling but is typically about the same width as a single character space in the font being used. This spacing can be significant when arranging inline-block elements, especially in layouts where precise alignment is required.

It's important to note that this behavior is specific to inline-level elements (like those with display: inline; or display: inline-block;). Block-level elements (like those with display: block;) do not exhibit this behavior because they are rendered on new lines by default, and whitespace between block-level elements is generally collapsed.

vzsi commented 5 months ago

Using Flexbox could solve this issue.

<div style="display: flex;">
    <div style="display:inline-block;">
    </div>
    <div style="display:inline-block;">
    </div>
</div>

Or setting the font size to 0 hack.


<div style="font-size: 0;">
    <div style="display:inline-block;">
    </div>
    <div style="display:inline-block;">
    </div>
</div>
wmnnd commented 4 months ago

Hey @vzsi, thank you for taking the time to report and investigate this.

I’m currently trying to understand how exactly you ended up with the broken Markup. When I build the same layout you have there (1-2 layout blocks separated by separator blocks), I don’t get the newline in my markup that seems to break things.

Are you saying that it's your SMTP server that is modifying your HTML?