gpt4 book ai didi

angular 5 和 quilljs [Parchment] 无法创建印迹

转载 作者:搜寻专家 更新时间:2023-10-30 21:22:30 25 4
gpt4 key购买 nike

我正在使用 primeng editor编辑器本身没有任何问题,但是我连续两天都在为自定义标签扩展标准 block 而战,官方文档说要使用任何附加功能quilljs api

我已经检查了 github 上的每个 api 和问题,在我看来,我的方法是正确的,但我无法摆脱这个烦人的错误:

ERROR Error: [Parchment] Unable to create marker blot
at new ParchmentError (scripts.bundle.js:148)
at Object.create (scripts.bundle.js:178)
at BlockBlot.insertAt (scripts.bundle.js:7323)
at Block.insertAt (scripts.bundle.js:855)
at Scroll.ContainerBlot.insertAt (scripts.bundle.js:3404)
at ScrollBlot.insertAt (scripts.bundle.js:7060)
at Scroll.insertAt (scripts.bundle.js:4252)
at Editor.insertEmbed (scripts.bundle.js:2606)
at scripts.bundle.js:1379
at Quill.modify (scripts.bundle.js:1610)

我想要实现的是添加带有不可编辑内容的自定义标签。这是我的代码:

...
import {Editor} from 'primeng/editor';

import * as Quill from 'quill';
import * as Parchment from 'parchment';
const Block = Quill.import('blots/block/embed');
class BlockEmbed extends Parchment.default.Embed {}
BlockEmbed.prototype = Block.prototype;

export class Variable extends BlockEmbed {

static blotName = 'marker';
static tagName = 'marker';

static create(value: any) {
console.log(value);
const node = (super.create(value) as any);
node.innerHTML = '<span contenteditable=false>' + value + '</span>';
node.setAttribute('contenteditable', false);
return node;
}

}

Variable.blotName = 'marker';
Variable.tagName = 'marker';

Quill.register('formats/marker', Variable);

@Component({
selector: 'manager',
templateUrl: './manager.component.html',
styleUrls: ['./manager.component.css']
})

export class ManagerComponent implements OnInit, AfterViewInit {

private quill: any;
@ViewChild(Editor) editorComponent: Editor;

ngOnInit() {}

// based on primeng github issue this how we can get references to quill
ngAfterViewInit() {
this.quill = this.editorComponent.quill;
}

variableSelected(event) {
// grubbing string variable from event
this.quill.insertEmbed(this.cursor.index || 0, 'marker', event.value);
}

}

基于 quill github 中的这些主题,我的代码应该可以正常工作:

topic 1

topic 2

topic 3

topic 4

那么有人可以帮助我找到我缺少的东西或我的问题所在吗?提前致谢。

最佳答案

我很高兴用下一种方法解决我的问题

...
declare var Quill: any;
const BlockEmbed = Quill.import('blots/embed');

export class Variable extends BlockEmbed {

static create(value: any) {
const node = super.create(typeof value === 'object' ? value.text : value);
node.innerText = typeof value === 'object' ? value.text : value;
node.setAttribute('contenteditable', false);
return node;
}

static value(node) {
return {
style: node.getAttribute('contenteditable'),
text: node.innerText
};
}

}

Variable['blotName'] = 'marker';
Variable['className'] = 'marker';
Variable['tagName'] = 'span';

Quill.register('formats/marker', Variable);

export class ManagerComponent implements OnInit, AfterViewInit {

private quill: any;

@ViewChild('stepper') stepper;
@ViewChild(Editor) editorComponent: Editor;

...

variableSelected(event) {
this.quill.insertEmbed(this.cursor.index || 0, 'marker', event.value, 'user');
this.quill.update('user');
}

关于angular 5 和 quilljs [Parchment] 无法创建印迹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48672240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com