nozer/quill-delta-to-html

Extra attributes in formats

Opened this issue · 0 comments

Thanks for this library, @nozer . I am trying to implement blockquote in two ways, one with background and other without background for that i added a separate block quote like this

import { Quill } from "react-quill";

let Block = Quill.import('blots/block');

class Blockquote extends Block {
  static create(value) {
    console.log(value);
    let node = super.create();

    if(typeof value !== "object"){
      return node;
    }

    if(!value.quote){
      return node;
    }

    node.setAttribute("class", "ql-customquote")
    return node;
  }

  static formats(node) {
    return {
      quote: node.getAttribute("class") === "ql-customquote"
    }
  }
}

Blockquote.blotName = 'blockquote';
Blockquote.tagName = 'blockquote';

export default Blockquote;

While adding the format i am sending quote: true or false. The delta ops looks like this.

{"ops":[{"insert":"Test"},{"attributes":{"blockquote":{"quote":true}},"insert":"\\n"},{"insert":"Test"},{"attributes":{"blockquote":{"quote":true}},"insert":"\\n"},{"insert":"TEst"},{"attributes":{"blockquote":{"quote":true}},"insert":"\\n"},{"insert":"\\n"}]}

In before render i am not able to get the attribute value as {blockquote: { quote: true/false}} instead i am getting { blockquote: true}. i want to style the content based on the quote flag. In editor it works fine. I tried custom tag and custom tag attributes.Any suggestions on how to achieve with this library