zoukankan      html  css  js  c++  java
  • Django ckeditor增加编辑代码 功能

     

    前言

     使用ckeditor这个组件的时候 对于长写博客的同学当然希望能有 增加代码这个功能按钮

      而这个按钮 需要自己配置

     我们的编辑器自然需要添加代码块的功能。

    需要用到插件codesnippet,ckeditor的插件放在了ckeditor/static/ckeditor/ckeditor/plugins/路径下。

    安装

    当我们添加一个功能插件时,需要在CKEDITOR_CONFIGS里的extraPlugins对应的value里添加该插件的名字(名字字母小写),

    如果该插件还有相对应的按钮,则在toolbar对应的value里添加名字(首字母大写),以codesnippet为例,

    在下面代码的第21行和24行分别添加了 'CodeSnippet' 和 'codesnippet'

     1  'default': {
     2         'toolbar': (
     3             ['div','Source','-','Save','NewPage','Preview','-','Templates'],
     4             ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print','SpellChecker','Scayt'],
     5             ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
     6             ['Form','Checkbox','Radio','TextField','Textarea','Select','Button', 'ImageButton','HiddenField'],
     7             ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
     8             ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
     9             ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    10             ['Link','Unlink','Anchor'],
    11             ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
    12             ['Styles','Format','Font','FontSize'],
    13             ['TextColor','BGColor'],
    14             ['Maximize','ShowBlocks','-','About', 'pbckcode'],
    15             ['Blockquote', 'CodeSnippet'],
    16         ),
    17         'width': 'auto',
    18         # 添加按钮在这里
    19         'toolbar_Custom': [
    20             ['NumberedList', 'BulletedList'],
    21             ['Blockquote', 'CodeSnippet'],
    22         ],
    23        # 插件
    24         'extraPlugins': ','.join(['codesnippet','widget','lineutils',]),
    25     },

    当然 你需要让你的 富文本编辑器 自适应 屏幕

      在上面的 17 行 增加   

    'width': 'auto',

    哈哈 然后 打开你的浏览器 访问后台项目就能看到啦

    hah  开心ok啦  8月 的第一封  加油啦

  • 相关阅读:
    沈询:事务与分布式事务原理与实现
    c++ 幕客网
    Meet Dgraph — an open source, scalable, distributed, highly available and fast graph databas
    开发与系统管理----开发工具 左蓝
    奇虎360技术博客
    java 相关软件使用趋势
    长亭技术专栏 安全攻防技术分享
    tcp/ip RFC
    gentoo and arclinux
    孙鑫视频VC++深入详解学习笔记
  • 原文地址:https://www.cnblogs.com/yf-html/p/9452574.html
Copyright © 2011-2022 走看看