Mdx: Self-closing hyphenated shortcoded tag is different when not void

Created on 29 Aug 2019  路  4Comments  路  Source: mdx-js/mdx

Subject of the issue

Hi, I'm dealing with a strange behavior: if I set a shortcode like this:

const shortcodes = {
 "cc-image": Image,
}

<MDXProvider components={shortcodes}>
   <MDXRenderer>{data.post.body}</MDXRenderer>
</MDXProvider>

and I use it self-closed

# Title

Paragraph

<cc-image />

the rendered html is like:

<h1>Title</h1>
<p>Paragraph</p>
<div class='image'></div>

if I use the same component but not self-closed, the final html include an extra wrapper paragraph for the component itself:

# Title

Paragraph

<cc-image></cc-image>

the rendered html is like:

<h1>Title</h1>
<p>Paragraph</p>
<p>
   <div class='image'></div>
</p>

Expected behaviour

Even if not self-closed the component must not be wrapped in an extra paragraph.

I don't know why but it happens only if the shortcoded tag includes an hyphen :-/

duplicate 馃懐 馃悰 typbug

All 4 comments

Thanks for reporting! This looks like a bug in the remark tokenization.

Also, strangely enough, if there's a newline between the open and close tag it _is_ parsed they way we'd expect:

# Title

Paragraph

<cc-image>
</cc-image>

Weird indeed! This will be fixed in 2.0.0 as we鈥檙e rewriting the parser to solve amongst other things, this problem!

I鈥檝e confirmed this is indeed fixed in the v2 prerelease, so going to go ahead and close this.

If you want to give it a shot now: @mdx-js/mdx@next.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deligent-ant picture deligent-ant  路  3Comments

silvenon picture silvenon  路  4Comments

jxnblk picture jxnblk  路  3Comments

johno picture johno  路  4Comments

dioptre picture dioptre  路  3Comments