micromark / micromark-extension-mdx-jsx

micromark extension to support MDX or MDX.js JSX
https://unifiedjs.com
MIT License
8 stars 4 forks source link

Attempt to reintroduce commonmark behavior #11

Closed iczero closed 8 months ago

iczero commented 8 months ago

Initial checklist

Description of changes

This is a proof of concept to reintroduce CommonMark-style HTML blocks to MDX. I would like to request comments on these changes.

Currently, MDX parses

<div class="test">
  content.
</div>

as

<div class="test">
  <p>content.</p>
</div>

The content within the tags is parsed as a paragraph, but this is often not wanted. CommonMark specifies this behavior to only occur if there is a blank line after the tag, as such:

<div class="test">

content.

</div>

but this is needlessly restrictive when you want markdown syntax within flow elements.

This change introduces a configuration option to parse content within flow elements as inline markdown. Paragraph wrapping can be restored by adding a blank line, as in CommonMark.

Examples:

input ===================output ===================
```md
*Hello.*
```
```html
Hello.
```
```md
*Test*
```
```html

Test

```
```md
Inline
a ```
```html

Inline
a

```

Configuration is done by setting preferInline (bad name, please advise) when creating the extension: mdxJsx({ acorn, acornOptions, addResult: true, preferInline: true }).

I am currently writing tests for this feature and will update the PR when I have good coverage.

I intend to maintain this patch set into the future because I am currently working on a project which wants this feature. I am opening this PR for the primary purpose of gathering feedback. If this feature is not wanted, please close this PR.

Finally, I would like to offer my sincere gratitude for the authors of micromark and related packages. Markdown truly is horrible to parse, and micromark makes everything so much easier.

Things that need fixing

This does not work because expressions are not handled: fixed hopefully

<div>{'<'}</div>

This does not work:

<a>`<`</a>
<a>**<Test />**</a>
github-actions[bot] commented 8 months ago

Hi! It seems some of the things asked in the template are missing? Please edit your post to fill out everything.

You won’t get any more notifications from me, but I’ll keep on updating this comment, and remove it when done!

If you need it, here’s the original template ```markdown ### Initial checklist * [ ] I read the support docs * [ ] I read the contributing guide * [ ] I agree to follow the code of conduct * [ ] I searched issues and couldn’t find anything (or linked relevant results below) * [ ] If applicable, I’ve added docs and tests ### Description of changes TODO ```

Thanks, — bb

JounQin commented 8 months ago

Hi, @iczero .

You'd better to create a related issue first actually.

iczero commented 8 months ago

The current approach does not work. Will try another one.

ChristianMurphy commented 8 months ago

See https://github.com/micromark/micromark-extension-mdx-jsx/issues/12#issuecomment-1875713767 for commentary on approach and ideas on how to (and not to) proceed.

iczero commented 8 months ago

The approach in this PR is fundamentally incorrect. (Un)fortunately, I have not run out of ideas yet.

github-actions[bot] commented 8 months ago

Hi! This was closed. Team: If this was merged, please describe when this is likely to be released. Otherwise, please add one of the no/* labels.