Created
April 9, 2014 23:45
-
-
Save somatonic/10330802 to your computer and use it in GitHub Desktop.
Fix TinyMCE   chars, leaving those without a space in front intact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* TinyMCE replace nbsp with regular whitespace | |
* | |
* Only nbsp preceeded with a whitespace will get replaced, this leaves | |
* single non breaking space only bewtween words | |
* | |
* ProcessWire 2.x | |
* Copyright (C) 2012 by Ryan Cramer | |
* Licensed under GNU/GPL v2, see LICENSE.TXT | |
* | |
* http://www.processwire.com | |
* http://www.ryancramer.com | |
* | |
*/ | |
class TextareaStripNbsp extends WireData implements Module{ | |
public static function getModuleInfo() { | |
return array( | |
'title' => 'Unicode   (x00a0) Stripper', | |
'version' => 100, | |
'summary' => "Replaces the Unicode non-breaking space character /\s\x{00a0}/u with a regular space for all InputfieldTinyMCE when saving.", | |
'autoload' => true | |
); | |
} | |
public function init(){ | |
$this->addHookAfter('InputfieldTinyMCE::processInput', $this, 'hookFixNBSP'); | |
} | |
public function hookFixNBSP(HookEvent $event){ | |
$value = $event->object->value; | |
// replace only nbsp with a preceeding space | |
// this ensures nbsp to not wrap words still works | |
$value = trim( preg_replace('/\s\x{00a0}/siu', " ", $value) ); | |
$event->object->value = $value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment