富文本编辑器-code 模块

作者:root



export let code={
    v:true,
    block:true,
    bind: true, //按钮文字联动
    disabled:['img','table'],
    /** 返回代码类型 */
    text:function(n,e){let p=this.E.domPathMap().get('pre')||this.E.domPathMap().get('code');return (p&&p.getAttribute('brush'))||!1},
    panel:{
        list:['clear','plain','javascript','html','php','css','xml','python'],
        command:function(n,v,state){
            this.E.SetRangeToBlock(2);
            let code=this.E.domPathMap().get('code'),pre=this.E.domPathMap().get('pre');
            v=='clear'?(code&&this.E.unwrap(code),pre&&this.E.unwrap(pre)):(
                code= code||this.E.wrap('code'),
                code.setAttribute('brush',v),
                code.className='language-'+v,
                this.E.lastRange.selectNode(code),
                pre=pre||this.E.wrap('pre'),
                pre.setAttribute('brush',v),
                pre.className='code-toolbar',
                code.childNodes.length==0&&(code.innerHTML='<br/>')
                ),
                this.E.flag.codeNodeArray=Array.from(this.E.editnode.querySelectorAll(this.E.selectorCode)),
            this.close()
        },
    }
}