rondinabrybry / rich-text-editor
A modern, modular rich text editor built with pure JavaScript
Package info
github.com/rondinabrybry/rich-text-editor
Language:JavaScript
pkg:composer/rondinabrybry/rich-text-editor
dev-main
2026-03-02 10:31 UTC
This package is auto-updated.
Last update: 2026-03-02 10:32:35 UTC
README
A modern, modular, CKEditor-like rich text editor built with pure JavaScript.
Features
- đ¨ Rich Text Formatting - Bold, italic, underline, strikethrough, subscript, superscript
- đ Block Formatting - Headings (H1-H6), paragraphs, blockquotes, code blocks
- đ Lists - Ordered and unordered lists with indent/outdent
- đ¯ Text Alignment - Left, center, right, justify
- đ Links & Media - Insert links and images
- đ¨ Colors - Text color and background color pickers
- âŠī¸ History - Undo/redo with keyboard shortcuts
- đ Plugin System - Extensible architecture for custom features
- ⥠Zero Dependencies - Pure vanilla JavaScript
- âŋ Accessible - Keyboard navigation and ARIA attributes
- đą Responsive - Works on desktop and mobile devices
Quick Start
Basic Usage
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="src/styles/rte.css"> </head> <body> <div id="editor"></div> <script type="module"> import RTE from './src/index.js'; const editor = new RTE('#editor', { placeholder: 'Start typing...', minHeight: 300 }); </script> </body> </html>
With Textarea
<textarea id="my-editor"></textarea> <script type="module"> import RTE from './src/index.js'; const editor = new RTE('#my-editor'); // The textarea will be synced automatically </script>
Configuration Options
const editor = new RTE('#editor', { // Toolbar configuration toolbar: [ 'bold', 'italic', 'underline', '|', 'heading', '|', 'bulletList', 'orderedList', '|', 'link', 'image', '|', 'undo', 'redo' ], // Placeholder text placeholder: 'Start typing...', // Height settings height: 'auto', // or number in pixels minHeight: 200, // minimum height maxHeight: 500, // maximum height (enables scrolling) // Readonly mode readonly: false, // Auto focus on init autofocus: false, // Sanitize content (XSS protection) sanitize: true, // Additional plugins plugins: [] });
Toolbar Items
| Item | Description |
|---|---|
bold |
Bold text (Ctrl+B) |
italic |
Italic text (Ctrl+I) |
underline |
Underline text (Ctrl+U) |
strikethrough |
Strikethrough text |
subscript |
Subscript text |
superscript |
Superscript text |
heading |
Heading dropdown (H1-H6) |
paragraph |
Paragraph format |
blockquote |
Block quote |
codeBlock |
Code block |
horizontalRule |
Horizontal line |
bulletList |
Unordered list |
orderedList |
Ordered list |
indent |
Increase indent |
outdent |
Decrease indent |
alignLeft |
Align left |
alignCenter |
Align center |
alignRight |
Align right |
alignJustify |
Justify |
link |
Insert/edit link |
unlink |
Remove link |
image |
Insert image |
textColor |
Text color picker |
backgroundColor |
Background color picker |
undo |
Undo (Ctrl+Z) |
redo |
Redo (Ctrl+Y) |
clearFormatting |
Remove formatting |
| |
Separator |
API Reference
Getting/Setting Content
// Get HTML content const html = editor.getContent(); // Get sanitized HTML content const safeHtml = editor.getContent(true); // Set HTML content editor.setContent('<p>Hello World</p>'); // Get plain text const text = editor.getText(); // Set plain text editor.setText('Hello World'); // Clear content editor.clear(); // Check if empty const isEmpty = editor.isEmpty();
Word & Character Count
// Get word count const words = editor.getWordCount(); // Get character count const chars = editor.getCharacterCount(); // Get character count without spaces const charsNoSpaces = editor.getCharacterCount(true);
Focus Management
// Focus the editor editor.focus(); // Blur the editor editor.blur(); // Check if focused const hasFocus = editor.hasFocus();
Readonly Mode
// Set readonly editor.setReadonly(true); // Check readonly state const isReadonly = editor.isReadonly();
Events
// Content changed editor.on('content:change', () => { console.log('Content changed'); }); // Editor focused editor.on('focus', () => { console.log('Editor focused'); }); // Editor blurred editor.on('blur', () => { console.log('Editor blurred'); }); // Editor ready editor.on('ready', () => { console.log('Editor is ready'); }); // Remove listener const unsubscribe = editor.on('content:change', handler); unsubscribe(); // Remove the listener
Execute Commands
// Execute a formatting command editor.execute('bold'); editor.execute('italic'); // Execute with value editor.execute('heading', 'h2'); editor.execute('textColor', '#ff0000'); // Register custom command editor.registerCommand('myCommand', { execute: (value) => { // Your command logic }, isActive: () => { // Return true if command is active return false; }, isEnabled: () => { // Return true if command is enabled return true; } });
Destroy
// Destroy the editor editor.destroy();
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
| Ctrl+B | Bold |
| Ctrl+I | Italic |
| Ctrl+U | Underline |
| Ctrl+K | Insert link |
| Ctrl+Z | Undo |
| Ctrl+Y | Redo |
| Ctrl+Shift+Z | Redo |
Theming
The editor uses CSS custom properties for easy theming:
:root { /* Colors */ --rte-primary-color: #3b82f6; --rte-primary-hover: #2563eb; --rte-bg-color: #ffffff; --rte-text-color: #1f2937; --rte-border-color: #e5e7eb; /* Toolbar */ --rte-toolbar-bg: #f9fafb; /* Buttons */ --rte-button-hover: #e5e7eb; --rte-button-active: #dbeafe; /* Spacing */ --rte-spacing-sm: 8px; --rte-spacing-md: 12px; --rte-spacing-lg: 16px; /* Border radius */ --rte-radius-sm: 4px; --rte-radius-md: 6px; --rte-radius-lg: 8px; }
Browser Support
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
Project Structure
RTE Package/
âââ src/
â âââ core/
â â âââ rte.js # Main editor class
â â âââ event-manager.js # Event system
â â âââ plugin-manager.js # Plugin management
â â âââ command-manager.js # Command handling
â â âââ selection-manager.js # Selection utilities
â â âââ data-manager.js # Content management
â â âââ toolbar-manager.js # Toolbar creation
â âââ icons/
â â âââ icons.js # SVG icons
â âââ styles/
â â âââ rte.css # Editor styles
â âââ index.js # Main entry point
âââ demo/
â âââ index.html # Demo page
âââ package.json
âââ README.md
License
MIT License - feel free to use in personal and commercial projects.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
