WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
9.99k stars 4.02k forks source link

How to create a custom inline-block? #10235

Closed mahdiyazdani closed 3 days ago

mahdiyazdani commented 5 years ago

Is there any guide on creating custom inline blocks?

pbiron commented 1 year ago

In that case would it be appropriate to remove the [Type] Developer Documentation label? Then it won't show up on the Docs team's radar.

to be honest...the labels applied to most issues in this repo make absolutely no sense to me ;-) So, I don't really know how to answer your question

Note: I edited my previous comment to make it more clear what I meant (I hit the comment button without proofreading what I'd wrote)

difawa commented 2 months ago

A simple example would be to display the user's IP address:

I wanted to create a easy way for editors to insert <wbr> or &nbsp; into text to manage line breaks

I've blockified both in an example plugin https://github.com/stokesman/lineup/ and here's a quick demo:

inline-block-demo.mp4 Since I've had this little hands-on with creating some inline blocks, I'll share my perspective. Creating one is basically the same as creating any other block. The inconvenience is—given what seems the typical use case of surrounding the block with text—you probably can't make do with that block on its own. You're likely to need two more blocks to accompany it—a container and an inline text block. The plugin includes those and there's a bit more detail in the readme.

If anyone tries this out, I think it will likely help them to understand that it would be quite a challenge to allow inner blocks in text-based blocks like Paragraph without hindering the ergonomics for the common use case of simply writing some text with rich formatting.

Hello sir, can you make the longer demo video? I just installed the plugin and I didn't find any difference on the editor page. I mean I didn't find the block to follow your demo. How to create the block like in your demo?

stokesman commented 2 months ago

If you didn’t find the Lineup block in the editor then I'll guess that you didn’t build the plugin. If you aren’t familiar with node/npm a here’s a good place to start with regards to its use in block development. If you have it installed then all it should take is executing npm i and then npm run build from the plugin directory in your terminal. Let me know if I guessed wrong and something else is the issue.

mtias commented 3 days ago

It seems the remaining use cases described here are better captured by the inline shortcodes proposal in the temporarily named "bits" — https://github.com/WordPress/gutenberg/discussions/39831

It's better to direct feedback there as it's still in proposal stage. There's no other way to define inline dynamic content today.