sleemanj / xinha

WYSIWYG HTML Editor Component (turns <textarea> into HTML editors)
http://trac.xinha.org/
Other
13 stars 2 forks source link

Fixed the core issue with HTML/WYSIWYG mode (removes the &nbsp; chars without other text) (Trac #1734) #1734

Closed kholub1989 closed 2 years ago

kholub1989 commented 2 years ago

Fixed a major problem when toggling, interacting, and pasting HTML code in WYSIWYG/HTML mode, the editor remove the &nbsp; without other text and replace it with " " string.

Code example for testing:

<p class="MsoNormal" style="padding: 0px; margin: 0in 0in 0.0001pt; font-size: medium; text-align: center;"><strong><font face="georgia, times new roman, times, serif">5121 Michigan Ave, Tipton, MI 49287</font></strong></p><p class="MsoNormal" style="padding: 0px; margin: 0in 0in 0.0001pt; font-size: medium; text-align: center;"><font face="georgia, times new roman, times, serif">&nbsp;</font></p><p class="MsoNormal" style="padding: 0px; margin: 0in 0in 0.0001pt; font-size: medium; text-align: center;"><font face="georgia, times new roman, times, serif"><strong>Directions:</strong>&nbsp;Take Michigan Ave (US-12) to Auction. The Auction is West of Clinton MI and East of Brooklyn and Onsted MI.&nbsp;&nbsp;Auction is on the South side of US 12 - look for signs. Tipton is located in the Irish Hills area.</font></p>

Solution:

+++ modules/GetHtml/DOMwalk.js 2022-03-24 07:24:21.010404643 -0400 -336,7 +336,16

{ if(root.data) { html = ' '; // [DC] Fix to replace 0xA0 and still trim whitespace only text. // This fixes dropped &nbsp; chars used without other text. if(root.data.replace(/\u00a0/g,'&nbsp;').includes('&nbsp;')) { html = root.data.replace(/\u00a0/g,'&nbsp;').trim(); } else { html = ' '; } } else {

DOMwalk js