Quill.js 格式()方法有什么作用?

2024-05-03

我正在尝试为 Quill.js 实现自定义样式,该样式允许文本中嵌套和(希望)重叠区域。我还不确定如何进行重叠,但嵌套似乎是可能的。

我已经完成了通常的印迹扩展(在打字稿中):

let Inline = Quill.import('blots/inline');

class Comment extends Inline {
    static create(value: any) : Node {
        let node = super.create();

        node.setAttribute('style', 'background-color: PeachPuff;');
        node.setAttribute('data-comment-id', value);
        node.setAttribute('class', "comment comment"  + value);
        return node;
    }

    static formats(domNode: Node) {
        return (<Element>domNode).getAttribute('data-comment-id');
    }
}

Comment.blotName = 'comment';
Comment.className = 'comment';
Comment.tagName = 'span';

Quill.register({
    'formats/comment': Comment
});

现在,嵌套行为有所不同,具体取决于我对 format() 方法所做的操作。当我尝试嵌套注释时,上面写的方式会分裂注释。如果我只是返回“true”,嵌套将被完全禁用。如果我让它未实现,嵌套将按预期工作(一个“”在另一个中),但前提是我离开node.setAttribute('style', 'background-color: PeachPuff;');在那里。当我将该行与formats()- 格式化方法根本不起作用。

当然我可以不实施formats()就这样吧。然而目前我只是随机尝试一些东西,这是我非常不喜欢的。这意味着我可能没有充分利用 API 的潜力,并且可能会产生意想不到的副作用,并且以后很难发现错误。

我已经阅读了示例,搜索了文档并浏览了 Quill.js 和 Parchment 源代码,但我一无所知。尽管到目前为止我真的很喜欢 Quill,但遗憾的是缺乏文档。

任何有更深入了解的人都可以向我解释一下这个方法的作用,或者 Quill/Parchment 如何进行格式到 Delta 到 html 的转换/标准化?

注意:这个问题是关于 Quill 的工作原理,而不是关于如何进行重叠注释或者这样的事情是否是一个好主意。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Quill.js 格式()方法有什么作用? 的相关文章

随机推荐