florentb / rehype-wrap-all

Wrap all matching elements with a given element
14 stars 2 forks source link

Wrap 2 siblings into one parent #3

Open ManasMadrecha opened 3 years ago

ManasMadrecha commented 3 years ago

Reproduction

['rehype-wrap-all', { selector: 'blockquote, blockquote+figcaption', wrapper: 'figure' }]

What is expected?

This should be converted

<blockquote>I am a blockquote</blockquote>
<figcaption></figcaption>

to this

<figure>
<blockquote>I am a blockquote</blockquote>
<figcaption></figcaption>
</figure>

What is happening?

This is being converted

<blockquote>I am a blockquote</blockquote>
<figcaption></figcaption>

to this

<figure>
<blockquote>I am a blockquote</blockquote>
</figure>
<figure>
<figcaption></figcaption>
</figure>

Need

Is there any way to wrap 2 siblings into one parent by this plugin. If not, is there any plugin to do so? I am using Nuxt + its Content module. Thank you

ChristianMurphy commented 3 years ago

@ManasMadrecha this makes sense, blockquote will get just that node, , is the css equivalent of "or", and blockquote+figcaption targets just the figure caption. If you want to merge them when they are adjacent, you could build something like https://github.com/syntax-tree/mdast-squeeze-paragraphs for figcaptions in rehype.