For years, users have complained about the inability to clean word formatting from summernote regions following a user pasting directly from word.
As with my image externalize extension, i have looked at recoding summernote.js without success.
Again i have going with a middleware approach
This extension is simple, just add a "Strip Word Formatting" step before saving to your database to have your output cleaned.
This uses a lot of regex and isnt 100% effective but it does do a pretty good job.
I hope, when i have time, to produce an App Connect version of this and perhaps key it in to the DOM "drop" event which i think would be more effctive but that will take a lot longer then the 45 minutes taken to make this!
If anyone else would like to try, feel free to grab the .js from "cleansn.js"
The Extension
The extension can be found here.
Installation Instructions:
Docker users may wish to read this:
On Installation, the extension can be found in the Summernote group
Usage
In this example i paste some word content into a summernote input
The code view shows the problem with word.
<p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:24.0pt;line-height:107%">Music Afternoon in aid of Tynedale
Hospice<o:p></o:p></span></p><p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:12.0pt;line-height:107%">We have arranged a charity event in
the garden <br>
<!--[if !supportLineBreakNewLine]--><br>
<!--[endif]--><o:p></o:p></span></p><p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:22.0pt;line-height:107%">Saturday 20<sup>th</sup> July at 3.00
pm<o:p></o:p></span></p><p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:12.0pt;line-height:107%">Featuring<o:p></o:p></span></p><p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:28.0pt;line-height:107%">LANDERMASON</span><span style="font-size:12.0pt;line-height:107%"> <o:p></o:p></span></p><p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:12.0pt;line-height:107%">Playing live.<o:p></o:p></span></p><p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:22.0pt;line-height:107%"> </span><span style="font-size:12.0pt;
line-height:107%">(landermason.com) <o:p></o:p></span></p><p class="MsoNormal" align="center" style="text-align:center"><span style="font-size:12.0pt;line-height:107%">Snacks and soft drinks will be
supplied free of charge, please bring your own wine / beer/ glasses. Please
bring your own chairs or blankets ifrequired. <o:p></o:p></span></p><p class="MsoNormal"><br></p><p><br></p><p><br></p>
I submit the content and process the input in an API action
saving the output of the "cleaner" action
a refresh on success at client level shows:
with nice clean code
<p align="center"><span>Music Afternoon in aid of Tynedale
Hospice</span></p><p align="center"><span>We have arranged a charity event in
the garden <br><br></span></p><p align="center"><span>Saturday 20<sup>th</sup> July at 3.00
pm</span></p><p align="center"><span>Featuring</span></p><p align="center"><span>LANDERMASON</span></p><p align="center"><span>Playing live.</span></p><p align="center"><span> </span><span>(landermason.com) </span></p><p align="center"><span>Snacks and soft drinks will be
supplied free of charge, please bring your own wine / beer/ glasses. Please
bring your own chairs or blankets ifrequired. </span></p><p><br></p><p><br></p><p><br></p>
Enjoy!