A powerful, feature-rich React component specifically designed to create beautiful blog posts in markdown format with a strong focus on SEO. Transform your markdown content into stunning, search-engine optimised (SEO) articles with comprehensive metadata extraction and beautiful styling.
- π YAML Frontmatter Support: Extract SEO metadata directly from markdown files
- πΌοΈ Rich Media Components: Custom markdown syntax for images, videos, galleries, and iframes
- π Mermaid Diagrams: Beautiful flowcharts and diagrams with SVG rendering
- π’ LaTeX Math Support: Inline and block math equations with KaTeX
- π― Table of Contents: Auto-generated navigation with smooth scrolling
- π Dark/Light Theme: Built-in theme switching with system preference detection
- π± Responsive Design: Mobile-first design with Tailwind CSS
- β‘ Performance Optimised: Efficient rendering with React hooks and context
- π¨ Customisable: Easy to extend with custom components and styling
- π¨ Tailwind CSS v4: Modern styling with Tailwind CSS v4
# Clone the repository
git clone <your-repo-url>
cd beautiful-react-markdown-renderer
# Install dependencies
npm install
# Install math and diagram support
npm install remark-math rehype-katex katex
# Start development server
npm run dev
import { MarkdownRenderer } from './src/components/markdown/MarkdownRenderer';
const markdownContent = `
---
title: "My Blog Post"
description: "A comprehensive guide to markdown rendering"
author: "John Doe"
publishedDate: "2024-01-15"
tags: ["markdown", "react", "blog"]
---
# Welcome to My Blog Post
This is a **beautiful** markdown renderer with custom components!
## Math Support
Inline math: $E = mc^2$
Block math:
$$
\\sum_{i=1}^{n} i = \\frac{n(n+1)}{2}
$$
## Mermaid Diagrams
\`\`\`mermaid
graph TD
A[Start] --> B[Process]
B --> C[Decision]
C --> D[End]
\`\`\`
<img src="https://example.com/image.jpg" alt="Example image" />
<youtube id="dQw4w9WgXcQ" title="Example Video" />
`;
function App() {
return (
<MarkdownRenderer
content={markdownContent}
showToc={true}
enableMath={true}
/>
);
}
Add metadata to your markdown files using YAML frontmatter:
---
title: "Understanding Biblical Archaeology"
description: "A comprehensive overview of archaeological evidence supporting biblical narratives"
author: "Dr. Sarah Johnson"
publishedDate: "2024-01-15"
modifiedDate: "2024-01-20"
readTime: "8 min read"
category: "Archaeology"
tags: ["archaeology", "bible", "evidence", "history"]
image: "https://example.com/archaeology-image.jpg"
featured: true
draft: false
---
# Your content starts here...
Field | Type | Description |
---|---|---|
title |
String | Post title for SEO and display |
description |
String | Meta description (under 160 chars) |
author |
String | Post author name |
publishedDate |
String | Publication date (YYYY-MM-DD) |
modifiedDate |
String | Last modification date (YYYY-MM-DD) |
readTime |
String | Estimated reading time |
category |
String | Post category |
tags |
Array | Array of tags for filtering |
image |
String | Featured image URL |
featured |
Boolean | Whether to feature this post |
draft |
Boolean | Whether this is a draft |
Use single dollar signs for inline equations:
Einstein's famous equation: $E = mc^2$
The quadratic formula: $x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}$
Use double dollar signs for display equations:
$$
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
$$
$$
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
$$
Features:
- Powered by KaTeX for fast, beautiful rendering
- Supports full LaTeX math syntax
- Dark mode compatible
- Responsive and mobile-friendly
- Custom styled containers with gradient backgrounds
Create beautiful flowcharts and diagrams using Mermaid syntax:
\`\`\`mermaid
graph TD
A[Start] --> B[Process Data]
B --> C{Decision}
C -->|Yes| D[Execute]
C -->|No| E[Skip]
D --> F[End]
E --> F
\`\`\`
Supported Formats:
- Flowcharts (graph TD, graph LR)
- More diagram types render with fallback styling
Features:
- Custom SVG rendering with beautiful gradients
- Interactive hover effects
- Dark mode support
- Curved connectors with arrows
- Node labels and connection labels
- Responsive layout
<img src="https://placehold.co/600x400/png" alt="Tranquil Software" />
Features:
- Responsive width (
w-full
) - Automatic height (
h-auto
) - Rounded corners (
rounded-lg
) - Caption display below image
- Theme-aware styling
<youtube id="dQw4w9WgXcQ" title="Rick Astley - Never Gonna Give You Up" />
Features:
- Responsive 16:9 aspect ratio
- Full YouTube embed with controls
- Rounded corners container
- Fullscreen support enabled
<iframe src="https://www.google.com/maps/embed?KEYS" title="Tranquil Software" />
Features:
- Fixed height (
h-96
) - Full width responsive
- Rounded corners
- Fullscreen support
<imagegallery
title="My Photo Collection"
images='[{"src": "https://placehold.co/600x400/png", "alt": "Tranquil Software"}]'
/>
<imagegallery
title="Archaeological Findings"
images='[
{"src": "https://placehold.co/600x400/png", "alt": "Tranquil Software"},
{"src": "https://placehold.co/600x400/png", "alt": "Tranquil Software"}
]'
fullWidth={true}
centerThumbnails={true}
thumbnailOptions='{"width": 300, "height": 200, "borderRadius": 8, "gap": 16}'
/>
Prop | Type | Default | Description |
---|---|---|---|
title |
String | "" | Gallery title |
images |
Array | [] | Array of image objects with src and alt |
fullWidth |
Boolean | false | Whether gallery should take full width |
centerThumbnails |
Boolean | false | Whether to center thumbnails |
thumbnailOptions |
Object | {...} | Thumbnail customization options |
Option | Type | Default | Description |
---|---|---|---|
width |
Number | 200 | Thumbnail width |
height |
Number | 150 | Thumbnail height |
borderRadius |
Number | 8 | Corner radius |
gap |
Number | 12 | Spacing between thumbnails |
MarkdownRenderer (Main entry point)
βββ MarkdownProvider (Context provider)
βββ MarkdownContentWrapper (Layout + TOC)
β βββ TableOfContents (Navigation)
β βββ MarkdownContent (ReactMarkdown wrapper)
β βββ Headings (h1-h6 with TOC registration)
β βββ Text (paragraphs, links, emphasis)
β βββ Lists (ul, ol, li)
β βββ CodeBlock (syntax highlighting)
β βββ Table (responsive tables)
β βββ Media (custom components)
β βββ MermaidDiagram (flowchart rendering)
β βββ Math (LaTeX equation rendering)
βββ ThemeContext (Dark/Light mode)
- ThemeContext.tsx: Manages dark/light theme state
- useToc.ts: Hook for table of contents functionality
- markdownParser.ts: Parses YAML frontmatter and extracts metadata
- SEO.tsx: Handles meta tags and SEO optimization
- MermaidDiagram.tsx: Custom SVG flowchart renderer
- Math.tsx: LaTeX math equation renderer with KaTeX
Markdown File (.md)
β
markdownParser.ts (extracts metadata + content)
β
[slug].tsx (loads post data + metadata)
β
BlogPost.tsx (wraps with ReadMeter)
β
MarkdownRenderer.tsx (renders markdown)
β
Remark Plugins (remarkGfm, remarkMath)
β
Rehype Plugins (rehypeRaw, rehypeHighlight, rehypeKatex)
β
Individual Components (Headings, Text, Lists, Math, Mermaid, etc.)
β
Final Rendered HTML + CSS + Theme
// colors.ts
export const textColors = {
primary: 'text-gray-900 dark:text-gray-100',
secondary: 'text-gray-600 dark:text-gray-400',
muted: 'text-gray-500 dark:text-gray-500',
// ... more colors
};
export const bgColors = {
primary: 'bg-white dark:bg-gray-900',
secondary: 'bg-gray-50 dark:bg-gray-800',
// ... more colors
};
src/
βββ components/
β βββ markdown/
β β βββ MarkdownRenderer.tsx
β β βββ components/
β β β βββ Headings.tsx
β β β βββ Text.tsx
β β β βββ Lists.tsx
β β β βββ CodeBlock.tsx
β β β βββ Table.tsx
β β β βββ Media.tsx
β β β βββ MermaidDiagram.tsx
β β β βββ Math.tsx
β β βββ context/
β β β βββ ThemeContext.tsx
β β βββ hooks/
β β β βββ useToc.ts
β β βββ markdownParser.ts
β βββ blog/
β βββ BlogPage.tsx
β βββ BlogPost.tsx
β βββ [slug].tsx
βββ lib/
β βββ utils.ts
β βββ colors.ts
βββ styles/
βββ markdown.css
To enable math support in your markdown, install the following dependencies:
npm install remark-math rehype-katex katex
npm install --save-dev @types/katex
beautiful-react-markdown-renderer/
βββ public/
β βββ assets/
β βββ favicon/
β βββ posts/
βββ src/
β βββ components/
β βββ data/
β βββ lib/
β βββ pages/
βββ index.html
βββ package.json
βββ tailwind.config.js
βββ tsconfig.json
βββ vite.config.ts
Prop | Type | Default | Description |
---|---|---|---|
content |
String | "" | Markdown content to render |
showToc |
Boolean | false | Whether to show table of contents |
className |
String | "" | Additional CSS classes |
enableMath |
Boolean | true | Enable LaTeX math rendering |
const { registerHeading, activeHeading } = useToc();
const { metadata, content } = parseMarkdownWithFrontmatter(markdown);
- remarkGfm: GitHub Flavored Markdown (tables, strikethrough, etc.)
-
remarkMath: Parses LaTeX math syntax (
$...$ and$$...$$ )
- rehypeRaw: Allows raw HTML in markdown
- rehypeHighlight: Syntax highlighting for code blocks
- rehypeKatex: Renders LaTeX math equations with KaTeX
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Free forever. Tranquil Software certified. β€οΈ
- Built with React
- Styled with Tailwind CSS
- Markdown parsing with ReactMarkdown
- Math rendering with KaTeX
- Diagram support inspired by Mermaid
Made with β€οΈ for beautiful markdown rendering by Tranquil Software