npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

remark-mdx-disable-explicit-jsx

v0.1.0

Published

Remark plugin to reenable styling of html tags with 'components' prop

Downloads

30,629

Readme

remark plugin to reenable styling of html tags with 'components' prop in mdx v2.

What is this?

Let's say you have the following mdx file:

<h2>Hello one!</h2>

## Hello two!

And you use it in your react code like this:

import MDXComponent from "./text.mdx";

const componetns = {
  h2: (props) => <h2 className="header" {...props} />,
};

export default function () {
  return <MDXComponent components={components} />;
}

Then, in mdx v1 and mdx v2 before [email protected], generated html on the page will be this:

<h2 class="header">Hello one!</h2>

<h2 class="header">Hello two!</h2>

But this behavior was changed in [email protected]. With this version of mdx, the result will be:

<h2>Hello one!</h2>

<h2 class="header">Hello two!</h2>

For the reasons why it was changed, check this issue.

But now we have a problem because there are a lot of use cases that require you to use html in your markdown. For example:

<a href="#" download>You can't add params to links without html</a>.

<table>
  <tbody>
    <tr>
      <td>
        <ul>
          <li>You can't use lists inside the table without html.</li>
        </ul>
      </td>
    </tr>
  </tbody>
</table>

So, if you have one of these use cases and want to reenable old behavior, you can use this plugin for it.

Install

This package is ESM only.

Install with npm:

npm install remark-mdx-disable-explicit-jsx

Install with yarn:

yarn add remark-mdx-disable-explicit-jsx

Use

To use with @mdx-js/loader, add the plugin to the loader's options inside webbpack's config:

import remarkMdxDisableExplicitJsx from "remark-mdx-disable-explicit-jsx";

// ...

{
  test: /\.mdx?$/,
  use: [
    {
      loader: '@mdx-js/loader',
      options: {
        remarkPlugins: [
          remarkMdxDisableExplicitJsx,
        ]
      }
    }
  ]
}

To use directly with @mdx-js/mdx compile, add the plugin to the options:

import { compile } from "@mdx-js/mdx";
import remarkMdxDisableExplicitJsx from "remark-mdx-disable-explicit-jsx";

await compile(file, { remarkPlugins: [remarkMdxDisableExplicitJsx] });

To use the plugin with options, add them this way:

import remarkMdxDisableExplicitJsx from "remark-mdx-disable-explicit-jsx";

// ...

{
  test: /\.mdx?$/,
  use: [
    {
      loader: '@mdx-js/loader',
      options: {
        remarkPlugins: [
          [remarkMdxDisableExplicitJsx, { whiteList: ["h1", "a"] }],
        ]
      }
    }
  ]
}

Options

If the plugin is used without options, it will enable styling for all html tags. If you only want to enable it for some tags, you can use whiteList and blackList options.

options.whiteList

An array of html tag names. For example, to make h1 and a stylable, use these options:

{
    whiteList: ["h1", "a"],
}

options.blackList

An array of html tag names. For example, to style everything, but h1, use these options:

{
    blackList: ["h1"],
}