开发者

CKEditor excessive formatting of plain text

The problem:

CKEditor is adding tons of <span> tags to plain text, such as the example below.

The code:

The setup is a php page, calling ckeditor and saving entries into a PostgreSQL table. I believe most settings on CKEditor is default. Here's some of the code:

include ('./ckeditor/ckeditor.php') ;
$CKEditor = new CKEditor() ;
$CKEditor->returnOutput = true;
$CKEditor->basePath = '/ckeditor/';
$CKEditor->config['width'] = 560;
$CKEditor->config['height'] = 300;
$CKEditor->textareaAttributes =
                array("cols" => 90, "rows" => 70);
$CKEditor->config['DefaultLanguage'] = "sv" ;
//$CKEditor->config['EnterMode'] = CKEDITOR.ENTER_BR;
$config['toolbar'] = array(
        array( 'Source', 开发者_开发技巧'-', 'Bold', 'Italic', 'Underline', 'Strike', '-' ),
        array( 'Image', 'Link', 'Unlink', '-', 'Table', 'NumberedList','BulletedList' )
);
$config['skin'] = 'v2';

Example input/output (in source):

The input:

En hel del av er

Becomes:

En <span data-scayt_word="hel" data-scaytid="2">hel</span> del 
<span data-scayt_word="av" data-scaytid="3">av</span> 
<span data-scayt_word="er" data-scaytid="4">er</span>

Is there a way to avoid this behaviour?


The easiest way: disable the spellchecker (scayt - spellcheck as you type)

$CKEditor->config['removePlugins'] ='scayt'; // comma separated if many

How to remove unused plugins

If you want to leave SCAYT available, but prevent the feature from being turned on automatically:

$CKEditor->config['scayt_autoStartup'] = false;

But this is strange behavior, how do you retrieves the content from ckeditor instance? Just try to get data from firebug to see the not dirty content:

console.log( CKEDITOR.instances.your_instance_name.getData() );


overkill to to turn the plug-in off if you still want it you can clean the output like so in php:

$output = preg_replace('/<span data-scayt_word="[^"]+" data-scaytid="[0-9]*">([^<]+)<\/span>/','$1',$input);

*credit to balrok for the regX


I also had this problem, if you want to clean up the html-source you can use this sed command:

cat scaytPolluted.html | sed -r 's/<span data-scayt_word="[^"]+" data-scaytid="[0-9]*">([^<]+)<\/span>/\1/g' > clean.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜