【问题标题】:Froala editor keep indent when pasting codeFroala 编辑器在粘贴代码时保持缩进
【发布时间】:2014-10-20 10:22:38
【问题描述】:

我在粘贴到 Froala 时遇到了一些问题。我有一个自定义代码按钮,它添加了<pre><code>Code here</code></pre> 标签:

$('textarea[name="description"]').editable({
    customButtons: {
        insertCode: {
            title: 'Insert code',
            icon: {
                type: 'font',
                value: 'fa fa-code'
            },
            callback: function() {
                if (!this.selectionInEditor()) {
                    this.$element.focus(); // Focus on editor if it's not.
                }

                var html = '<pre><code>' + (this.text() || '&#8203;') + '</code></pre>';

                this.insertHTML(html);
                this.saveUndoStep();
            }
        }
    }
});

我希望能够将代码粘贴到编辑器中,删除样式但保留换行符和缩进。与CNTL+K 在 SO 上类似。这可能吗?

【问题讨论】:

    标签: jquery wysiwyg indentation paste froala


    【解决方案1】:

    您应该将 this.text() 替换为获取选定 HTML 而不是选定文本的内容。 Froala WYSIWYG 编辑器没有这种机制,但您可以使用Get Selected HTML in browser via Javascript 问题的答案。

    【讨论】:

      猜你喜欢
      • 2014-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      相关资源
      最近更新 更多