We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36816
    • 109 Posts
    I'm leaving this here in the hope that it helps someone else; I spent quite a bit of time chasing my tail to figure it out.

    At least for the environment I'm using (below), TinyMCE insists on placing white space in empty table cells. I believe this is to allow various browsers to place the mouse cursor caret in the cell for editing.

    That's all well and good until content editors don't delete that white space when editing content, esp. right-aligned numeric content.

    My thought was that I'd just write up a MODX plugin to strip out that white space. What made it a challenge was that in this configuration, TinyMCE adds in a Unicode No-break space - U+00A0 - character, not an ordinary Latin-1 (or ASCII) character. They both look the same in a browser, so it was a head-scratcher to find out why my search/replace expressions didn't work.

    Here, for reference are two preg_replace expressions (I suspect there's a way to make it just one, but I didn't find it) that will strip table cells of leading & trailing regular spaces and various unicode spaces, including that inserted by TinyMCE into empty table cells.

    // Trim trailing table cell content whitespace. 
    $workingContent = preg_replace('/\p{Zs}*(<\/td>)/iu', '$1', $output);
        
    // Trim leading table cell content whitespace. 
    $workingContent = preg_replace('/(<td[^>]*>)\p{Zs}*/iu', '$1', $workingContent);
    


    The accepted answer in this StackOverflow discussion was helpful:
    http://stackoverflow.com/questions/3230623/filter-all-types-of-whitespace-in-php

    Environment
    MODX 2.2.2-pl
    Site content encoding: UTF-8
    TinyMCE 4.3.2