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

joyui-markdown

v1.0.1

Published

joyui-markdown uses markdown-to-jsx and JoyUI(from MUI) to help you render MD/MDX files with JoyUI components.

Downloads

11

Readme

JoyUI Markdown

About

joyui-markdown uses markdown-to-jsx and JoyUI(from MUI) to help you render MD/MDX files with JoyUI components.

User Guide

Installation

# with npm
npm i joyui-markdown@latest

# with yarn
yarn add joyui-markdown

Usage

The example below will render the h1 tag using JoyUI Typography component.

import React from 'react';
import { JoyuiMarkdown } from 'joyui-markdown';
// You can also use
// import JoyuiMarkdown from 'joyui-markdown';
// But the first approach is recommended.

const App = () => {
  return <JoyuiMarkdown>{`# Hello markdown!`}</JoyuiMarkdown>;
};

export default App;

Props

Props available for JoyuiMarkdown component:

| Name | Type | Default | Optional or Mandatory | | ----------------- | ----------------------- | ---------------- | --------------------- | | key | React.key | - | optional | | children | string | - | optional | | overrides | MarkdownToJSX.Overrides | defaultOverrides | optional | | options | MarkdownToJSX.Options | - | optional | | codeWrapperStyles | CSSProperties | - | optional | | prismTheme | PrismTheme | vsDark | optional | | Highlight | HighlightComponent | - | optional | | themes | HighlightThemes | - | optional | | hideLineNumbers | boolean | false | optional |

NOTE: You cannot use overrides and options at the same time.

overrides

You can optionally override a tag to use your component.

An example of override with a regular HTML tag:

JS and JSX:

import React from 'react';
import { JoyuiMarkdown, getOverrides } from 'joyui-markdown';

const App = () => {
  return (
    <JoyuiMarkdown
      overrides={{
        ...getOverrides({}), // This will keep the other default overrides.
        h1: {
          component: 'p',
          props: {
            style: { color: 'red' },
          },
        },
      }}
    >
      {`# Hello markdown!`}
    </JoyuiMarkdown>
  );
};

export default App;

TS and TSX:

import React from 'react';
import { JoyuiMarkdown, getOverrides } from 'joyui-markdown';

const App = () => {
  return (
    <JoyuiMarkdown
      overrides={{
        ...getOverrides(), // This will keep the other default overrides.
        h1: {
          component: 'p',
          props: {
            style: { color: 'red' },
          } as React.HTMLProps<HTMLParagraphElement>,
        },
      }}
    >
      {`# Hello markdown!`}
    </JoyuiMarkdown>
  );
};

export default App;

An example of override with your component:

JS and JSX:

import React from 'react';
import { JoyuiMarkdown, getOverrides } from 'joyui-markdown';
import CustomTypography from './components/CustomTypography';

const App = () => {
  return (
    <JoyuiMarkdown
      overrides={{
        ...getOverrides(), // This will keep the other default overrides.
        h1: {
          component: CustomTypography,
          props: {
            // custom props
          },
        },
      }}
    >
      {`# Hello markdown!`}
    </JoyuiMarkdown>
  );
};

export default App;

TS and TSX:

import React from 'react';
import { JoyuiMarkdown, getOverrides } from 'joyui-markdown';
import CustomTypography, {
  CustomTypographyProps,
} from './components/CustomTypography';

const App = () => {
  return (
    <JoyuiMarkdown
      overrides={{
        ...getOverrides(), // This will keep the other default overrides.
        h1: {
          component: CustomTypography,
          props: {
            // custom props
          } as CustomTypographyProps,
        },
      }}
    >
      {`# Hello markdown!`}
    </JoyuiMarkdown>
  );
};

export default App;

options

You can read about options in the markdown-to-jsx docs.

Note: If you want to override something and also need to set some options, add the overrides property in the options. Don't use overrides and options property together on the JoyuiMarkdown component.

codeWrapperStyles

You can pass your desired styles for the syntax highlighter component. These are the default styles:

  ...
  borderRadius: '0.5rem',
  padding: '0.5rem 0.75rem',
  overflow: 'auto',
  ...

Syntax Highlight

joyui-markdown uses prism-react-renderer to highlight code blocks. As this is an optional dependencies, you need to install it if you want to have a syntax highlighter. So to highlight your code:

  • First install prism-react-renderer
# with npm
npm i prism-react-renderer

# with yarn
yarn add prism-react-renderer
  • Then pass the Highlight and the themes to the JoyuiMarkdown component
import React from 'react';
import { JoyuiMarkdown } from 'joyui-markdown';
import { Highlight, themes } from 'prism-react-renderer';

const App = () => {
  return (
    <JoyuiMarkdown
      Highlight={Highlight}
      themes={themes}
      prismTheme={themes.github}
    >
      {`# Hello markdown!`}
    </JoyuiMarkdown>
  );
};

export default App;

With the prismTheme property you can change the highlight theme.

import React from 'react';
import { JoyuiMarkdown } from 'joyui-markdown';
import { Highlight, themes } from 'prism-react-renderer';

const App = () => {
  return (
    <JoyuiMarkdown
      Highlight={Highlight}
      themes={themes}
      prismTheme={themes.github}
    >
      {`# Hello markdown!`}
    </JoyuiMarkdown>
  );
};

export default App;

Also to disable the line numbers in the code block you can use the hideLineNumbers.

import React from 'react';
import { JoyuiMarkdown } from 'joyui-markdown';
import { Highlight, themes } from 'prism-react-renderer';

const App = () => {
  return (
    <JoyuiMarkdown
      Highlight={Highlight}
      themes={themes}
      prismTheme={themes.github}
      hideLineNumbers
    >
      {`# Hello markdown!`}
    </JoyuiMarkdown>
  );
};

export default App;

When you use overrides, you can have the syntax highlight by passing the Highlight, themes, and themes.github (or your favorite one) to the getOverrides function.

import React from 'react';
import { JoyuiMarkdown, getOverrides } from 'joyui-markdown';
import { Highlight, themes } from 'prism-react-renderer';

const App = () => {
  return (
    <JoyuiMarkdown
      overrides={{
        ...getOverrides({ Highlight, themes, theme: themes.github }), // This will keep the other default overrides.
        h1: {
          component: 'p',
          props: {
            style: { color: 'red' },
          },
        },
      }}
    >
      {`# Hello markdown!`}
    </JoyuiMarkdown>
  );
};

export default App;

Backers