Custom inline blot with <span> and className not working.
See original GitHub issueI’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:
- Created 6 years ago
- Comments:10 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Duplicate: https://stackoverflow.com/questions/47811541/custom-inline-blot-with-span-and-classname-not-working/47820727#47820727
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)
Because the first check in
formats
is to determine iftagName
is a string, and thus returnstrue
, then since mytagName = 'span'
, then I just added my ownformats
function like this: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 returnedtrue
. Only thing I don’t quite understand why the InlineBlot would first do thisif (domNode.tagName === InlineBlot.tagName) return undefined;
in itsformats
function.So, my stripped down blot class looks like this:
And it’s finally appending the span.aur-tag element to the selection in my editor