1. phpcms/libs/classes/form.class.php找['Maximize'],在它下面添加['autoformat']

    phpcms 文章一键排版_第1张图片

  2. statics/js/ckeditor/config.js找到config.extraPlugins修改为

    config.extraPlugins = 'capture,autoformat';phpcms 文章一键排版_第2张图片

  3. statics\js\ckeditor\plugins 新建文件夹autoformat并新建文件plugin.js


  4. (function() {
        CKEDITOR.plugins.add('autoformat', {
            requires: ['styles', 'button'],
            init: function(a) {
                a.addCommand('autoformat', CKEDITOR.plugins.autoformat.commands.autoformat);
                a.ui.addButton('autoformat', {
                    label: "清除格式,一键排版",
                    command: 'autoformat',
                    //这个autoformat.gif是你的插件图标,放在同目录下 
                    icon: this.path + "autoformat.gif"
                });
            }
        });
        CKEDITOR.plugins.autoformat = {
            commands: {
                autoformat: {
                    exec: function(a) {
                        var _html = a.getData();
                        //清除样式代码 
                        _html = _html.replace(/
    /ig, '

    ');                     _html = _html.replace(/]*>/ig, '');                     _html = _html.replace(/<\/strong>/ig, '');                     _html = _html.replace(/]*>/ig, '');                     _html = _html.replace(/<\/em>/ig, '');                     _html = _html.replace(/]*>/ig, '');                     _html = _html.replace(/<\/u>/, '');                     _html = _html.replace(/]*>/ig, '');                     _html = _html.replace(/<\/li>/ig, '');                     _html = _html.replace(/]*>/ig, '');                     _html = _html.replace(/<\/span>/ig, '');                     _html = _html.replace(/ /ig, '');                     _html = _html.replace(/ /ig, '');                     _html = _html.replace(/

    <\/p>/ig, '');                     _html = _html.replace(/                      _html = _html.replace(/]*>/ig, '');                     _html = _html.replace(/<\/p>/ig, '');                     _html = _html.replace(//ig, '');                     _html = _html.replace(/[\n]/ig, '');                     //按分组,将换行
    全部替换成p标签                      bb = _html.split("");                     aa = '';                     for (var i = 0; i < bb.length; i++) {                         aa = aa + '

    ' + bb[i] + '

    ';                     }                     //首行缩进                      _html = aa.replace(/]*>/ig, '

      ');                     _html = _html.replace(/

      <\/p>/ig, '');                     _html = _html.replace(/

    <\/p>/ig, '');                     //在这里执行你将_html中的空行替换掉的操作                      a.setData(_html);                 }             }         }     }; })();