【问题标题】:How to add custom formatting to Redactor如何将自定义格式添加到 Redactor
【发布时间】:2013-04-20 17:40:39
【问题描述】:

我想知道是否可以向编辑器添加自定义格式?我创建了一个自定义按钮,并且能够更改文本的格式,但只能使用某些元素:

['p', 'blockquote', 'pre', 'h3', 'h4', 'h5']

但是,我无法添加以下任何内容:

['small', 'figcaption']

我按照 Redactor 文档设置按钮,这是我的函数被调用:

  var selected_html = $('#redactor_content').getSelected();
  $('#redactor_content').execCommand('formatblock', '<small>');

我也尝试将元素添加到我的“formattingTags”数组中,但似乎没有任何影响。

formattingTags: ['p', 'blockquote', 'small', 'pre', 'h3', 'h4']

提前谢谢你。

【问题讨论】:

    标签: redactor


    【解决方案1】:

    我想我明白了。

    我在按钮功能中添加了以下内容:

    var $selected_html = $('#redactor_content').getSelected();
    $('#redactor_content').execCommand('inserthtml', '<small>' + $selected_html + '</small>');
    

    但是,这并不完美,因为它不会替换父标签,并且您可以继续在元素中添加元素。

    【讨论】:

      【解决方案2】:

      类似的东西:

      redactorOptionsDefaults = {
          buttonsAdd: {},
          activeButtonsAdd: {},
          buttonsCustom: {}
      };
      
      redactorOptionsDefaults.buttonsCustom.small = {
          title: 'small Header',
          callback: function () {
              this.formatBlocks('small');
          }
      }
      redactorOptionsDefaults.activeButtonsAdd.small = 'small';
      

      它格式化块,选择块时如果需要突出显示按钮。但是不要在重复按钮单击时删除样式

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-08-24
        • 1970-01-01
        • 1970-01-01
        • 2014-10-20
        • 2023-03-10
        • 2021-06-12
        相关资源
        最近更新 更多