Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to reintroduce commonmark behavior #11

Closed
wants to merge 2 commits into from

Conversation

iczero
Copy link

@iczero iczero commented Jan 3, 2024

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) Previous issues on this issue were understandably rejected. I would like to introduce a configuration option for this change.
  • If applicable, I’ve added docs and tests (TODO: I am currently writing tests.)

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 ===================
<div>
  *Hello.*
</div>
<div>
  <em>Hello.</em>
</div>
<div>

*Test*

</div>
<div>
  <p>
    <em>Test</em>
  </p>
</div>
<div>
  Inline
</div> a
<p>
  <div>
    Inline
  </div>
  a
</p>

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 github-actions bot added the 👋 phase/new Post is being triaged automatically label Jan 3, 2024

This comment has been minimized.

@iczero iczero force-pushed the jsx-flow-to-inline branch from a592fe0 to b31b519 Compare January 3, 2024 07:27
@JounQin
Copy link
Member

JounQin commented Jan 3, 2024

Hi, @iczero .

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

@iczero
Copy link
Author

iczero commented Jan 3, 2024

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

@ChristianMurphy
Copy link
Member

See #12 (comment) for commentary on approach and ideas on how to (and not to) proceed.

@iczero
Copy link
Author

iczero commented Jan 5, 2024

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

@iczero iczero closed this Jan 5, 2024

This comment has been minimized.

@wooorm wooorm added the 🤷 no/invalid This cannot be acted upon label Jan 5, 2024
@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 👋 phase/new Post is being triaged automatically labels Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤷 no/invalid This cannot be acted upon 👎 phase/no Post cannot or will not be acted on
Development

Successfully merging this pull request may close these issues.

4 participants