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

mdx-tailor

v0.1.3

Published

A custom MDX library for transforming markdown into styled components. Works best in Nextjs App router and with tailwindCSS

Downloads

2

Readme

mdx-tailor 🪡✨

NPM Version License

mdx-tailor is a fully typed Markdown to JSX transformer library, designed to empower developers to style Markdown content with custom MDX components 🎨 and bring it to life as React components. With type inference and flexible configuration, mdx-tailor enables a seamless developer experience 🚀.

Works best with Next.js and other React frameworks.

Features 🌟

  • Fully Typed: Leverage TypeScript for strong typing throughout the library.
  • Configurable: Easily define your Markdown transformation rules and styles with a comprehensive configuration object.
  • Type Inference for Configurations: No need for verbose type annotations—enjoy automatic type inference for your configurations.
  • Custom Styling (using TailwindCSS): Define styled components for your Markdown elements, providing endless creative possibilities.

Installation 💾

Install mdx-tailor using npm:

npm install mdx-tailor

Or with bun:

bun install mdx-tailor

Usage 🛠️

Import your custom styled components and the mdxTailor function, along with your configuration:

import { MDXTailor } from "mdx-tailor";
import components from "./path-to-your-styled-components";
import mdxConfig from "./path-to-your-mdx-config";

const mdx = MDXTailor({ config: mdxConfig, styled_components: components });

Use the getMDXData method to transform and retrieve your Markdown content as valued JSX elements:

function MyMarkdownComponent() {
  const markdownContent = `
  ---
  title: Amazing Title
  author: John Doe
  ---

  ## Subheading

  - List
  - Of
  - Items
  `;

  const data = mdx.getMDXData(markdownContent, "toolkit");

  // Now render your Markdown content as JSX!
  return (
    <div>
      {data && (
        <>
          <h1>{data.metadata.title}</h1>
          <h2>{data.metadata.author}</h2>
          {mdx.markdownToJSX(data.content)}
        </>
      )}
    </div>
  );
}

Custom Styled Components ✒️

You can define your own styled components to control how each Markdown element looks. For example:

import { cn } from "@/lib/utils";

export const components = {
  h1: (props) => <h1 {...props} className={cn("text-xl font-bold", props.className)} />,
  h2: (props) => <h2 {...props} className={cn("text-lg text-red-500 font-bold", props.className)} />,
  // Add more custom styled components...
};

export default components;

Now you can import these components and use them with mdx-tailor to render your markdown content with custom styles.

Configuration :gear:

Define your MDX configurations for robust document structure and metadata typing. Below is an example configuration:

const mdxConfig = {
  workDir: "/src/server/mdx",
  // Define your routes with associated metadata
  routes: [
    {
      name: "toolkit",
      path: "/toolkit",
      folder: "/cheatsheet",
      // Define metadata fields for the route
      metadata: [
        { name: "author", type: "string", required: true },
        // ...additional metadata fields
      ],
    },
    // ...additional routes
  ],
};

export default mdxConfig;

By utilizing TypeScript, mdx-tailor automatically infers the types for provided configurations, ensuring your metadata aligns with the expected types and structure.

Contributing 🤝

We welcome contributions of all kinds — whether you're fixing bugs, adding new features, or improving documentation. Your contributions are invaluable to the community.

License 📜

mdx-tailor is open-sourced software licensed under the MIT license.

Contact 📧

Made with ❤️ by - @xcaeser

Project Link: https://github.com/xcaeser/mdx-tailor