admin管理员组文章数量:1304216
I'm using the RichText
component to add some custom list on my Gutenberg Block.
function onItemsChange(items) {
setAttributes({ items })
}
<RichText
multiline="li"
tagName="ul"
value={attributes.items}
onChange={onItemsChange}
placeholder={__('Enter item list')}
/>
So this is rendering the next markup
<ul>
<li>item 1</li>
<li>item 2</li>
</ul>
But I wanted to generate the next markup on every list item
<li class="list-item-class">
<div class="flex">
<!-- svg image -->
</div>
<p class="some-class">
Item 1
</p>
</li>
I was thinking of using some sort of replace on the onItemsChange
function. Do you think this is a good approach? Or I'm doing it wrong? Any ideas? Maybe I need to use a Dynamic Block Yes I'm really lost here...
For example (I know this is not working):
function onItemsChange(items) {
items = items.replaceAll('<li>', '<li class"list-item-class"><div class="flex"><!-- svg image --></div>');
setAttributes({ items })
}
At this moment I was using the attributes:
items: {
type: 'string',
source: 'html',
selector: 'ul',
},
But I think it would be better to use
items: {
type: 'array',
source: 'children',
selector: 'ul',
},
本文标签: javascriptAdd custom HTML markup to Gutenberg RichText
版权声明:本文标题:javascript - Add custom HTML markup to Gutenberg RichText 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741782153a2397373.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论