You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Quill.js v2自定义行内类属性器抛出‘create is not a function’错误

解决Quill自定义行内类格式报错问题

问题根源:自定义行内类属性未被添加到默认文本Blot的允许属性列表中,Quill误将其识别为需要实例化的Blot类型,因此抛出TypeError: o.create is not a function错误。内置size格式已被Quill预先配置到允许列表,所以可正常运行。

正确实现步骤如下:

  1. 导入必要模块:ClassAttributor、Scope 和 TextBlot
  2. 创建行内类属性器
  3. 将自定义属性的key添加到TextBlot.allowedAttributes数组
  4. 注册属性器到Quill

完整代码示例:

import { ClassAttributor, Scope, TextBlot } from 'parchment';

// 定义行内类属性器
const InlineTestClass = new ClassAttributor('inlineTest', 'ql-inline-test', {
  scope: Scope.INLINE,
  whitelist: ['yes', 'no', 'maybe'],
});

// 允许TextBlot使用该自定义属性
TextBlot.allowedAttributes.push('inlineTest');

// 注册到Quill
Quill.register({
  'attributors/class/inlineTest': InlineTestClass,
  'formats/inlineTest': InlineTestClass,
}, true);

完成上述配置后,执行quill.formatText(5, 5, { 'inlineTest': 'yes' })即可正常为目标文本添加ql-inline-test-yes类,无需扩展InlineBlot类,完全基于Quill原生机制实现。

内容的提问来源于stack exchange,提问作者Rich - enzedonline

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 19:28:19