-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom inline blot with <span> and className not working. #1866
Comments
Please follow the issue template and include all the requested info. |
Thanks @benbro! Here is the template! Steps for Reproduction
Expected behavior: A new Actual behavior: Nothing happens. Platforms: Chrome, Safari, Firefox (and I think all the others but those are the ones I have) Version: Version: 1.3.4 |
Hi @benbro, That link doesn't resolve anymore. Is it possible for someone to repeat the information? I'm interested in how to get around this too. |
@benbro. I am experiencing the same issue, and finding that the link is now a dead end. |
@dannyrb, @chrisronline : Take a look at https://github.com/quilljs/parchment/blob/master/src/blot/inline.ts#L23 There you will see this: if (domNode.tagName === InlineBlot.tagName) return undefined; It's not clear why this line is there or why it should return static formats(domNode: HTMLElement): any {
if (typeof this.tagName === 'string') {
return true;
} else if (Array.isArray(this.tagName)) {
return domNode.tagName.toLowerCase();
}
return undefined;
} On a whim, I simply did this: export default MyCustomInline extends Inline {
static tagName = 'span'
formats() {
return MyCustomInline.tagName
}
} ...and that got things working for me. I have no idea what side effects my "solution" will have, as I'm still learning my way about the API, and the documentation only says:
...which seems rather arcane and unhelpful. When I set a breakpoint inside {
bold: true
} But it really doesn't seem to matter (as far as I've cared to dig) whether you return a mapping of tags to truthy values or if you simply return a string...though I am assuming that the mapping is more correct...again, for reasons that do not appear to be documented. It probably goes without saying that It's very disappointing to have this issue unceremoniously closed by @benbro with nothing more than a link to SO (which has been noted already, is dead), and then pretty much ignored as others have expressed a desire for a real resolution. This does not reflect well on the project. |
@dkreft completely forgot about this issue. I had a similar experience. I kept playing and landed on something that looked like this:
Originally, I only wanted the This seems to imply that there is more required to creating an extended Inline Blot than suggested in the documentation. 🤷♂️ |
I'm having the same issue. Any updates here? I'm unable to figure out Inline with span and class. |
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 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 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 |
@scrimothy somehow this is not working for me slab/parchment#118 |
I'm going to bump this, @scrimothy 's fix worked for me but I'm wondering if there's any plans on fixing this? |
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:
And I'm creating this:
And it's not working. But if I change the
tagName
tospann
it does work! What am I missing here?! What's the right way of doing this?Thanks!
The text was updated successfully, but these errors were encountered: