simplemde-markdown-editor
A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.
Top Related Projects
🍞📝 Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible.
A completely customizable framework for building rich text editors. (Currently in beta.)
In-browser Markdown editor
A markdown parser and compiler. Built for speed.
A markdown editor. http://lab.lepture.com/editor/
Quick Overview
SimpleMDE is a simple, embeddable JavaScript Markdown editor. It provides a clean and distraction-free interface for writing Markdown, with features like auto-save, spell-check, and live preview.
Pros
- Lightweight and Customizable: SimpleMDE is a lightweight library that can be easily customized to fit your project's needs.
- Markdown Support: It provides full support for Markdown syntax, making it easy to write and format content.
- Live Preview: The editor includes a live preview feature, allowing users to see the rendered Markdown in real-time.
- Keyboard Shortcuts: SimpleMDE supports a variety of keyboard shortcuts, improving the writing experience.
Cons
- Limited Functionality: While SimpleMDE is a great basic Markdown editor, it may lack some advanced features found in more feature-rich editors.
- Older Codebase: The project has not been actively maintained since 2018, and the codebase may not be using the latest web technologies.
- Potential Compatibility Issues: As the project is not actively maintained, there may be compatibility issues with newer browsers or libraries.
- Limited Customization Options: While the library is customizable, the options for customization may be limited compared to other Markdown editors.
Code Examples
Here are a few examples of how to use SimpleMDE in your project:
<!-- Include the SimpleMDE CSS and JavaScript files -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
<!-- Create a textarea element for the editor -->
<textarea id="editor"></textarea>
<script>
// Initialize the SimpleMDE editor
var simplemde = new SimpleMDE({
element: document.getElementById("editor"),
spellChecker: false,
autosave: {
enabled: true,
uniqueId: "MyUniqueID",
delay: 1000,
},
});
</script>
This code sets up a basic SimpleMDE editor, with the autosave feature enabled.
// Programmatically set the editor's value
simplemde.value("# Hello, World!");
// Get the editor's value
var editorValue = simplemde.value();
These examples show how to programmatically set and retrieve the editor's value.
// Add a custom button to the toolbar
simplemde.addButton({
name: "customButton",
action: function customButtonAction(editor) {
// Add custom functionality here
editor.codemirror.replaceSelection("Custom button clicked!");
},
className: "fa fa-custom-button",
title: "Custom Button",
});
This example demonstrates how to add a custom button to the SimpleMDE toolbar.
Getting Started
To get started with SimpleMDE, follow these steps:
- Include the SimpleMDE CSS and JavaScript files in your HTML file:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
- Create a
<textarea>
element where you want the editor to be placed:
<textarea id="editor"></textarea>
- Initialize the SimpleMDE editor in your JavaScript code:
var simplemde = new SimpleMDE({
element: document.getElementById("editor"),
// Add any desired configuration options
});
- (Optional) Customize the editor's behavior and appearance by passing in configuration options to the
SimpleMDE
constructor.
That's it! You now have a basic SimpleMDE editor set up in your project.
Competitor Comparisons
🍞📝 Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible.
Pros of tui.editor
- Supports a wider range of features, including tables, code blocks, and inline HTML
- Provides a more feature-rich and customizable editor experience
- Integrates with various frameworks and libraries, such as React, Vue.js, and Angular
Cons of tui.editor
- Larger in size and complexity compared to SimpleMDE
- May have a steeper learning curve for users familiar with SimpleMDE
- Requires more configuration and setup to integrate into a project
Code Comparison
SimpleMDE:
var simplemde = new SimpleMDE({
element: document.getElementById("editor"),
spellChecker: false,
autosave: {
enabled: true,
uniqueId: "MyUniqueID",
delay: 1000,
},
});
tui.editor:
var editor = new tui.Editor({
el: document.querySelector('#editor'),
previewStyle: 'vertical',
height: '500px',
initialEditType: 'markdown',
toolbarItems: [
'heading',
'bold',
'italic',
'strike',
'divider',
'hr',
'quote',
'divider',
'ul',
'ol',
'task',
'divider',
'code',
'codeblock'
]
});
A completely customizable framework for building rich text editors. (Currently in beta.)
Pros of Slate
- Slate is a highly customizable and extensible rich text editor framework, allowing for the creation of complex and feature-rich editors.
- Slate provides a powerful and flexible API that enables developers to build custom editing experiences tailored to their specific needs.
- Slate has a large and active community, with extensive documentation and a wealth of community-contributed plugins and extensions.
Cons of Slate
- Slate has a steeper learning curve compared to SimpleMDE, as it requires a deeper understanding of the framework and its underlying concepts.
- Slate may be overkill for simple markdown editing use cases, as it provides more functionality than is necessary in such scenarios.
- Integrating Slate into an existing project may require more effort and configuration compared to a more lightweight solution like SimpleMDE.
Code Comparison
SimpleMDE (sparksuite/simplemde-markdown-editor):
var simplemde = new SimpleMDE({
element: document.getElementById("editor"),
spellChecker: false,
autosave: {
enabled: true,
unique_id: "MyUniqueID",
delay: 1000,
},
});
Slate (ianstormtaylor/slate):
const editor = slate.createEditor();
const [value, setValue] = useState(initialValue);
const renderElement = useCallback((props) => <Element {...props} />, []);
const renderLeaf = useCallback((props) => <Leaf {...props} />, []);
return (
<Slate editor={editor} value={value} onChange={(value) => setValue(value)}>
<Editable
renderElement={renderElement}
renderLeaf={renderLeaf}
onKeyDown={handleKeyDown}
/>
</Slate>
);
In-browser Markdown editor
Pros of StackEdit
- StackEdit is a full-featured Markdown editor with support for various file formats, including HTML, LaTeX, and Mermaid diagrams.
- StackEdit offers real-time collaboration and synchronization across multiple devices, making it a useful tool for team-based projects.
- StackEdit provides a clean and intuitive user interface, making it easy for users to focus on their writing and content creation.
Cons of StackEdit
- StackEdit is a more complex and feature-rich tool compared to SimpleMDE, which may be overkill for users who only need basic Markdown editing capabilities.
- StackEdit requires an internet connection to function, as it is a web-based application, while SimpleMDE can be used offline.
- StackEdit may have a steeper learning curve for users who are not familiar with its extensive features and customization options.
Code Comparison
SimpleMDE:
var simplemde = new SimpleMDE({
element: document.getElementById("editor"),
spellChecker: false,
autosave: {
enabled: true,
unique_id: "MyUniqueID",
delay: 1000,
},
});
StackEdit:
var stackedit = new Stackedit();
stackedit.on("ready", function() {
// Set the editor content
stackedit.setContent("# Hello, world!");
// Open the file manager
stackedit.openFile({
name: "example.md",
content: {
text: "# Hello, world!",
},
});
});
A markdown parser and compiler. Built for speed.
Pros of markedjs/marked
- Lightweight and Fast: markedjs/marked is a lightweight and fast Markdown parser, making it a good choice for performance-critical applications.
- Customizable: markedjs/marked provides a range of options and hooks for customizing the parsing and rendering of Markdown.
- Widely Used: markedjs/marked is a widely used and well-established Markdown parser, with a large community and extensive documentation.
Cons of markedjs/marked
- Limited Editor Features: markedjs/marked is a Markdown parser and does not provide any built-in editor features, unlike sparksuite/simplemde-markdown-editor.
- No Live Preview: markedjs/marked does not include a live preview feature, which can be useful for users when writing Markdown content.
Code Comparison
markedjs/marked:
marked.setOptions({
renderer: new marked.Renderer(),
highlight: function(code, lang) {
const hljs = require('highlight.js');
const validLanguage = hljs.getLanguage(lang) ? lang : 'plaintext';
return hljs.highlight(validLanguage, code).value;
},
pedantic: false,
gfm: true,
breaks: false,
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
});
sparksuite/simplemde-markdown-editor:
var simplemde = new SimpleMDE({
element: document.getElementById("editor"),
spellChecker: false,
autosave: {
enabled: true,
uniqueId: "MyUniqueID",
delay: 1000,
},
toolbar: ["bold", "italic", "heading", "|", "quote", "unordered-list", "ordered-list", "|", "link", "image", "code", "table", "|", "preview", "side-by-side", "fullscreen", "|", "guide"],
});
A markdown editor. http://lab.lepture.com/editor/
Pros of lepture/editor
- Supports a wider range of formatting options, including tables, code blocks, and inline styles.
- Provides a more customizable and extensible API, allowing developers to easily integrate it into their applications.
- Includes a built-in preview mode, which allows users to see the rendered Markdown in real-time.
Cons of lepture/editor
- Has a steeper learning curve compared to SimpleMDE, as it requires more configuration and setup.
- May have a larger file size and dependencies, which could impact performance in some use cases.
- Lacks some of the user-friendly features found in SimpleMDE, such as automatic saving and spell-checking.
Code Comparison
SimpleMDE (sparksuite/simplemde-markdown-editor):
var simplemde = new SimpleMDE({
element: document.getElementById("editor"),
spellChecker: false,
autosave: {
enabled: true,
uniqueId: "MyUniqueID",
delay: 1000,
},
});
editor (lepture/editor):
var editor = new Editor({
element: document.getElementById("editor"),
status: false,
toolbar: [
"bold", "italic", "heading", "quote", "unordered-list", "ordered-list",
"link", "image", "table", "code", "preview", "side-by-side", "fullscreen",
"guide"
]
});
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
SimpleMDE - Markdown Editor
A drop-in JavaScript textarea replacement for writing beautiful and understandable Markdown. The WYSIWYG-esque editor allows users who may be less experienced with Markdown to use familiar toolbar buttons and shortcuts. In addition, the syntax is rendered while editing to clearly show the expected result. Headings are larger, emphasized words are italicized, links are underlined, etc. SimpleMDE is one of the first editors to feature both built-in autosaving and spell checking.
Why not a WYSIWYG editor or pure Markdown?
WYSIWYG editors that produce HTML are often complex and buggy. Markdown solves this problem in many ways, plus Markdown can be rendered natively on more platforms than HTML. However, Markdown is not a syntax that an average user will be familiar with, nor is it visually clear while editing. In otherwords, for an unfamiliar user, the syntax they write will make little sense until they click the preview button. SimpleMDE has been designed to bridge this gap for non-technical users who are less familiar with or just learning Markdown syntax.
Install
Via npm.
npm install simplemde --save
Via bower.
bower install simplemde --save
Via jsDelivr. Please note, jsDelivr may take a few days to update to the latest release.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
Quick start
After installing, load SimpleMDE on the first textarea on a page
<script>
var simplemde = new SimpleMDE();
</script>
Using a specific textarea
Pure JavaScript method
<script>
var simplemde = new SimpleMDE({ element: document.getElementById("MyID") });
</script>
jQuery method
<script>
var simplemde = new SimpleMDE({ element: $("#MyID")[0] });
</script>
Get/set the content
simplemde.value();
simplemde.value("This text will appear in the editor");
Configuration
- autoDownloadFontAwesome: If set to
true
, force downloads Font Awesome (used for icons). If set tofalse
, prevents downloading. Defaults toundefined
, which will intelligently check whether Font Awesome has already been included, then download accordingly. - autofocus: If set to
true
, autofocuses the editor. Defaults tofalse
. - autosave: Saves the text that's being written and will load it back in the future. It will forget the text when the form it's contained in is submitted.
- enabled: If set to
true
, autosave the text. Defaults tofalse
. - delay: Delay between saves, in milliseconds. Defaults to
10000
(10s). - uniqueId: You must set a unique string identifier so that SimpleMDE can autosave. Something that separates this from other instances of SimpleMDE elsewhere on your website.
- enabled: If set to
- blockStyles: Customize how certain buttons that style blocks of text behave.
- bold Can be set to
**
or__
. Defaults to**
. - code Can be set to
```
or~~~
. Defaults to```
. - italic Can be set to
*
or_
. Defaults to*
.
- bold Can be set to
- element: The DOM element for the textarea to use. Defaults to the first textarea on the page.
- forceSync: If set to
true
, force text changes made in SimpleMDE to be immediately stored in original textarea. Defaults tofalse
. - hideIcons: An array of icon names to hide. Can be used to hide specific icons shown by default without completely customizing the toolbar.
- indentWithTabs: If set to
false
, indent using spaces instead of tabs. Defaults totrue
. - initialValue: If set, will customize the initial value of the editor.
- insertTexts: Customize how certain buttons that insert text behave. Takes an array with two elements. The first element will be the text inserted before the cursor or highlight, and the second element will be inserted after. For example, this is the default link value:
["[", "](http://)"]
.- horizontalRule
- image
- link
- table
- lineWrapping: If set to
false
, disable line wrapping. Defaults totrue
. - parsingConfig: Adjust settings for parsing the Markdown during editing (not previewing).
- allowAtxHeaderWithoutSpace: If set to
true
, will render headers without a space after the#
. Defaults tofalse
. - strikethrough: If set to
false
, will not process GFM strikethrough syntax. Defaults totrue
. - underscoresBreakWords: If set to
true
, let underscores be a delimiter for separating words. Defaults tofalse
.
- allowAtxHeaderWithoutSpace: If set to
- placeholder: Custom placeholder that should be displayed
- previewRender: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
- promptURLs: If set to
true
, a JS alert window appears asking for the link or image URL. Defaults tofalse
. - renderingConfig: Adjust settings for parsing the Markdown during previewing (not editing).
- singleLineBreaks: If set to
false
, disable parsing GFM single line breaks. Defaults totrue
. - codeSyntaxHighlighting: If set to
true
, will highlight using highlight.js. Defaults tofalse
. To use this feature you must include highlight.js on your page. For example, include the script and the CSS files like:<script src="https://cdn.jsdelivr.net/highlight.js/latest/highlight.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/highlight.js/latest/styles/github.min.css">
- singleLineBreaks: If set to
- shortcuts: Keyboard shortcuts associated with this instance. Defaults to the array of shortcuts.
- showIcons: An array of icon names to show. Can be used to show specific icons hidden by default without completely customizing the toolbar.
- spellChecker: If set to
false
, disable the spell checker. Defaults totrue
. - status: If set to
false
, hide the status bar. Defaults to the array of built-in status bar items.- Optionally, you can set an array of status bar items to include, and in what order. You can even define your own custom status bar items.
- styleSelectedText: If set to
false
, remove theCodeMirror-selectedtext
class from selected lines. Defaults totrue
. - tabSize: If set, customize the tab size. Defaults to
2
. - toolbar: If set to
false
, hide the toolbar. Defaults to the array of icons. - toolbarTips: If set to
false
, disable toolbar button tips. Defaults totrue
.
// Most options demonstrate the non-default behavior
var simplemde = new SimpleMDE({
autofocus: true,
autosave: {
enabled: true,
uniqueId: "MyUniqueID",
delay: 1000,
},
blockStyles: {
bold: "__",
italic: "_"
},
element: document.getElementById("MyID"),
forceSync: true,
hideIcons: ["guide", "heading"],
indentWithTabs: false,
initialValue: "Hello world!",
insertTexts: {
horizontalRule: ["", "\n\n-----\n\n"],
image: [""],
link: ["[", "](http://)"],
table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
},
lineWrapping: false,
parsingConfig: {
allowAtxHeaderWithoutSpace: true,
strikethrough: false,
underscoresBreakWords: true,
},
placeholder: "Type here...",
previewRender: function(plainText) {
return customMarkdownParser(plainText); // Returns HTML from a custom parser
},
previewRender: function(plainText, preview) { // Async method
setTimeout(function(){
preview.innerHTML = customMarkdownParser(plainText);
}, 250);
return "Loading...";
},
promptURLs: true,
renderingConfig: {
singleLineBreaks: false,
codeSyntaxHighlighting: true,
},
shortcuts: {
drawTable: "Cmd-Alt-T"
},
showIcons: ["code", "table"],
spellChecker: false,
status: false,
status: ["autosave", "lines", "words", "cursor"], // Optional usage
status: ["autosave", "lines", "words", "cursor", {
className: "keystrokes",
defaultValue: function(el) {
this.keystrokes = 0;
el.innerHTML = "0 Keystrokes";
},
onUpdate: function(el) {
el.innerHTML = ++this.keystrokes + " Keystrokes";
}
}], // Another optional usage, with a custom status bar item that counts keystrokes
styleSelectedText: false,
tabSize: 4,
toolbar: false,
toolbarTips: false,
});
Toolbar icons
Below are the built-in toolbar icons (only some of which are enabled by default), which can be reorganized however you like. "Name" is the name of the icon, referenced in the JS. "Action" is either a function or a URL to open. "Class" is the class given to the icon. "Tooltip" is the small tooltip that appears via the title=""
attribute. Note that shortcut hints are added automatically and reflect the specified action if it has a keybind assigned to it (i.e. with the value of action
set to bold
and that of tooltip
set to Bold
, the final text the user will see would be "Bold (Ctrl-B)").
Additionally, you can add a separator between any icons by adding "|"
to the toolbar array.
Name | Action | Tooltip Class |
---|---|---|
bold | toggleBold | Bold fa fa-bold |
italic | toggleItalic | Italic fa fa-italic |
strikethrough | toggleStrikethrough | Strikethrough fa fa-strikethrough |
heading | toggleHeadingSmaller | Heading fa fa-header |
heading-smaller | toggleHeadingSmaller | Smaller Heading fa fa-header |
heading-bigger | toggleHeadingBigger | Bigger Heading fa fa-lg fa-header |
heading-1 | toggleHeading1 | Big Heading fa fa-header fa-header-x fa-header-1 |
heading-2 | toggleHeading2 | Medium Heading fa fa-header fa-header-x fa-header-2 |
heading-3 | toggleHeading3 | Small Heading fa fa-header fa-header-x fa-header-3 |
code | toggleCodeBlock | Code fa fa-code |
quote | toggleBlockquote | Quote fa fa-quote-left |
unordered-list | toggleUnorderedList | Generic List fa fa-list-ul |
ordered-list | toggleOrderedList | Numbered List fa fa-list-ol |
clean-block | cleanBlock | Clean block fa fa-eraser fa-clean-block |
link | drawLink | Create Link fa fa-link |
image | drawImage | Insert Image fa fa-picture-o |
table | drawTable | Insert Table fa fa-table |
horizontal-rule | drawHorizontalRule | Insert Horizontal Line fa fa-minus |
preview | togglePreview | Toggle Preview fa fa-eye no-disable |
side-by-side | toggleSideBySide | Toggle Side by Side fa fa-columns no-disable no-mobile |
fullscreen | toggleFullScreen | Toggle Fullscreen fa fa-arrows-alt no-disable no-mobile |
guide | This link | Markdown Guide fa fa-question-circle |
Customize the toolbar using the toolbar
option like:
// Customize only the order of existing buttons
var simplemde = new SimpleMDE({
toolbar: ["bold", "italic", "heading", "|", "quote"],
});
// Customize all information and/or add your own icons
var simplemde = new SimpleMDE({
toolbar: [{
name: "bold",
action: SimpleMDE.toggleBold,
className: "fa fa-bold",
title: "Bold",
},
{
name: "custom",
action: function customFunction(editor){
// Add your own code
},
className: "fa fa-star",
title: "Custom Button",
},
"|", // Separator
...
],
});
Keyboard shortcuts
SimpleMDE comes with an array of predefined keyboard shortcuts, but they can be altered with a configuration option. The list of default ones is as follows:
Shortcut | Action |
---|---|
Cmd-' | "toggleBlockquote" |
Cmd-B | "toggleBold" |
Cmd-E | "cleanBlock" |
Cmd-H | "toggleHeadingSmaller" |
Cmd-I | "toggleItalic" |
Cmd-K | "drawLink" |
Cmd-L | "toggleUnorderedList" |
Cmd-P | "togglePreview" |
Cmd-Alt-C | "toggleCodeBlock" |
Cmd-Alt-I | "drawImage" |
Cmd-Alt-L | "toggleOrderedList" |
Shift-Cmd-H | "toggleHeadingBigger" |
F9 | "toggleSideBySide" |
F11 | "toggleFullScreen" |
Here is how you can change a few, while leaving others untouched:
var simplemde = new SimpleMDE({
shortcuts: {
"toggleOrderedList": "Ctrl-Alt-K", // alter the shortcut for toggleOrderedList
"toggleCodeBlock": null, // unbind Ctrl-Alt-C
"drawTable": "Cmd-Alt-T" // bind Cmd-Alt-T to drawTable action, which doesn't come with a default shortcut
}
});
Shortcuts are automatically converted between platforms. If you define a shortcut as "Cmd-B", on PC that shortcut will be changed to "Ctrl-B". Conversely, a shortcut defined as "Ctrl-B" will become "Cmd-B" for Mac users.
The list of actions that can be bound is the same as the list of built-in actions available for toolbar buttons.
Height
To change the minimum height (before it starts auto-growing):
.CodeMirror, .CodeMirror-scroll {
min-height: 200px;
}
Or, you can keep the height static:
.CodeMirror {
height: 300px;
}
Event handling
You can catch the following list of events: https://codemirror.net/doc/manual.html#events
var simplemde = new SimpleMDE();
simplemde.codemirror.on("change", function(){
console.log(simplemde.value());
});
Removing SimpleMDE from textarea
You can revert to the initial textarea by calling the toTextArea
method. Note that this clears up the autosave (if enabled) associated with it. The textarea will retain any text from the destroyed SimpleMDE instance.
var simplemde = new SimpleMDE();
...
simplemde.toTextArea();
simplemde = null;
Useful methods
The following self-explanatory methods may be of use while developing with SimpleMDE.
var simplemde = new SimpleMDE();
simplemde.isPreviewActive(); // returns boolean
simplemde.isSideBySideActive(); // returns boolean
simplemde.isFullscreenActive(); // returns boolean
simplemde.clearAutosavedValue(); // no returned value
How it works
SimpleMDE began as an improvement of lepture's Editor project, but has now taken on an identity of its own. It is bundled with CodeMirror and depends on Font Awesome.
CodeMirror is the backbone of the project and parses much of the Markdown syntax as it's being written. This allows us to add styles to the Markdown that's being written. Additionally, a toolbar and status bar have been added to the top and bottom, respectively. Previews are rendered by Marked using GFM.
Top Related Projects
🍞📝 Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible.
A completely customizable framework for building rich text editors. (Currently in beta.)
In-browser Markdown editor
A markdown parser and compiler. Built for speed.
A markdown editor. http://lab.lepture.com/editor/
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot