Giter VIP home page Giter VIP logo

simplemde-markdown-editor's Introduction

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.

Demo

Preview

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 to false, prevents downloading. Defaults to undefined, which will intelligently check whether Font Awesome has already been included, then download accordingly.
  • autofocus: If set to true, autofocuses the editor. Defaults to false.
  • 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 to false.
    • 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.
  • 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 *.
  • 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 to false.
  • 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 to true.
  • 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 to true.
  • 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 to false.
    • strikethrough: If set to false, will not process GFM strikethrough syntax. Defaults to true.
    • underscoresBreakWords: If set to true, let underscores be a delimiter for separating words. Defaults to false.
  • 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 to false.
  • renderingConfig: Adjust settings for parsing the Markdown during previewing (not editing).
    • singleLineBreaks: If set to false, disable parsing GFM single line breaks. Defaults to true.
    • codeSyntaxHighlighting: If set to true, will highlight using highlight.js. Defaults to false. 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">
  • 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 to true.
  • 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 the CodeMirror-selectedtext class from selected lines. Defaults to true.
  • 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 to true.
// 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: ["![](http://", ")"],
		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.

simplemde-markdown-editor's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplemde-markdown-editor's Issues

TypeError: undefined is not an object (evaluating 't.value')

I tried out the very basic setup of this plugin but am getting this error:

screen shot 2015-08-14 at 14 44 49

Here's what the code looks like:

    <link rel="stylesheet" media="screen" href="//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css" />
    <link rel="stylesheet" media="screen" href="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.css" />
    <script src="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
    <script>
      var simplemde = new SimpleMDE();
      simplemde.render();
    </script>

Multiple editors on one page with spell checker enabled consume a lot of memory

I've run into this ~3 weeks ago in 1.4.0, but it seems like it was not been fixed.

Browser tab eats ~1Gb of memory on a page with ~10 of editors with spell checker enabled and it grows the more editors on a page you have.

I didn't look very closely into that, but with profiling enabled in Chrome I see a lot of calls to Typo._parseDIC. My understanding is that every editor fetches it's own spell checking dictionary, so memory consumption grows linearly with the number of editors. They should share one dictionary, probably.

Make any Div editable

I would like to be able to have a div that contains markdown be editable without using a textarea.

Number sub-lists issue?

Is this an issue with numbered sub-list handling in the editor view (notice the numbering inconsitency between editor and preview)?

example

At.js Support

Not sure if this is a limitation on SimpleMDE's end or CodeMirror's end (since CodeMirror does all the editing in pre>span tags, but getting At.js to work is just too lofty a goal today it seems.

Any insight you can provide on how this might be possible?

Option to force double line break?

Example screencast

I think this is rarely desirable from an end user standpoint. If the markdown standard itself doesn't support single line breaks, could we have an option to force a double line breaks when a user presses enter?

Assuming it's an optional opt-in / opt-out thing, the only downside I can think of is removing these line breaks will require two backspace presses... though I suppose you could get clever there as well so that it's one enter press to force double line break, and one backspace press to delete double line break (if one is detected).

Your thoughts on this?

Icons disappearing?

You mention this in your readme:

// Customize only the order of existing buttons
var simplemde = new SimpleMDE({
    toolbar: ["bold", "italic", "heading", "|", "quote"],
});

When I do this, my icons and tooltips disappear. Is this intentional, or bug?
Example Screencast

For the record, here's my exact code:

var simplemde = new SimpleMDE({
    element: document.getElementById("#description"),
    tabSize: 4,
    toolbar: ["bold", "italic", "heading", "|", "quote"],
});
simplemde.render();

Custom preview source

Add option to specify a callback, which will return rendered markdown instead of using default editor.constructor.markdown

It can be useful in cases when editor is used with richer markdown superset, than it supports by default. For example, callback can make request to a server, which can render this richer subset properly and display that.

We're using this approach already in allura but it requires copy&pasting togglePreview method, which requires synchronization whenever new version is released.

Also, events or custom callbacks for preview open/close events would be useful, e.g. to add some custom styles to the editor.

Editor as jquery plugin

Hi! You can create editor as jquery plugin?

Example:

$('#editor').simpleMDE({
  toolbar: false
});

$('#editor').simpleMDE('value', '# text');
$('#editor').simpleMDE('value');
# => '# text'

$('#editor').on('simple_mde:change', function(e) { console.log(e) })

Image & quote toolbar icons

Was just playing around with the new toolbar settings (thanks for that!) and found something odd.

    var simplemdeObj = new SimpleMDE({
        element: byId("<?=$name?>"),
        status: false,
        lineWrapping: true
    });
    console.log(simplemdeObj.toolbar);

In the console output there is no property for image, and the object inside quote is actually the image button.

2-3 errors (from recently added features)

I'm getting the error:

Uncaught TypeError: Cannot read property 'className' of null

In the last line of this block:

SimpleMDE.prototype.createSidebyside = function() {
    var cm = this.codemirror;
    var wrapper = cm.getWrapperElement();
    var preview = wrapper.nextSibling;

    if(!/editor-preview-side/.test(preview.className)) {

I have the old/normal preview enabled, and when I click it, I get this error:

Uncaught TypeError: Cannot read property 'singleLineBreaks' of undefined

(I don't have singleLineBreaks defined in the options when I initialize the object.)

Possible causes, or steps to reproduce:

  • I don't have the side-by-side enabled in the toolbar buttons.
  • The textarea I'm targeting does not have any siblings.
  • I'm getting SME from cdn.jsdelivr.net

I'm not sure if it's related, or a separate problem, but I have a change event defined that used to work, but is no longer firing (apart from that and preview, everything else seems to work fine.)

Pass through mode options

Do so using the new parsingConfig option to keep SimpleMDE's configuration as clean as possible, without relying on users knowing CodeMirror's details. To do:

  • Fully document the available options in the README
  • Fully test the implementation

toolbar missing buttons

Greetings!

This is probably something I am doing wrong but am stuck ATM, help!

When I define toolbar like like this:

toolbar: ["bold", "italic", "strikethrough", "heading", "|", "code", "quote", "unordered-list", "numbered-list", "|", "link", "image", "horizontal-rule", "|", "preview", "side-by-side", "guide"]

strikethrough, numbered-list, and side-by-side are blank. (when moused over they look like what the red arrow is pointing to in the screenshot, when clicked on nothing happens)

There is nothing in console for any of the process.

screenshot of problem

Instantiation HTML:

<textarea id="comment-1" form="form-1441391701-0" name="comment" class="form-control" placeholder="" >initial content</textarea>
<script type="text/javascript">
    $( document ).ready(function() {
        var simplemde = new SimpleMDE({ 
            element: $("#comment-1")[0],
            toolbar: ["bold", "italic", "strikethrough", "heading", "|", "code", "quote", "unordered-list", "numbered-list", "|", "link", "image", "horizontal-rule", "|", "preview", "side-by-side", "guide"]
        });
        simplemde.render(); 
    });
</script>

Mobile fullscreen toolbar height

The height for the fullscreen toolbar is fixed at 50px, so when it responsively shrinks, buttons move to the second row and are hidden.

Cursor can be misplaced in some line wrapping situations

https://jsfiddle.net/zjxnwroL/8/

  1. Place cursor in the end of the first list item (i.e. after "indexation")
  2. Type one character (e.g. "q")
  3. Remove it (backspace)
  4. Move cursor down one line using keyboard and type something

Note, after (3) cursor is already in wrong position, but if you proceed typing/deleting it will fix itself. Seems like (4) messes it up completely

Plain CodeMirror does not have this kind of bug https://jsfiddle.net/o335vwsw/6/

I've tried to compress CodeMirror to include 'gfm' mode and create a jsfiddle with it, but it does not work for me (see console output here)

It might be a problem related to gfm mode, but I'm not sure.

Allow users to define custom markup more easily

It would be helpful to have an ability to add toolbar buttons to insert custom markup. It is possible now to extend toolbar with custom buttons, but to define custom markup you'll need to use helpers _toggleBlock, _toggleLine, etc. The problem is they are not exposed in the public API, so the only option is copy&paste them into own code, but that's really hard to maintain.

It would be great for _toggleBlock, _toggleLine (and whatever you think also might be necessary) to be exposed for outside usage.

Multiple Textareas Different Heights

There doesn't seem to be a way to set different heights for multiple textareas.

Any chance of an option being added for this instead of it being entirely controlled by a single CSS class?

Thoughts from /u/x-skeww

  • icons at the top lack tooltips
  • active state of the preview toggle button should be more obvious
  • the buttons should be deactivated in preview mode (they actually still work!)
  • preview and edit mode disagree when it comes to escaping (e.g. ## foo)
  • images in edit mode could show a preview when hovered or something like that

Full-screen edit mode

Just demo'ed SME to a colleague, and they had a suggestion:

Toolbar button to resize the editor to the full size of the window.

(Github textarea's have it, if you want an idea of how it looks.)

Include source?

Hi, just spent a couple of hours looking at and comparing markdown editors, and SimpleMDE/lepture seems like the best.

Great to see that you're continuing to add to the project and keep it alive :-)

One concern I have with committing to SimpleMDE is that if you get busy with other things, the code isn't public to fork or submit pull-requests against. Do you have any plans to include the source in the repo?

A few of the features I'd be interested in, and would consider adding pull-requests for:

  • More toolbar buttons (h1, h2, h3, hr, etc)
  • tooltips (html title attribute) on the toolbar buttons

Mobile issues

  • Side by side preview does not look good on small screens
  • Fade edges of mobile toolbar to indicate scroll left/right. Also make sure it scrolls whether fullscreen or not.
  • Prevent scrolling behind editor when fullscreen. Especially when it taps to start editing.

Better element option behavior

@WesCossick, I agree, if no element key is explicitly set in options array. But but if element is explicitly set in options, that suggests the user does not want default behaviour. If the user then makes an error selecting the element (as I did), there's no error in console to reflect erroneous element selector. Might I suggest a small tweak?

If no element key is explicitly set in options, revert to your default (first textarea in DOM).
If an explicit element key is set in options, override default (but throw error in console if user's selector is erroneous).

โ€”@jesseleite

Inconsistent behaviour between links and images.

Firstly, what an amazing Markdown editor. I love the visual feedback given by inline styling, and the wysiwyg-like toolbar... yet this thing is NOT a wysiwyg editor, so it doesn't come with any of the buggy baggage that most wysiwyg editors struggle with. THANK YOU <3

Anyway, regarding my issue: I've noticed inconsistent behaviour between links and images. Here's a screencast to show what I mean: http://recordit.co/VeU4EJQeWP

Tooltips

Add basic title attribute tooltips to toolbar button, along with option to enable/disable.

Side by side preview

Again thank you Wes, great lib. Here is my approach of the only thing missing heh... (actually 3).

https://jsfiddle.net/xb0rbkvk/9
A split button goes to fullscreen where left is editor, right is preview. 50/50.
Preview is live updated and scrolls are synced (roll code, preview rolls too).

Not creating a PR to consult you first, JS ain't my forte. And... I (and my editor) share massive OCD, so I removed all blanks and changed tabs by spaces.
Also added strike through (github markdown but marked supported) and tables.

More dev instructions in readme

Can you add to the readme a block of html for running SME without using cdn.jsdelivr.net? Specifically for testing - I wasn't sure if all the source files were needed, and in what order (and TBH, was a bit too lazy to copy each file name and work it out ๐Ÿ˜‰).

Something like:

<script src="//your-domain-here.com/js/codemirror/codemirror.js"></script>
<script src="//your-domain-here.com/js/codemirror/overlay.js"></script>
<script src="//your-domain-here.com/js/codemirror/markdown.js"></script>
<script src="//your-domain-here.com/js/marked.js"></script>
<script src="//your-domain-here.com/js/spell-checker.js"></script>
<script src="//your-domain-here.com/js/typo.js"></script>
<script src="//your-domain-here.com/js/simplemde.js"></script>

Simplified toolbar option

Instead of mandating the full toolbar option be created like so:

var simplemde = new SimpleMDE({
    toolbar: [{
            name: "bold",
            action: toggleBold,
            className: "fa fa-bold",
            title: "Bold (Ctrl+B)",
        },
        "|", // Separator
        ...
    ],
});

Allow a simplified version that uses just the names available in the chosen order:

var simplemde = new SimpleMDE({
    toolbar: ["bold", "italic", "|", "code", "quote"],
});

Then use the default actions, class names, titles, etc. for the chosen icons in the chosen order.

Multiple editors on the same page

First of all - thank you for the incredible editor, it is amazing. I need this thing very much, and I'm sure a lot of people will too. This is an extremely valuable project.

I have noticed a bug, or maybe I'm just not using it right.

I have a nested commenting system on my website(like reddit). Each comment has a textarea for typing in the reply. I'm trying to render the editor in each of the areas.

$('textarea').each(function() {
        var simplemde = new SimpleMDE(this);
        simplemde.render(); 
 })

But it ends up rendering the 2nd editor right after the first one, not inside the correct text area.

Can you help me out with this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.