溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

phpcms 文章一鍵排版

發(fā)布時(shí)間:2020-06-27 14:09:19 來(lái)源:網(wǎng)絡(luò) 閱讀:700 作者:菜鳥(niǎo)不菜么 欄目:web開(kāi)發(fā)
  1. phpcms/libs/classes/form.class.php找['Maximize'],在它下面添加['autoformat']

    phpcms 文章一鍵排版

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

    config.extraPlugins = 'capture,autoformat';phpcms 文章一鍵排版

  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',
                    //這個(gè)autoformat.gif是你的插件圖標(biāo),放在同目錄下 
                    icon: this.path + "autoformat.gif"
                });
            }
        });
        CKEDITOR.plugins.autoformat = {
            commands: {
                autoformat: {
                    exec: function(a) {
                        var _html = a.getData();
                        //清除樣式代碼 
                        _html = _html.replace(/<div/ig, '<p');
                        _html = _html.replace(/<\/div>/ig, '</p>');
                        _html = _html.replace(/<strong[^>]*>/ig, '');
                        _html = _html.replace(/<\/strong>/ig, '');
                        _html = _html.replace(/<em[^>]*>/ig, '');
                        _html = _html.replace(/<\/em>/ig, '');
                        _html = _html.replace(/<u[^>]*>/ig, '');
                        _html = _html.replace(/<\/u>/, '');
                        _html = _html.replace(/<li[^>]*>/ig, '');
                        _html = _html.replace(/<\/li>/ig, '');
                        _html = _html.replace(/<span[^>]*>/ig, '');
                        _html = _html.replace(/<\/span>/ig, '');
                        _html = _html.replace(/&nbsp;/ig, '');
                        _html = _html.replace(/ /ig, '');
                        _html = _html.replace(/<p><\/p>/ig, '');
                        _html = _html.replace(/<a/ig, '<a rel="nofollow"');
    
    
                        //將p標(biāo)簽替換成<br /> 
                        _html = _html.replace(/<p[^>]*>/ig, '');
                        _html = _html.replace(/<\/p>/ig, '<br />');
                        _html = _html.replace(/<br \/><br \/>/ig, '<br />');
                        _html = _html.replace(/[\n]/ig, '');
    
                        //按<br />分組,將換行<br>全部替換成p標(biāo)簽 
                        bb = _html.split("<br />");
                        aa = '';
                        for (var i = 0; i < bb.length; i++) {
                            aa = aa + '<p>' + bb[i] + '</p>';
                        }
    
                        //首行縮進(jìn) 
                        _html = aa.replace(/<p[^>]*>/ig, '<p>  ');
                        _html = _html.replace(/<p>  <\/p>/ig, '');
                        _html = _html.replace(/<p><\/p>/ig, '');
    
                        //在這里執(zhí)行你將_html中的空行替換掉的操作 
                        a.setData(_html);
                    }
                }
            }
        };
    })();
附件:http://down.51cto.com/data/2366632
向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI