去除Dede编辑器粘贴/回车都自动加DIV的方法
DEDE5.6版及后续版本内置的可视化编辑器变成了只有ckeditor 使用中发现一个问题不管是黏贴文本进来,还是手工输入,然后回车,都会被自动加<DIV>标签,如果遇到长文章,自动分页,可能会出现<DIV></DIV>标签被截断的现象,造成文章后面的模板全部错乱。因此需要将自动添加的<DIV>标签去除。
打开/dede/inc/inc_archives_functions.php
大概在这个文件的第633行找到下面的代码:
function AnalyseHtmlBody($body,&$description,&$litpic,&$keywords,$dtype='')
{
在下面加入如下代码:
$body = str_replace("div","p",$body);
echo $str."\n";
但是以上代码仅限于普通的网站,也就是不会在发布的文章中有文本的<DIV>字符的,如果是站长源码类网站,或者技术类网站,因为经常会在文章中出现<DIV>的字眼,这些字同样会在发布的时候被自动替换掉,这样就使发布的文章跟原文不一样的。因此笨牛网在尝试了以上方法后发现不适合笨牛网(BNXB.COM)使用,继续查阅文章,发现可以从CKEDITOR的配置文件着手
/include/ckeditor/config.js
在
/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
// config.language = 'fr';
config.uiColor = '#F1F5F2';
// 文件浏览
config.filebrowserImageBrowseUrl = "../include/dialog/select_images.php";
config.filebrowserFlashBrowseUrl = "../include/dialog/select_media.php";
config.filebrowserImageUploadUrl = "../include/dialog/select_images_post.php";
下方添加
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_P;
config.enterMode = CKEDITOR.ENTER_BR;这句在的意思就是将ENTER换行的换行符改成<BR>
config.shiftEnterMode = CKEDITOR.ENTER_P; 这句的意思就是将SHIFT+ENTER换行的换行符改成<P>
所以如果想ENTER改成<P>那可以使用config.enterMode = CKEDITOR.ENTER_P;
改完后文件如下
/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
// config.language = 'fr';
config.uiColor = '#F1F5F2';
// 文件浏览
config.filebrowserImageBrowseUrl = "../include/dialog/select_images.php";
config.filebrowserFlashBrowseUrl = "../include/dialog/select_media.php";
config.filebrowserImageUploadUrl = "../include/dialog/select_images_post.php";
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_P;
config.autoParagraph = false;
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_P;
};
这样在手工录入的时候就可以按回车换行,换行符是<BR>而不是之前的<DIV>了。
不过到这里还不是完全符合我们的要求,我们从外部TXT文件黏贴内容进来,任然会被自动套一层<DIV></DIV>
以下继续改进
打开/include/ckeditor/ckeditor.js
然后查找 'p':'div' 改成'div':'p'
完成
打开/dede/inc/inc_archives_functions.php
大概在这个文件的第633行找到下面的代码:
function AnalyseHtmlBody($body,&$description,&$litpic,&$keywords,$dtype='')
{
在下面加入如下代码:
$body = str_replace("div","p",$body);
echo $str."\n";
但是以上代码仅限于普通的网站,也就是不会在发布的文章中有文本的<DIV>字符的,如果是站长源码类网站,或者技术类网站,因为经常会在文章中出现<DIV>的字眼,这些字同样会在发布的时候被自动替换掉,这样就使发布的文章跟原文不一样的。因此笨牛网在尝试了以上方法后发现不适合笨牛网(BNXB.COM)使用,继续查阅文章,发现可以从CKEDITOR的配置文件着手
/include/ckeditor/config.js
在
/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
// config.language = 'fr';
config.uiColor = '#F1F5F2';
// 文件浏览
config.filebrowserImageBrowseUrl = "../include/dialog/select_images.php";
config.filebrowserFlashBrowseUrl = "../include/dialog/select_media.php";
config.filebrowserImageUploadUrl = "../include/dialog/select_images_post.php";
下方添加
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_P;
config.enterMode = CKEDITOR.ENTER_BR;这句在的意思就是将ENTER换行的换行符改成<BR>
config.shiftEnterMode = CKEDITOR.ENTER_P; 这句的意思就是将SHIFT+ENTER换行的换行符改成<P>
所以如果想ENTER改成<P>那可以使用config.enterMode = CKEDITOR.ENTER_P;
改完后文件如下
/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
// config.language = 'fr';
config.uiColor = '#F1F5F2';
// 文件浏览
config.filebrowserImageBrowseUrl = "../include/dialog/select_images.php";
config.filebrowserFlashBrowseUrl = "../include/dialog/select_media.php";
config.filebrowserImageUploadUrl = "../include/dialog/select_images_post.php";
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_P;
config.autoParagraph = false;
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_P;
};
这样在手工录入的时候就可以按回车换行,换行符是<BR>而不是之前的<DIV>了。
不过到这里还不是完全符合我们的要求,我们从外部TXT文件黏贴内容进来,任然会被自动套一层<DIV></DIV>
以下继续改进
打开/include/ckeditor/ckeditor.js
然后查找 'p':'div' 改成'div':'p'
完成
顶(0)
踩(0)
- 最新评论