richtabor / dark-mode-toggle-block

A WordPress block to add a toggle between light and dark mode on a site.
https://rich.blog/dark-mode-toggle-block
36 stars 9 forks source link

Block markup #12

Open webmandesign opened 2 weeks ago

webmandesign commented 2 weeks ago

I'm trying to add this block into my theme's template parts and noticed it outputs a full HTML markup in editor, such as:

<!-- wp:tabor/dark-mode-toggle {"style":{"border":{"width":"2px"},"elements":{"link":{"color":{"text":"var:preset|color|contrast-alt"}}}},"backgroundColor":"base","textColor":"contrast-alt","borderColor":"contrast-alt"} -->
<div class="wp-block-tabor-dark-mode-toggle is-small">...</div>
<!-- /wp:tabor/dark-mode-toggle -->

From my experience this is prone to future errors once a plugin is updated, for example, or WordPress core changes something regarding block markup.

Would it be possible to make the plugin output a simple inline HTML comment markup (such as is the case with core/site-logo block with its <!-- wp:site-logo /--> markup), something like:

<!-- wp:tabor/dark-mode-toggle {"style":{"border":{"width":"2px"},"elements":{"link":{"color":{"text":"var:preset|color|contrast-alt"}}}},"backgroundColor":"base","textColor":"contrast-alt","borderColor":"contrast-alt"} /-->

Thank's for consideration!

richtabor commented 5 days ago

Yea, it's a trade-off either way. It's currently not a dynamic block. I'll think about it more, but I'm trying to recall why I did not go that route.