Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

md-to-react-email

codeskills-dev2.5mMIT5.0.5TypeScript support: included

A simple Markdown to jsx parser for email templates written in typescript.

markdown, react-email, jsx-email, md, email, jsx

readme

md-to-react-email

Read the documentation here

Description

md-to-react-email is a lightweight utility for converting Markdown into valid JSX that can be used in React-email or JSX-email templates. This tool simplifies the process of creating responsive and customizable email templates by leveraging the power of React and Markdown.

Note: Starting from version 4, md-to-react-email uses Marked for markdown transformation. see all changes here

Support

The following markdown flavors are supported

  • Offical markdown flavour

Installation

Install from your command line.

With yarn

yarn add md-to-react-email

With npm

npm install md-to-react-email

Features

Functions:

  • camelToKebabCase: converts strings from camelcase ['thisIsCamelCase'] to kebab case ['this-is-kebab-case']
  • parseCssInJsToInlineCss: converts css styles from css-in-js to inline css e.g fontSize: "18px" => font-size: 18px;
  • parseMarkdownToJSX: parses markdown to valid JSX for the client (i.e the browser)

Components:

  • EmailMarkdown: a react component that takes in markdown input and parses it directly in your code base

Usage:

  • Directly as React-email or JSX-email component

      ```
      import {EmailMarkdown} from "md-to-react-email"
    
      export default function EmailTemplate() {
      return (
              <Email>
                      <Head />
                      <Section>
                      <EmailMarkdown markdown={`# Hello, World!`} />
                      </Section>
              </Email>
      )
      }
      ```
  • Directly into react-email template

      ```
      import {parseMarkdownToJSX} from "md-to-react-email"
    
      const markdown = `# Hello World`
      const parsedReactMail = parseMarkdownToJSX({markdown})
    
      console.log(parsedReactMail) // `<h1 style="...valid inline CSS...">Hello, World!</h1>`
      ```

Components

md-to-react-email contains pre-defined react and html components for the email template structure and styling. You can modify these components to customize the look and feel of your email template.

The following components are available for customization:

  • Headers (h1 - h6)
  • BlockQuotes
  • Text: paragraphs, bold and italic text
  • Links
  • Code: Code blocks and inline code
  • Lists: ul, ol, li
  • Image
  • Line-breaks (br)
  • Horizontal-rule (hr)
  • Table: table, thead, tbody, th, td, tr
  • Strikethrough

Supported Email Clients

The provided React components and default styling are designed to work well across various email clients and providers. However, due to the inconsistent support for modern web standards in different email clients, it's recommended to test your email templates in multiple clients to ensure compatibility.

The following email clients are known to be supported:

  • Gmail
  • Apple Mail
  • Outlook (desktop and web)
  • Yahoo Mail
  • HEY Mail
  • Super Human
Gmail logo Apple Mail Outlook logo Yahoo! Mail logo HEY logo Superhuman logo
Gmail ✔ Apple Mail ✔ Outlook ✔ Yahoo! Mail ✔ HEY ✔ Superhuman ✔

Contributing

Contributions to md-to-react-email are welcome! If you find a bug, have suggestions for improvements, or want to add new features, feel free to open an issue or submit a pull request. Please make sure to follow the existing coding style and conventions.

When submitting a pull request, provide a clear description of the changes made and ensure that all tests pass. Adding appropriate tests for new features or bug fixes is highly appreciated.

Bugs and Feature Requests

For bugs and feature requests, please create an issue.

Author

License

md-to-react-email is licensed under the MIT License.

changelog

Change Log

5.0.5

Patch Changes

  • 7e344b3: Add support for React 19

5.0.4

Patch Changes

  • 612003c: Fix memory leak caused by how Marked custom renderer was used

5.0.3

Patch Changes

  • 5f1e815: Fixes inner error for styles like fontWeight: 500

5.0.2

Patch Changes

  • a916ef1: Fix: replace quotes in custom styles with html hex code

5.0.1

Patch Changes

  • 092dd65: ## Fixes

    • Markdown custom styles can't handle quotes properly

5.0.0

Major Changes

  • b6f11cc: Rename exports to be generic

    Removed

    • remove data-id attributes from components, utils and types
    • react-email peer and dev dependency

4.1.0

Minor Changes

  • c78e7e4: ### Changes

    • Remove DOMPurify from lib

    Fixes

    • Fixed unordered list ul styles

4.0.0

Major Changes

  • 3ae845c: ### Changes

    • Added Marked for markdown transformations
    • Removed ParseMarkdownToReactEmail function

    Fixes

    • Fixed issue with list parsing
    • Fixed parseCssInJsToInlineCss issue with numerical values

3.0.4

Patch Changes

  • b5f7677: ### Bug fixes

    • Fixed issue with parsing paragraphs
    • Converted bold and italics tag to and
    • Fixed issue with parsing nested blockquotes
    • Fixed issue with parsing code blocks

    Optimisations

    This PR added optimisations for the following:

    • Cleaning up unused style tags for the generated markup
    • Moved the changesets
    • Added CI workflows

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

3.0.3 (2023-07-04)

Features

  • Added checks to handle undefined | null | ''
  • Added checks to handle input that is not of type string

3.0.1 (2023-07-04)

Features

  • Added target="_blank" attribute to link tags

3.0.0 (2023-07-04)

Features

  • Made data-id attributes optional in rendered markup
  • Added sanitization for markdown output in react-email component
  • Updated parseMarkdownToReactEmailJSX function usage synthax

2.0.2 (2023-06-20)

Features

  • Removed data-id attributes from markup

2.0.1 (2023-06-20)

Features

  • Major Bug fix for parseMarkdownToReactEmailJSX
  • Major Bug fix for reactEmailMarkdown Component

1.2.0 (2023-06-15)

Features

  • Added support for tables from GFM
  • Added support for strikethrough from GFM

1.0.2 (2023-06-11)

Bug Fixes for commonJS

  • Updated Package.json

1.0.1 (2023-06-7)

https://github.com/codeskills-dev/md-to-react-email/releases/tag/v1.0.0

  • Updated README.md

1.0.0 (2023-06-7)

Note: Initial package release