2

I've tried all the examples in the Parchment docs, but none of them work correctly. For example, using the following code from the documentation...

import Parchment from 'parchment';

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

let node = document.createElement('div');
Align.add(node, 'right');
console.log(node.outerHTML);

The docs state that this will print <div class="blot-align-right"></div>, but I actually just get <div></div>.

I've checked what happens in the debugger. Align.add() calls canAdd(), which always returns false.

Can anyone provide a working example of using Parchment?

Rik Heywood
  • 13,816
  • 9
  • 61
  • 81
  • I've made some progress. Looks like you might also need to register a blot that represents the div, or attributes will be discarded. – Rik Heywood Dec 18 '16 at 16:15

1 Answers1

0

This should work:

Parchment = Quill.import('parchment');

let Align = new Parchment.Attributor.Style('align', 'text-align', {
  whitelist: ['right', 'center', 'justify']
});

Quill.register(Align);

let node = document.createElement('div');
Align.add(node, 'right');
console.log(node.outerHTML);