slab / parchment

Generalized state model for rich-text editors to interface with browser DOM
BSD 3-Clause "New" or "Revised" License
628 stars 143 forks source link

How to add custom inline blot (or any blot whatsoever)? #118

Open falk-stefan opened 2 years ago

falk-stefan commented 2 years ago

I'm getting out of ideas. After trying for an eternity I'd like to ask directly how it's possible to add a blot in Angular.

I want the user to be able to annotate text. Ideally it would be possible to add overlapping annotation but I'd be happy if adding a simple blot would work for a start.

I'm essentially creating an Annotation:

import {InlineBlot} from "parchment";
import * as QuillNamespace from 'quill';
let Quill: any = QuillNamespace;

class Annotation extends InlineBlot {
  blotName = "annotation";
  tagName = "SPAN";
  className = "annotation-class";
  static create(node: Node){
    console.log("CREATE");
    return node;
  }
  static formats() {
    return true as any;
  }
}

Quill.register(Annotation, true);

which I try to add like this:

this.quill.on('selection-change', function(range: RangeStatic) {
  if (range) {
    if (range.length > 0) {
      quill.formatText(range, Annotation.tagName, true);
    }
  }
});

However, nothing really happens. There's nothing crashing but there's nothing added as well.

What am I missing here?

ramarivera commented 1 year ago

Absolutely late to the party, but since your blot is using both a tag and class name, I believe you need to use both somehow.

I had some experience with embeds, and for those there is a special method.

Did you manage to solve this somehow? If not, I could try to take a look :)

ramarivera commented 1 year ago

https://quilljs.com/guides/cloning-medium-with-parchment/

I'm theory you should use blot name, not tag name I think?