question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom inline blot with <span> and className not working.

See original GitHub issue

I’m creating a custom inline blot. I want to use span and style it with css. I read in the: “Cloning Medium with Parchment” tutorial the following:

Note Inline blots use <span> and Block Blots use <p> by default, so if you would like to use these tags for your custom Blots, you will have to specify a className in addition to a tagName.

And I’m creating this:

class TestBlot extends Inline { }
TestBlot.blotName = 'thick';
TestBlot.tagName = 'span';
TestBlot.className = 'test-class';
Quill.register(TestBlot);

And it’s not working. But if I change the tagName to spann it does work! What am I missing here?! What’s the right way of doing this?

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
scrimothycommented, Oct 28, 2019

Adding to what @dkreft said (which completely fixed my same issue):

Looking at that codeblock (from https://github.com/quilljs/parchment/blob/master/src/blot/abstract/format.ts#L11-L18)

static formats(domNode: HTMLElement): any {
    if (typeof this.tagName === 'string') {
      return true;
    } else if (Array.isArray(this.tagName)) {
      return domNode.tagName.toLowerCase();
    }
    return undefined;
  }

Because the first check in formats is to determine if tagName is a string, and thus returns true, then since my tagName = 'span', then I just added my own formats function like this:

static formats(): boolean {
  return true;
}

Still seems silly for this to be required, but until there’s a legit fix internally, this seems to be working properly. I can’t think of any possible side effects this would have since in my case (with tagName = 'span') this function should’ve normally returned true. Only thing I don’t quite understand why the InlineBlot would first do this if (domNode.tagName === InlineBlot.tagName) return undefined; in its formats function.

So, my stripped down blot class looks like this:

export class TagBlot extends Inline {
  static blotName = 'tag';
  static className = 'aur-tag';
  static tagName = 'span';

  static formats(): boolean {
    return true;
  }
}

And it’s finally appending the span.aur-tag element to the selection in my editor

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to set a selected text with a inline <span> class?
I would like to wrap a text with . I've attempted to do it via extending the Inline class. i.e. class MBlot extends...
Read more >
Display - Tailwind CSS
Use inline , inline-block , and block to control the flow of text and elements. When controlling the flow of text, using the...
Read more >
Cloning Medium with Parchment - Quill Rich Text Editor
Through Parchment you can customize the content and formats Quill ... You cannot observe an Inline blot by just typing at this point...
Read more >
nth-child() - CSS: Cascading Style Sheets - MDN Web Docs
<h3> <code>span:nth-child(2n+1)</code>, WITHOUT an <code><em></code> among the child elements. </h3> <p>Children 1, 3, 5, ...
Read more >
Display property · Bootstrap v5.0
<div class="d-inline p-2 bg-primary text-white">d-inline</div> <div ... use responsive display classes for showing and hiding elements by device.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found