Welcome to MarkdownEditor, the leading open source JavaScript markdown editor plugin. Enjoy a simple, powerful, and embeddable markdown editor with real-time preview, syntax highlighting, responsive design, and seamless integration for all web projects.
- Overview
- Installation
- Usage
- Markdown Content Retrieval
- Set Markdown Content to Editor
- Configuration Options
- Toolbar Customization
- Example Implementations
- Contribution Guidelines
- License
- ✅ Actively Maintenaning: The plugin receives regular updates to stay up to date.
- ✅ User-Friendly: It offers a WYSIWYG-style interface, making it great for non-technical users.
- ✅ Simple Markdown Get/Set: No complicated techniques are required to get and set the markdown content. You can use the <textarea> value or name attribute to get and set markdown content.
- ✅ Responsive: The editor is fully responsive, providing a seamless experience across all screen sizes.
- ✅ RTL Support: By default Right-to-Left (RTL) text is supported, making it ideal for languages like Arabic, Urdu, and Farsi.
- ✅ Module Support: Supports ESM, UMD, and CommonJS modules, making it easy to integrate with different module systems.
- ✅ Live Preview Mode: Watch your markdown content render while you type, providing a real-time preview of formatting, links, images, and more.
- ✅ Automatic Dark Mode Support: The editor follows your system's or website's dark mode settings, giving a seamless experience.
The MarkdownEditor Plugin is designed to be the best, simple, and embeddable JavaScript markdown editor plugin available. It is an open source project that boasts:
- Real-time Preview: See your markdown rendered instantly as you type.
- Syntax Highlighting: Enhanced readability with clear code and markdown formatting.
- Easy Integration: Seamlessly integrate into any web project with minimal setup.
- Customizable Toolbar: Dynamically configure and reorder toolbar options like bold, italic, and more.
Integrating the MarkdownEditor Plugin into your project is straightforward. You can install it using NPM, import the JavaScript file directly, or use a CDN for rapid deployment.
For projects utilizing bundling tools like Webpack, run:
npm install markdown-text-editor
After installation, import the MarkdownEditor
class from the package:
import MarkdownEditor from "markdown-text-editor";
To get started, include a <textarea>
element in your HTML and initialize the editor by targeting its container:
<textarea class="editor-container"></textarea>
const editor = new MarkdownEditor('.editor-container', {
placeholder: 'Write your markdown...',
toolbar: ['heading', 'bold', 'italic', 'strikethrough', 'ul', 'ol', 'checklist', 'blockquote', 'link', 'preview'],
});
import the CSS file directly in your js code:
import 'markdown-text-editor/dist/markdown-text-editor.css';
Alternatively, include the following CDN links in your HTML:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/markdown-text-editor.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/markdown-text-editor.min.css">
In this method, you can access the markdown content entered into the editor directly using JavaScript. This is helpful when you want to dynamically retrieve the value and process it in your application (e.g., displaying it elsewhere or sending it via AJAX).
<form>
<textarea class="editor-container h-48" rows="5"></textarea>
<button type="button" id="submit-btn">Submit</button>
<div class="output"></div>
</form>
const editor = new MarkdownEditor('.editor-container', {
placeholder: 'Start writing...',
toolbar: ['bold', 'italic', 'preview'],
});
document.getElementById('submit-btn').addEventListener('click', function() {
const markdownValue = document.querySelector('.editor-container').value;
console.log(markdownValue);
document.querySelector('.output').innerHTML = `<pre>${markdownValue}</pre>`;
});
If you prefer a traditional form submission approach (for example, in server-side applications like Django), you can integrate the markdown editor into a form that submits the value to the server for processing.
<form method="POST" action="/your-server-endpoint">
<textarea class="editor-container h-48" rows="5" name="markdown"></textarea>
<button type="submit">Submit</button>
</form>
you can retrieve the value from a traditional <textarea>
in a form submission without any custom element. When the form is submitted, the content inside the <textarea>
is automatically included as part of the form data, using the name attribute of the <textarea>
.
const editor = new MarkdownEditor('.editor-container', {
placeholder: 'Write your markdown...',
toolbar: ['preview', 'bold', 'italic'],
});
<form method="POST" action="/your-server-endpoint">
<textarea class="editor-container h-48" rows="5" name="markdown">Add your markdown content here</textarea>
<button type="submit">Submit</button>
</form>
Customize your Markdown editor by passing an options
object during initialization. Below are some key configuration options:
Option | Type | Default | Description |
---|---|---|---|
placeholder |
string |
'Write your markdown...' |
Sets the placeholder text for the textarea (optional, as you can also use the standard HTML textarea attribute) |
toolbar |
array |
['heading', 'bold', 'italic', 'strikethrough', 'ul', 'ol', 'checklist', 'blockquote', 'link', 'image', 'preview'] |
Determines which tools appear in the toolbar and their order. |
Tailor the toolbar to suit your needs by choosing which formatting options to include. The MarkdownEditor Plugin supports several tools, including:
bold
: Enables bold text formatting.italic
: Enables italic text formatting.strikethrough
: Allows text to be struck through.ol
: (Ordered List): Converts text into a numbered list format.ul
: (Unordered List): Converts text into a bullet point list.checklist
: Adds checkboxes to your text, making it great for tasks, to-do lists, or tracking completion status.image
: Allows you to insert images via markdown syntax.link
: Lets you add hyperlinks to your text.preview
: Toggles the real-time markdown preview.
Example:
const editor = new MarkdownEditor('.editor-container', {
placeholder: 'Start writing...',
toolbar: [
'bold',
'italic',
'strikethrough',
'ul',
'ol',
'checklist',
'image',
'link',
'preview'
],
});
-
The image tool supports a
fileInput
configuration that allows:accept
: Array of allowed image file types (e.g.,'webp'
,'avif'
).uploadUrl
: The endpoint where image files will be uploaded.
-
After a successful upload, the server must return the image path, which will be automatically populated in the URL field.
Usage example:
const options = {
placeholder: 'Start writing...',
toolbar: [
'link',
{
image: {
fileInput: {
accept: ['webp', 'avif'],
uploadUrl: '/api/upload', // Your upload endpoint
},
}
},
'preview'
],
}
const editor = new MarkdownEditor(element, options);
-
If
fileInput
is not configured, the image modal will default to only showing theURL
andalt text
fields.Usage example:
const options = { placeholder: 'Start writing...', toolbar: [ 'link', 'image', 'preview' ], } const editor = new MarkdownEditor(element, options);
You can configure whether the alt text input for images in the markdown editor is required.
{
image: {
fileInput: {
accept: ['webp', 'avif'],
uploadUrl: '/api/upload' // Your upload endpoint
},
altInput: {
required: false // Optional: disables alt text validation (default is true)
}
}
}
required: true
(default): Enforces alt text input for better SEO and accessibility.required: false
: Allows inserting images without alt text.
This configuration helps developers control alt text validation for each markdown editor instance. For example, when using multiple editors in the same app, you can define different alt text rules per instance.
Tip: You can reorder or remove any toolbar buttons by modifying the toolbar array during initialization.
Below is a complete HTML example demonstrating how to integrate the MarkdownEditor Plugin into your project:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown Editor Example</title>
<link rel="stylesheet" href="dist/markdown-editor-plugin.css">
</head>
<body>
<textarea class="editor-container h-56" rows="6"></textarea>
<script src="dist/markdown-editor-plugin.js"></script>
<script>
const editor = new MarkdownEditor('.editor-container', {
placeholder: 'Type your markdown...',
toolbar: [
'bold',
'italic',
'strikethrough',
'ul',
'ol',
'checklist',
'link',
{
image: {
fileInput: {
accept: ['webp', 'avif'],
uploadUrl: '/api/upload', // Your upload endpoint
},
}
},
'preview'
],
});
</script>
</body>
</html>
For projects using Webpack, import and initialize the editor as follows:
import MarkdownEditor from 'markdown-text-editor';
const editor = new MarkdownEditor('.editor-container', {
placeholder: 'Write markdown...',
toolbar: [
'bold',
'italic',
'strikethrough',
'ul',
'ol',
'checklist',
'image',
'link',
'preview'
],
});
Contributions to this open source project are highly encouraged! If you have bug fixes, feature enhancements, or new ideas, please consider opening an issue or submitting a pull request. Your help will ensure that this best, simple, embeddable JavaScript markdown editor plugin continues to evolve and serve the community with real-time preview and syntax highlighting capabilities.
This project is released under the MIT License.
Thank you for choosing the MarkdownEditor Plugin – your reliable, feature-rich solution for seamless markdown editing and content creation with easy integration. Happy coding!
If you like this project, consider giving it a star! 🌟