Giter Site home page Giter Site logo

frm / simplemde-markdown-editor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sparksuite/simplemde-markdown-editor

0.0 2.0 0.0 1.88 MB

This a mirror repository of NextStepWebs' SimpleMDE Markdown Editor.

Home Page: http://nextstepwebs.github.io/simplemde-markdown-editor

License: MIT License

JavaScript 97.61% CSS 2.39%

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 to modify the markdown with toolbar buttons and shortcuts. WYSIWYG editors that produce HTML are often complex and buggy. Markdown solves this problem in many ways, but is less visually clear while editing. SimpleMDE has been designed to bridge this gap for non-technical users who are less familiar with or just learning markdown syntax.

Demo

Preview

Quick start

SimpleMDE is available on jsDelivr. Font Awesome is available on MaxCDN. Please note, jsDelivr may take a few days to update to the latest release.

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>

And then load SimpleMDE on the first textarea on a page

<script>
var simplemde = new SimpleMDE();
simplemde.render();
</script>

Use a specific textarea

Pure JavaScript method

<script>
var simplemde = new SimpleMDE( {element: document.getElementById("MyID")} );
simplemde.render();
</script>

jQuery method

<script>
var simplemde = new SimpleMDE( {element: $("#MyID")[0]} );
simplemde.render();
</script>

Get the content

simplemde.value();

Configuration

  • element: The DOM element for the textarea to use. Defaults to the first textarea on the page.
  • status: If set to false, hide the status bar. Defaults to true.
    • Optionally, you can set an array of status bar elements to include, and in what order.
  • 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.
  • toolbarGuideIcon: If set to false, disable guide icon in the toolbar. Defaults to true.
  • autofocus: If set to true, autofocuses the editor. Defaults to false.
  • lineWrapping: If set to false, disable line wrapping. Defaults to true.
  • indentWithTabs: If set to false, indent using spaces instead of tabs. Defaults to true.
  • tabSize: If set, customize the tab size. Defaults to 2.
  • spellChecker: If set to false, disable the spell checker. Defaults to true.
  • autosave: Saves the text that's being written. It will forget the text when the form is submitted.
    • enabled: If set to true, autosave the text. Defaults to false.
    • unique_id: You must set a unique identifier so that SimpleMDE can autosave. Something that separates this from other textareas.
    • delay: Delay between saves, in milliseconds. Defaults to 10000 (10s).
var simplemde = new SimpleMDE({
	element: document.getElementById("MyID"),
	status: false,
	status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage
	toolbar: false,
	autofocus: true,
	lineWrapping: false,
	indentWithTabs: false,
	tabSize: 4,
	autosave: {
		enabled: true,
		unique_id: "MyUniqueID",
		delay: 1000,
	},
});

Toolbar icons

Below are the available toolbar icons, 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. The Ctrl and Alt in the title tags will be changed automatically to their Mac equivalents when needed. Additionally, you can add a separator between any icons by adding "|" to the toolbar array.

Name Action Class Tooltip
bold toggleBold fa fa-bold Bold (Ctrl+B)
italic toggleItalic fa fa-italic Italic (Ctrl+I)
code toggleCodeBlock fa fa-code Code (Ctrl+Alt+C)
quote toggleBlockquote fa fa-quote-left Quote (Ctrl+')
unordered-list toggleUnorderedList fa fa-list-ul Generic List (Ctrl+L)
numbered-list toggleOrderedList fa fa-list-ol Numbered List (Ctrl+Alt+L)
link drawLink fa fa-link Create Link (Ctrl+K)
image drawImage fa fa-picture-o Insert Image (Ctrl+Alt+I)
horizontal-rule drawHorizontalRule fa fa-minus Insert Horizontal Line
fullscreen toggleFullScreen fa fa-arrows-alt Toggle Fullscreen (F11)
preview togglePreview fa fa-eye Toggle Preview (Ctrl+P)
guide This link fa fa-question-circle Markdown Guide

Customize the toolbar using the toolbar option like:

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

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());
});

How it works

SimpleMDE is an improvement of lepture's Editor project and includes a great many number of changes. 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.

What's changed?

As mentioned earlier, SimpleMDE is an improvement of lepture's Editor project. So you might be wondering, what's changed? Quite a bit actually. Here's some notable changes:

  • Upgraded from CodeMirror 3 to CodeMirror 5
  • Many changes to the style, appearance, and user friendliness
  • Interface more closely resembles Bootstrap
  • Now mobile friendly
  • Option to autosave the text as you type
  • Now spell checks what you write
  • The text editor now automatically grows as you type more
  • Fixed a large amount of bugs
  • Switched to Font Awesome icons
  • Improved preview rendering in many ways
  • Improved as-you-type appearance of headers and code blocks
  • Simplified the toolbar
  • Many new options during instantiation
  • New icons and tooltips
  • Additional keyboard shortcuts

simplemde-markdown-editor's People

Contributors

wescossick avatar frm avatar nofxx avatar frmendes avatar jetmind avatar maclover7 avatar

Watchers

James Cloos avatar  avatar

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.