A powerful, Notion-like block editor library for React with rich text formatting, syntax highlighting, and LaTeX support.
- 🧱 Block-based Architecture: Everything is a block (paragraphs, headings, images, etc.)
- ✨ Rich Text Formatting: Bold, italic, underline, code, and links
- 🎨 Syntax Highlighting: Code blocks with Prism.js support
- 📐 LaTeX Support: Mathematical formulas with KaTeX
- 🌙 Dark Mode: Built-in dark/light theme support
- 📱 Responsive: Works on desktop and mobile
- 🎯 TypeScript: Full TypeScript support
- 🎨 Customizable: Easy to style and extend
npm install block-text
import React, { useState } from "react";
import { BlockEditor, BlockRenderer, Block, createBlock } from "block-text";
function App() {
const [blocks, setBlocks] = useState<Block[]>([
createBlock("heading1", "Welcome to Block Editor"),
createBlock("paragraph", "Start typing your content here..."),
]);
return (
<div>
<BlockEditor blocks={blocks} onChange={setBlocks} isDarkMode={false} />
<BlockRenderer blocks={blocks} />
</div>
);
}
- Paragraph: Multi-line text with formatting
- Heading 1, 2, 3: Different heading levels
- Quote: Styled quote blocks
- Code Block: Syntax-highlighted code with language support
- Formula: LaTeX mathematical expressions
- Image: Image blocks with alt text and captions
- Callout: Highlighted information blocks
- Divider: Visual separators
- Bullet List: Unordered lists with nested items
- Numbered List: Ordered lists with nested items
Main editor component for creating and editing blocks.
<BlockEditor
blocks={Block[]}
onChange={(blocks: Block[]) => void}
isDarkMode?: boolean
className?: string
/>
Component for rendering blocks in read-only mode.
<BlockRenderer
blocks={Block[]}
className?: string
/>
Creates a new block with the specified type and content.
createBlock(
type: Block["type"],
content?: string,
metadata?: any
): Block
Creates a text segment with formatting.
createTextSegment(
text: string,
formats: Format[] = []
): TextSegment
- Enter: New line (in paragraphs)
- Shift+Enter: New block
- Ctrl/Cmd+B: Bold
- Ctrl/Cmd+I: Italic
- Ctrl/Cmd+U: Underline
- Ctrl/Cmd+K: Code formatting
The library uses Tailwind CSS classes. You can customize the appearance by:
- Overriding CSS classes
- Using the
className
prop on components - Modifying the dark mode implementation
- JavaScript, TypeScript
- Python, Java, C#, C, C++
- HTML, CSS, JSON, YAML
- SQL, Bash, Markdown
- And many more via Prism.js
E = mc^2
\frac{1}{2}mv^2
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
# Install dependencies
npm install
# Build library
npm run build
# Watch mode for development
npm run dev
MIT
Contributions are welcome! Please feel free to submit a Pull Request.