Skip to content

Markdown

Render markdown strings as styled inline HTML for emails.

Parses markdown strings into HTML with inline styles applied to every element. Uses the marked library under the hood with a custom renderer that injects styles directly onto each HTML tag for email client compatibility.

Import

tsx
import { Markdown } from "@unmail/react";
vue
<script setup>
import { Markdown } from "@unmail/vue";
</script>

Usage

tsx
import { Markdown } from "@unmail/react";

const content = `
# Hello World

This is a **bold** statement with a [link](https://example.com).

- Item one
- Item two
`;

export function Email() {
  return (
    <Markdown
      markdownContainerStyles={{ padding: "16px", maxWidth: "600px" }}
      markdownCustomStyles={{
        h1: { fontSize: "28px", color: "#333" },
        link: { color: "#067df7" },
      }}
    >
      {content}
    </Markdown>
  );
}
vue
<script setup>
import { Markdown } from "@unmail/vue";

const content = `
# Hello World

This is a **bold** statement with a [link](https://example.com).

- Item one
- Item two
`;
</script>

<template>
  <Markdown
    :markdown-container-styles="{ padding: '16px', maxWidth: '600px' }"
    :markdown-custom-styles="{
      h1: { fontSize: '28px', color: '#333' },
      link: { color: '#067df7' },
    }"
  >
    {{ content }}
  </Markdown>
</template>

Props

PropTypeDefaultDescription
childrenstringThe markdown content to render. Required.
markdownCustomStylesMarkdownStylesTypeOverride styles for specific HTML elements.
markdownContainerStylesReact.CSSPropertiesStyles for the wrapper <div>.

Supported style keys

The markdownCustomStyles prop accepts an object with the following keys, each mapping to a CSSProperties value:

KeyTarget element
h1h6Heading elements
pParagraphs
bold<strong> / **text**
italic<em> / *text*
strikethrough<del> / ~~text~~
link<a> links
image<img> images
blockQuote<blockquote>
codeBlockFenced code blocks
codeInlineInline code
hrHorizontal rules
brLine breaks
table<table>
thead<thead>
tbody<tbody>
tr<tr>
td<td>
olOrdered lists
ulUnordered lists
liList items

Notes

  • The component uses React.forwardRef (React) to forward refs to the wrapper <div>.
  • All rendered HTML elements receive inline styles, which is required for email client compatibility since <style> blocks are stripped by many email clients.
  • The marked library handles the markdown parsing. Standard markdown syntax is supported.
  • Custom styles are merged with default styles — you only need to specify the properties you want to override.

Released under the MIT License.