在 Quill 中禁止某些格式 [英] Suppress certain formats in Quill

查看:83
本文介绍了在 Quill 中禁止某些格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Quill 编辑器,需要将某些旧内容(已经是 HTML)转换为羊皮纸 delta 格式.在创建 Quill 编辑器之前将 HTML 放入 DOM 非常有效:

<p>我的遗留内容</p>

<脚本>var editor = new Quill("#my-editor");

但是,一些遗留 HTML 非常混乱,并且包含我不想支持的某些样式结构(字体、颜色、背景).

Quill 在忽略它不理解的标签、类和样式属性方面做得很好.但是我想取消注册某些我希望它也忽略的已知格式.我试过这样做...

Quill.register({'格式/颜色':空,'格式/字体':空,格式/背景":空});

...试图从 Quill 注册表中取消注册这些格式.但随后我在运行时收到此错误:

TypeError: 无法读取 null 的属性blotName"在 Function.register (vendor/quill-1.3.2.js:1068:82)

有什么建议吗?

解决方案

啊,傻我...我自己找到了答案...

我一直在寻找一种将特定格式列入黑名单的方法,但正确的方法是使用 formats 参数options 对象到白名单我真正想要使用的格式...

var editor = new Quill("#my-editor",{格式":[大胆的","斜体",]});

配置选项记录在此处,可用于白名单的核心格式列表是此处.

I have a Quill editor that needs to convert certain legacy content, which is already HTML, into the parchment delta format. Putting the HTML into the DOM before creating the Quill editor works perfectly:

<div id="my-editor">
  <p>My legacy content</p>
</div>
<script>
  var editor = new Quill("#my-editor");
</script>

However, some of the legacy HTML is very messy and contains certain style constructs (font, color, background) that I don't want to support.

Quill does a great job of ignoring tags, classes, and style attributes that it doesn't understand. But I'd like to un-register certain known formats that I want it to also ignore. I've tried doing this...

Quill.register({
  'formats/color': null,
  'formats/font': null,
  'formats/background': null
});

...in an attempt to un-register those formats from the Quill registry. But then I get this error at runtime:

TypeError: Cannot read property 'blotName' of null
    at Function.register (vendor/quill-1.3.2.js:1068:82)

Any suggestions?

解决方案

Ah, silly me... I found the answer myself...

I was looking for a way to blacklist specific formats, but the correct way to do this is to use the formats param in the options object to whitelist the formats I actually want to use...

var editor = new Quill(
  "#my-editor",
  {
    "formats" : [
      "bold",
      "italic",
    ]
  }
);

The configuration option is documented here and the list of core formats available for whitelisting is here.

这篇关于在 Quill 中禁止某些格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆