Code Monkey home page Code Monkey logo

mui-markdown's Introduction

About

mui-markdown uses markdown-to-jsx and MUI(formerly material-ui) to help you render MD/MDX files with MUI components.

User Guide

Installation

# with npm
npm i mui-markdown

# with yarn
yarn add mui-markdown

Usage

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

import React from 'react';
import MuiMarkdown from 'mui-markdown';

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

export default App;

Props

Props available for MuiMarkdown component:

Name Type Default Optional or Mandatory
key React.key optional
overrides MarkdownToJSX.Overrides optional
options MarkdownToJSX.Options optional
disableTableContainer boolean false optional
blockquoteBorderColor string MUI info color optional
inlineCodeBgColor string rgba(127, 127, 127, 0.2) optional
inlineCodeColor string currentcolor optional
codeBlockTheme PrismTheme vsDark optional

overrides

You can optionally override a tag to use your component.

example of override with a regular HTML tag:

JS and JSX:

import React from 'react';
import MuiMarkdown from 'mui-markdown';

const App = () => {
  return (
    <MuiMarkdown
      overrides={{
        h1: {
          component: 'p',
          props: {
            style: { color: 'red' },
          },
        },
      }}
    >
      {`# Hello markdown`}
    </MuiMarkdown>
  );
};

export default App;

TS and TSX:

import React from 'react';
import MuiMarkdown from 'mui-markdown';

const App = () => {
  return (
    <MuiMarkdown
      overrides={{
        h1: {
          component: 'p',
          props: {
            style: { color: 'red' },
          } as React.HTMLProps<HTMLParagraphElement>,
        },
      }}
    >
      {`# Hello markdown`}
    </MuiMarkdown>
  );
};

export default App;

example of override with your component:

JS and JSX:

import React from 'react';
import MuiMarkdown from 'mui-markdown';
import CustomTypography from './components/CustomTypography';

const App = () => {
  return (
    <MuiMarkdown
      overrides={{
        h1: {
          component: CustomTypography,
          props: {
            // custom props
          },
        },
      }}
    >
      {`# Hello markdown`}
    </MuiMarkdown>
  );
};

export default App;

TS and TSX:

import React from 'react';
import MuiMarkdown from 'mui-markdown';
import CustomTypography, {
  CustomTypographyProps,
} from './components/CustomTypography';

const App = () => {
  return (
    <MuiMarkdown
      overrides={{
        h1: {
          component: CustomTypography,
          props: {
            // custom props
          } as CustomTypographyProps,
        },
      }}
    >
      {`# Hello markdown`}
    </MuiMarkdown>
  );
};

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 MuiMarkdown component.

disableTableContainer

Optionally you can disable container wrapper around tables. If true, table component will be like this:

  <Table>
    {children}
  <Table>

default(false):

<TableContainer component={Paper}>
  <Table>
    {children}
  <Table>
</TableContainer>

blockquoteBorderColor

You can change the blockquote component border color with this property. The default color is theme.palette.info.main

example:

...
<MuiMarkdown blockquoteBorderColor='gold'>
{
  `> This is a block of code`
}
</MuiMarkdown>
...

inlineCodeBgColor

This property helps you change the inline code background color.

example:

...
<MuiMarkdown inlineCodeBgColor='gold'>
{
  '<p>Install the package via `npm i mui-markdown` or `yarn add mui-markdown`</p>'
}
</MuiMarkdown>
...

inlineCodeColor

With this property you're able to change inline code text color.

example:

...
<MuiMarkdown inlineCodeColor='dodgerblue'>
{
  '<p>Install the package via `npm i mui-markdown` or `yarn add mui-markdown`</p>'
}
</MuiMarkdown>
...

codeBlockTheme

mui-markdown uses prism-react-renderer to highlight code blocks. With this property you can change the highlight theme. Availabe themes are:

  • dracula
  • duotoneDark
  • duotoneLight
  • github
  • nightOwl
  • nightOwlLight
  • oceanicNext
  • okaidia
  • palenight
  • shadesOfPurple
  • synthwave84
  • ultramin
  • vsDark
  • vsLight

mui-markdown's People

Contributors

hpouyanmehr avatar ardeaf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.