MdInput
A markdown editor component with live preview, syntax highlighting, and markdown toolbar
Installation
Terminal
Import
Component.tsx
Basic
Basic: Shows the default markdown input usage.
- Demonstrates a simple markdown editor with toolbar and preview.
- Use for basic markdown editing needs.
Keyboard Shortcuts
Keyboard Shortcuts: Demonstrates all supported keyboard shortcuts.
**Text Formatting:**
- `Cmd/Ctrl + B` — Bold text
- `Cmd/Ctrl + I` — Italic text
- `Cmd/Ctrl + K` — Insert link
**Code:**
- `Cmd/Ctrl + `` ` `` — Inline code
- `Cmd/Ctrl + Shift + `` ` `` — Code block
**Structure:**
- `Cmd/Ctrl + Shift + .` — Blockquote
- `Cmd/Ctrl + 1-6` — Heading levels (H1-H6)
**Mentions:**
- Type `@` followed by name to trigger mention menu
- Use `↑/↓` to navigate, `Enter/Tab` to select, `Esc` to close
Without Preview
Without Preview: Shows markdown input without preview tab.
- Only shows the write mode with toolbar.
- Useful when preview is not needed.
Only Preview
Only Preview: Shows markdown input with only preview tab.
- Only shows the preview tab.
- Useful when users prefer to see the preview of the markdown content.
Without Toolbar
Without Toolbar: Shows markdown input without toolbar.
- Only shows the textarea and preview tabs.
- Useful when users prefer keyboard shortcuts.
Read Only
Read Only: Shows markdown input in read-only mode.
- Displays content but prevents editing.
- Useful for displaying formatted content.
Disabled
Disabled: Shows markdown input in disabled state.
- Prevents all interactions.
- Useful for disabled form states.
Custom Height
Custom Height: Shows markdown input with custom minimum height.
- Allows customizing the editor height.
- Useful for different layout requirements.
Empty
Empty: Shows markdown input with empty initial value.
- Demonstrates the placeholder functionality.
- Useful for new content creation.
Custom Toolbar Actions
Custom Toolbar Actions: Shows markdown input with only specific toolbar actions.
- Demonstrates filtering toolbar actions using visibleActions prop on MdInput.Toolbar.
- Only shows bold, italic, and code actions.
- Useful when you want to limit available formatting options.
Lists Only
Lists Only: Shows markdown input with only list-related actions.
- Demonstrates toolbar with only list actions.
- Hides text formatting actions.
- Useful for structured content creation.
Git Hub Flavored Markdown
GitHub Flavored Markdown: Comprehensive test of all GitHub-supported Markdown formats.
- Headings (H1-H6)
- Text formatting (bold, italic, strikethrough, inline code)
- Lists (ordered, unordered, task lists)
- Code blocks with syntax highlighting
- Tables
- Blockquotes
- Links and images
- Horizontal rules
- Auto-links
- Mentions and issue references
- And more GitHub-specific features
Custom Layout
Custom Layout: Shows markdown input with custom layout using compound components.
- Demonstrates reordering components and custom styling.
- Use for unique design requirements.
Markdown supported
Custom Toolbar
Custom Toolbar: Shows markdown input with custom toolbar groups.
- Demonstrates how to create custom toolbar groups with different actions.
- Groups are automatically separated by dividers.
- Useful for creating specialized editing experiences.
With Mentions
With Mentions: Shows markdown input with
Custom Mention Format
Custom Mention Format: Shows markdown input with custom mention insertion format.
- Demonstrates custom onSelect callback to format inserted text.
- Inserts mentions with custom format including email.
- Useful for custom mention syntax or formatting requirements.
Mentions With Filtering
Mentions with Filtering: Shows markdown input with mention filtering.
- Type @ followed by characters to filter mentions.
- Menu updates in real-time as you type.
- Useful for large lists of mentionable items.
Mentions In Existing Content
Mentions in Existing Content: Shows markdown input with mentions in existing content.
- Demonstrates mention functionality with pre-filled content.
- Shows how mentions work alongside markdown formatting.
- Useful for editing existing content with mentions.
Custom Mention Rendering
Custom Mention Rendering: Shows markdown input with custom mention rendering component.
- Demonstrates how to customize the appearance of
Mention Rendering In Various Formats
Mention Rendering in Various Formats: Shows how mentions are rendered in different markdown contexts.
- Mentions in headings, paragraphs, lists, blockquotes, and links.
- Demonstrates that mentions work consistently across all markdown elements.
- Useful for testing mention rendering in various content structures.
Mention With Allowed Domains
Mention with Allowed Domains: Shows markdown input with allowed URL prefixes for mention images and links.
- Demonstrates how to configure allowedPrefixes to whitelist specific URL prefixes.
- The same prefix list applies to both links and images in markdown.
- Useful when mention components use external URLs that need to be whitelisted.
Whitelist Security
URL Whitelist Security: Demonstrates URL prefix whitelisting for links and images.
**Security Feature:**
For security reasons, URLs that are not in the whitelist will NOT be rendered.
You must manually add trusted domain prefixes to `allowedPrefixes` prop.
**How it works:**
- Only URLs starting with whitelisted prefixes are rendered as clickable links or images
- Non-whitelisted URLs are stripped or rendered as plain text
- This prevents XSS attacks, phishing links, and malicious content
**Example whitelist:**
```tsx
allowedPrefixes={[
"https://your-domain.com",
"https://trusted-cdn.com",
"https://api.dicebear.com"
]}
```
**Note:** This applies to both markdown links `[text](url)` and images ``.
Code Display
Code Display: Comprehensive demonstration of inline code and code blocks with syntax highlighting.
- Shows inline code with backticks.
- Demonstrates multi-line code blocks with language-specific syntax highlighting.
- Supports JavaScript, TypeScript, Python, JSON, HTML, CSS, Bash, and more.
- Code blocks powered by Shiki with automatic theme detection.
- Includes copy-to-clipboard functionality.
- Useful for technical documentation, tutorials, and API references.
API reference
| MdInputProps | Type | Default |
|---|---|---|
disabled | boolean |undefined | - |
mentionItems | MdInputMentionItemProps[] |undefined | - |
mentionOnSelect | ((item: MdInputMentionItemProps, query: string) => string) |undefined | - |
onChange | ((value: string) => void) |undefined | - |
readOnly | boolean |undefined | - |
value | string |undefined | - |