I've been working with the primeng editor and everything seems fine with the editor itself. However, I've spent the last two days struggling to extend a standard block for a custom tag. The official documentation suggests using the quilljs API for additional features.
Despite checking all APIs and GitHub issues, it appears that I'm on the right track but I keep encountering this pesky error:
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)
My goal is to add a custom tag with non-editable content inside. Here's a snippet of my code:
...
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) {
// grab string variable from event
this.quill.insertEmbed(this.cursor.index || 0, 'marker', event.value);
}
}
According to similar topics on the quill GitHub, my code should be functioning correctly:
topic 3
topic 4
If anyone could assist me in pinpointing what I might be overlooking or where my issue lies, I would greatly appreciate it. Thanks in advance.