Skip to content

Commit

Permalink
Update documentation for blot interface changes
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Mar 19, 2024
1 parent 2ccc6be commit 74986a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ class Blot {
Implementation for a Blot representing a link, which is a parent, inline scoped, and formattable.

```typescript
import Parchment from 'parchment';
import { InlineBlot, register } from 'parchment';

class LinkBlot extends Parchment.Inline {
class LinkBlot extends InlineBlot {
static blotName = 'link';
static tagName = 'A';

Expand Down Expand Up @@ -145,7 +145,7 @@ class LinkBlot extends Parchment.Inline {
}
}

Parchment.register(LinkBlot);
register(LinkBlot);
```

Quill also provides many great example implementations in its [source code](https://github.com/quilljs/quill/tree/develop/formats).
Expand Down Expand Up @@ -189,17 +189,17 @@ class Attributor {

Note custom attributors are instances, rather than class definitions like Blots. Similar to Blots, instead of creating from scratch, you will probably want to use existing Attributor implementations, such as the base [Attributor](#attributor), [Class Attributor](#class-attributor) or [Style Attributor](#style-attributor).

The implementation for Attributors is surprisingly simple, and its [source code](https://github.com/quilljs/parchment/tree/master/src/attributor) may be another source of understanding.
The implementation for Attributors is surprisingly simple, and its [source code](https://github.com/quilljs/parchment/tree/main/src/attributor) may be another source of understanding.

### Attributor

Uses a plain attribute to represent formats.

```js
import Parchment from 'parchment';
import { Attributor, register } from 'parchment';

let Width = new Parchment.Attributor.Attribute('width', 'width');
Parchment.register(Width);
let Width = new Attributor('width', 'width');
register(Width);

let imageNode = document.createElement('img');

Expand All @@ -212,13 +212,13 @@ console.log(imageNode.outerHTML); // Will print <img>

### Class Attributor

Uses a classname pattern to represent formats.
Uses a class name pattern to represent formats.

```js
import Parchment from 'parchment';
import { ClassAttributor, register } from 'parchment';

let Align = new Parchment.Attributor.Class('align', 'blot-align');
Parchment.register(Align);
let Align = new ClassAttributor('align', 'blot-align');
register(Align);

let node = document.createElement('div');
Align.add(node, 'right');
Expand All @@ -230,12 +230,12 @@ console.log(node.outerHTML); // Will print <div class="blot-align-right"></div>
Uses inline styles to represent formats.

```js
import Parchment from 'parchment';
import { StyleAttributor, register } from 'parchment';

let Align = new Parchment.Attributor.Style('align', 'text-align', {
let Align = new StyleAttributor('align', 'text-align', {
whitelist: ['right', 'center', 'justify'], // Having no value implies left align
});
Parchment.register(Align);
register(Align);

let node = document.createElement('div');
Align.add(node, 'right');
Expand Down
11 changes: 11 additions & 0 deletions src/blot/abstract/blot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ export interface BlotConstructor {
defaultChild?: BlotConstructor;
}

/**
* Blots are the basic building blocks of a Parchment document.
*
* Several basic implementations such as Block, Inline, and Embed are provided.
* In general you will want to extend one of these, instead of building from scratch.
* After implementation, blots need to be registered before usage.
*
* At the very minimum a Blot must be named with a static blotName and associated with either a tagName or className.
* If a Blot is defined with both a tag and class, the class takes precedence, but the tag may be used as a fallback.
* Blots must also have a scope, which determine if it is inline or block.
*/
export interface Blot extends LinkedNode {
scroll: Root;
parent: Parent;
Expand Down

0 comments on commit 74986a5

Please sign in to comment.