reactjs - React Quill Matchers are not applying to Headers -
i've made custom attributor classes highlighting whole lines, i've run issue clipboard matchers.
using quill toolbar buttons can toggle attributors on line, when updating contents db (which uses dangerouslypastehtml()), <h1> elements have attributor classes stripped of them.
i think has matches , fact both attributor , headers block scoped, can't figure out.
custom attributor:
export default class diffhighlightattributor extends parchment.attributor.class { add(node, value) { if (!this.canadd(node, value)) return false; this.remove(node); node.classlist.add(`diff-${this.keyname}`); return true; } remove(node) { let matches = match(node, this.keyname); matches.foreach(function(name) { node.classlist.remove(name); }); if (node.classlist.length === 0) { node.removeattribute('class'); } } }
instantiating , registering attributors:
const parchment = quill.import('parchment'); const delta = quill.import('delta'); const diffremoveattributor = new diffhighlightattributor('highlight_removed', 'highlight_removed', { scope: parchment.scope.block }); const diffaddattributor = new diffhighlightattributor('highlight_added', 'highlight_added', { scope: parchment.scope.block }); quill.register(diffremoveattributor, true); quill.register(diffaddattributor, true);`
configuring , implementing react components:
this.formats = [ 'header', 'font', 'size', 'bold', 'italic', 'underline', 'strike', 'blockquote', 'list', 'bullet', 'indent', 'link', 'image', 'color', 'highlight_added', 'highlight_removed' ]; this.modules = { toolbar: { container: `#toolbar${this.id}` }, clipboard: { matchers: [ ['.diff-highlight_added', (node, delta) => { return delta.compose(new delta().retain(delta.length(), { highlight_added: true })); }], ['.diff-highlight_removed', (node, delta) => { return delta.compose(new delta().retain(delta.length(), { highlight_removed: true })); }] ] } }; ... <reactquill ref='richeditor' onchange={this.handleinput} formats={this.formats} modules={this.modules} value={this.state.value} theme={'snow'} >
Comments
Post a Comment