文档注册表项

注册表项

注册表允许多个具有不同格式的编辑器共存于同一页面上。

¥Registries allow multiple editors with different formats to coexist on the same page.

如果你使用 Quill.register() 注册格式,该格式将被注册到全局注册表,所有 Quill 实例都将使用该注册表。

¥If you register a format with Quill.register(), the format will be registered to a global registry, which will be used by all Quill instances.

但是,在某些情况下,你可能需要拥有多个注册表,以便不同的 Quill 实例可以具有不同的格式。例如,你可能希望有一个仅支持粗体和斜体的 Quill 实例,以及另一个支持粗体、斜体和下划线的 Quill 实例。

¥However, in some cases, you might want to have multiple registries, so that different Quill instances can have different formats. For example, you might want to have a Quill instance that only supports bold and italic, and another Quill instance that supports bold, italic, and underline.

用法

¥Usage

要创建带有自定义注册表的 Quill,你可以将注册表对象传递给 Quill 构造函数:

¥To create a Quill with a custom registry, you can pass in a registry object to the Quill constructor:

const registry = new Parchment.Registry();
// Register the formats that you need for the editor with `registry.register()`.
// We will cover this in more detail in the next section.
const quill = new Quill('#editor', {
registry,
// ...other options
})

寄存器格式

¥Register Formats

自定义注册表默认不包含任何格式。你应该使用 registry.register() 注册所需的格式。为了拥有一个功能齐全的编辑器,你需要注册一些基本格式:

¥A custom registry doesn't come with any formats by default. You should register the formats that you need with registry.register(). There are some essential formats that you will need to register in order to have a functional editor:

<!-- Include stylesheet -->
<link href="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/quill/2.0.0-dev.4/quill.snow.css" rel="stylesheet" />
<div id="editor">
</div>
<!-- Include the Quill library -->
<script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/quill/2.0.0-dev.4/quill.js"></script>
<script src="/index.js"></script>
Note

你可能已经注意到,上面工具栏上的格式按钮不起作用。这是因为我们还没有注册任何相应的格式。

¥You may have noticed that the format buttons on the toolbar above doesn't work. This is because we haven't registered any of the corresponding formats yet.

工具栏模块不会检测格式是否可用,因此它将始终显示按钮。请关注 本指南 以了解更多关于如何自定义工具栏的信息。

¥The toolbar module doesn't detect whether a format is available or not, so it will always show the buttons. Follow this guide to learn more about how to customize the toolbar.