quill icon indicating copy to clipboard operation
quill copied to clipboard

Can I preset a default font style for newly entered text?

Open ClarkWong opened this issue 6 years ago • 11 comments

Example: I expect the newly entered text to be <p><span style="font-size: 14px; font-family: Microsoft YaHei;">some text</span></p>, not <p>some text</p>.

ClarkWong avatar Jan 08 '20 08:01 ClarkWong

You probably need to make a custom blot for that.

The easier way is to override or customize the quill stylesheet file and set the font-family for the .ql-editor p selector. Even better you can set the font-family properties on the .ql-container.

vasilenka avatar Jan 14 '20 10:01 vasilenka

You probably need to make a custom blot for that.

The easier way is to override or customize the quill stylesheet file and set the font-family for the .ql-editor p selector. Even better you can set the font-family properties on the .ql-container.

I expect to be able to generate inline styles because I need to be compatible with Outlook.

ClarkWong avatar Jan 14 '20 10:01 ClarkWong

Ah, I see. I've only been tinkering with Quill for the past 2 weeks, so I'm not really sure how to achieve that. Making your own custom blot seems like the only way.

Another way I can think of for your use-case is injecting the <span> with it's style using javascript when the user is done writing with Quill.

vasilenka avatar Jan 15 '20 01:01 vasilenka

@ClarkWong hi, did you find a solution for this? I ran into same issue

dmitrybndar avatar Feb 03 '20 17:02 dmitrybndar

👍

gagan-lokesh avatar Jun 29 '20 10:06 gagan-lokesh

@ClarkWong @dmitrybndar Any update on this?

gagan-lokesh avatar Jun 29 '20 10:06 gagan-lokesh

@gagan-lokesh oh, it was 4 month ago :) I found then some workaround (for my case). Just looked at my code and grab this part from it, maybe it helps you.

const BlockPrototype = Quill.import("blots/block");

class CustomBlock extends BlockPrototype {
  constructor(domNode, value) {
    super(domNode, value);
    this.format("size", "18px");
  }

  static tagName = "P";

  format(name, value) {
    if (name === "size") {
      this.domNode.style.fontSize = value;
    } else {
      super.format(name, value);
    }
  }
}

Quill.register(CustomBlock, true);

dmitrybndar avatar Jun 29 '20 14:06 dmitrybndar

Works! Thanks so much @dmitrybndar :smile:

gagan-lokesh avatar Jun 29 '20 15:06 gagan-lokesh

Simply change change CSS you want in this class

.ql-editor {
  padding: 12px 0;
  font-size: 18px;
}

udittehri avatar Aug 24 '21 16:08 udittehri

Simply change change CSS you want in this class

.ql-editor {
  padding: 12px 0;
  font-size: 18px;
}

this actually works at least for me but i believe its better to add a collection of fonts for use rather than just setting one check this https://stackoverflow.com/questions/68302512/how-to-remove-or-change-the-default-font-in-quill-js

kariuki-kithinji avatar Dec 27 '22 12:12 kariuki-kithinji

Quill 2.0 has been released (announcement post) with many changes and fixes. If this is still an issue please create a new issue after reviewing our updated Contributing guide :pray:

quill-bot avatar Apr 17 '24 10:04 quill-bot