Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prettier-plugin-mdx-no-text-child

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-mdx-no-text-child

Add this plugin as a dev dependency:

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Usage

Add this plugin as a dev dependency:

NPMYarn
$ npm i --dev prettier-plugin-mdx-no-text-child
yarn add -D prettier-plugin-mdx-no-text-child

And that's it, Prettier will automatically load the plugin based on the package name (prettier-plugin-*).

General Purpose

MDX is a markdown extension that allows insertion of JSX inside the Markdown markup. This is especially useful for referencing custom component.

Example:

# This is the header

<Info>

This is an info block.

</Info>

In MDX, the line break after the opening tag is meaningful and define what the child node is:

MDX markupJSX result
<Info>

This is a **paragraph**.

</Info>
<Info>
  <p>
    This is a <strong>paragraph</strong>.
  </p>
</Info>
MDX markupJSX result
<Info>
This is **not** a paragraph.
</Info>
<Info>
  This is **not** a paragraph.
</Info>

As custom components are often used in MDX to wrap other elements (i.e. an image with a caption), this behavior leads to mistakes and unexpected results.

Example:

MDX markupJSX result
<Info>
This is not a **paragraph**.

But **this one** is.
</Info>

<Info>
  This is not a **paragraph**.
  <p>
    But <strong>this one</strong> is.
  </p>
</Info>

See this issue for more context: https://github.com/mdx-js/mdx/issues/628

Prettier

Prettier supports MDX since the version 1.15.0. By default, Prettier formats the previous example as is:

<Info>
This is not a **paragraph**.

But **this one** is.
+
</Info>

Prettier inserts a line break before the closing tag, but it doesn't insert a line break after the opening tag because it would change the meaning of the code (and Prettier is only about formatting).

Well, this plugin does:

<Info>
+
This is not a **paragraph**.

But **this one** is.
+
</Info>

Roadmap

This is a 0.x version because this plugin is currently just smart enough to suit my own needs.

To enter 1.0, it needs to be more flexible and have options to exclude specific tags, or insert line breaks only if there are multiple children.

It more need more test cases, there are a LOT of untested situations where the formatting can go wrong.

FAQs

Package last updated on 12 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc