├── .npmrc ├── cypress ├── support │ ├── e2e.js │ └── commands.js ├── .eslintrc ├── plugins │ └── index.js └── e2e │ ├── 1-default-editor │ ├── index.html │ ├── visual.cy.js │ ├── preview.cy.js │ └── statusbar.cy.js │ ├── 2-url-prompt │ ├── index.html │ └── url-prompt.cy.js │ ├── 4.image-rendering │ ├── index.html │ └── image-rendering.cy.js │ ├── 3-class-prefix │ ├── class-prefix.cy.js │ ├── index-no-prefix.html │ └── index.html │ └── 5-marked-options │ ├── marked-options.cy.js │ └── index.html ├── cypress.config.ts ├── types ├── tsconfig.json ├── easymde-test.ts └── easymde.d.ts ├── .gitignore ├── .github ├── ISSUE_TEMPLATE │ ├── question.md │ ├── feature_request.md │ └── bug_report.md ├── ISSUE_TEMPLATE.md └── workflows │ └── cd.yaml ├── .editorconfig ├── example ├── index.html └── index_sideBySideFullscreenFalse.html ├── .eslintrc ├── LICENSE ├── src ├── js │ └── codemirror │ │ └── tablist.js └── css │ └── easymde.css ├── package.json ├── CONTRIBUTING.md ├── gulpfile.js ├── CHANGELOG.md └── README.md /.npmrc: -------------------------------------------------------------------------------- 1 | tag-version-prefix="" 2 | -------------------------------------------------------------------------------- /cypress/support/e2e.js: -------------------------------------------------------------------------------- 1 | require('./commands'); 2 | -------------------------------------------------------------------------------- /cypress.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'cypress'; 2 | 3 | export default defineConfig({ 4 | e2e: { 5 | excludeSpecPattern: [ 6 | '**/*.html', 7 | ], 8 | video: true, 9 | }, 10 | }); 11 | -------------------------------------------------------------------------------- /types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es3", 4 | "ignoreDeprecations": "5.0", 5 | "strict": true, 6 | "noImplicitReturns": true, 7 | "noEmit": true 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # generated files 2 | dist/ 3 | 4 | # NPM files 5 | node_modules/ 6 | 7 | # IDE files 8 | *.iml 9 | *.ipr 10 | *.iws 11 | .idea/ 12 | .vscode/ 13 | dev_test/ 14 | 15 | # Test artifacts 16 | cypress/screenshots 17 | cypress/videos 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Ask a question if anything is unclear 4 | title: '' 5 | labels: Question 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe your question** 11 | Please describe your question in as much detail as possible. 12 | -------------------------------------------------------------------------------- /cypress/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": [ 3 | "cypress" 4 | ], 5 | "env": { 6 | "node": true, 7 | "es6": true, 8 | "cypress/globals": true 9 | }, 10 | "extends": [ 11 | "../.eslintrc", 12 | "plugin:cypress/recommended" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /cypress/plugins/index.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | /** 4 | * @type {Cypress.PluginConfig} 5 | */ 6 | // eslint-disable-next-line no-unused-vars 7 | module.exports = (on, config) => { 8 | // `on` is used to hook into various events Cypress emits 9 | // `config` is the resolved Cypress config 10 | }; 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_size = 4 9 | indent_style = space 10 | trim_trailing_whitespace = true 11 | 12 | [*.yaml] 13 | indent_size = 2 14 | 15 | [*.md] 16 | max_line_length = off 17 | trim_trailing_whitespace = false 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | ### I'm submitting a... 3 | - [x] Bug report 4 | - [ ] Feature request 5 | 6 | ### Reproduction steps 7 | 8 | 1. ... 9 | 2. ... 10 | 11 | ### Version information 12 | Browser type and version: 13 | EasyMDE version: 14 | -------------------------------------------------------------------------------- /cypress/e2e/1-default-editor/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Default 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Example / Preview 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /cypress/e2e/2-url-prompt/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Default 7 | 8 | 9 | 10 | 11 | 12 | 13 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /cypress/e2e/4.image-rendering/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Default 7 | 8 | 9 | 10 | 11 | 12 | 13 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "rules": { 4 | "strict": 0, 5 | "no-console": 0, 6 | "quotes": [ 7 | "error", 8 | "single" 9 | ], 10 | "semi": [ 11 | "error", 12 | "always" 13 | ], 14 | "comma-dangle": [ 15 | "error", 16 | "always-multiline" 17 | ] 18 | }, 19 | "env": { 20 | "browser": true, 21 | "node": true 22 | }, 23 | "parserOptions": { 24 | "ecmaVersion": 2018 25 | }, 26 | "extends": "eslint:recommended" 27 | } 28 | -------------------------------------------------------------------------------- /cypress/e2e/3-class-prefix/class-prefix.cy.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | describe('Default editor', () => { 4 | it('table', () => { 5 | cy.visit(__dirname + '/index-no-prefix.html'); 6 | 7 | cy.get('button.table').should('be.visible'); 8 | cy.get('button.table').invoke('outerWidth').should('not.equal', 30); 9 | }); 10 | 11 | it('loads the editor with default settings', () => { 12 | cy.visit(__dirname + '/index.html'); 13 | 14 | cy.get('button.mde-table').should('be.visible'); 15 | cy.get('button.mde-table').invoke('outerWidth').should('equal', 30); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /example/index_sideBySideFullscreenFalse.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Example / Preview / sideBySideFullscreen : false 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /cypress/e2e/5-marked-options/marked-options.cy.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | describe('Marked options', () => { 4 | beforeEach(() => { 5 | cy.visit(__dirname + '/index.html'); 6 | }); 7 | 8 | it('must apply the markedOptions to the markdown parser', () => { 9 | cy.get('.EasyMDEContainer').should('be.visible'); 10 | cy.get('#textarea').should('not.be.visible'); 11 | 12 | cy.get('.EasyMDEContainer .CodeMirror').type('# Title{enter}'); 13 | 14 | cy.previewOn(); 15 | 16 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

Title

'); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: Feature 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots/mock-ups about the feature request here. 21 | -------------------------------------------------------------------------------- /cypress/e2e/5-marked-options/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Default 7 | 8 | 9 | 10 | 11 | 12 | 13 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /cypress/e2e/1-default-editor/visual.cy.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | describe('Default editor', () => { 4 | beforeEach(() => { 5 | cy.visit(__dirname + '/index.html'); 6 | }); 7 | 8 | it('loads the editor with default settings', () => { 9 | cy.get('.EasyMDEContainer').should('be.visible'); 10 | cy.get('#textarea').should('not.be.visible'); 11 | 12 | cy.get('.EasyMDEContainer .editor-toolbar').should('be.visible'); 13 | cy.get('.EasyMDEContainer .CodeMirror').should('be.visible'); 14 | cy.get('.EasyMDEContainer .editor-preview').should('not.be.visible'); 15 | cy.get('.EasyMDEContainer .editor-statusbar').should('be.visible'); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /cypress/e2e/3-class-prefix/index-no-prefix.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Default 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: Bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Version information** 27 | - OS: [e.g. Windows, MacOS] 28 | - Browser: [e.g. Chrome 72] 29 | - EasyMDE version: [e.g. 2.5.1] 30 | 31 | **Additional context** 32 | Add any other context about the problem here. 33 | -------------------------------------------------------------------------------- /cypress/e2e/3-class-prefix/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Default 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Sparksuite, Inc. 4 | Copyright (c) 2017 Jeroen Akkerman. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /src/js/codemirror/tablist.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: http://codemirror.net/LICENSE 3 | 4 | var CodeMirror = require('codemirror'); 5 | 6 | CodeMirror.commands.tabAndIndentMarkdownList = function (cm) { 7 | var ranges = cm.listSelections(); 8 | var pos = ranges[0].head; 9 | var eolState = cm.getStateAfter(pos.line); 10 | var inList = eolState.list !== false; 11 | 12 | if (inList) { 13 | cm.execCommand('indentMore'); 14 | return; 15 | } 16 | 17 | if (cm.options.indentWithTabs) { 18 | cm.execCommand('insertTab'); 19 | } else { 20 | var spaces = Array(cm.options.tabSize + 1).join(' '); 21 | cm.replaceSelection(spaces); 22 | } 23 | }; 24 | 25 | CodeMirror.commands.shiftTabAndUnindentMarkdownList = function (cm) { 26 | var ranges = cm.listSelections(); 27 | var pos = ranges[0].head; 28 | var eolState = cm.getStateAfter(pos.line); 29 | var inList = eolState.list !== false; 30 | 31 | if (inList) { 32 | cm.execCommand('indentLess'); 33 | return; 34 | } 35 | 36 | if (cm.options.indentWithTabs) { 37 | cm.execCommand('insertTab'); 38 | } else { 39 | var spaces = Array(cm.options.tabSize + 1).join(' '); 40 | cm.replaceSelection(spaces); 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /cypress/support/commands.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | const unquote = (str) => str.replace(/(^")|("$)/g, ''); 4 | 5 | Cypress.Commands.add( 6 | 'before', 7 | { 8 | prevSubject: 'element', 9 | }, 10 | (element, property) => { 11 | const win = element[0].ownerDocument.defaultView; 12 | const before = win.getComputedStyle(element[0], 'before'); 13 | return unquote(before.getPropertyValue(property)); 14 | }, 15 | ); 16 | 17 | Cypress.Commands.add('previewOn' , () => { 18 | cy.get('.EasyMDEContainer .editor-preview').should('not.be.visible'); 19 | cy.get('.EasyMDEContainer .editor-toolbar button.preview').should('not.have.class', 'active'); 20 | cy.get('.EasyMDEContainer .editor-toolbar button.preview').click(); 21 | cy.get('.EasyMDEContainer .editor-toolbar button.preview').should('have.class', 'active'); 22 | cy.get('.EasyMDEContainer .editor-preview').should('be.visible'); 23 | }); 24 | 25 | Cypress.Commands.add('previewOff' , () => { 26 | cy.get('.EasyMDEContainer .editor-preview').should('be.visible'); 27 | cy.get('.EasyMDEContainer .editor-toolbar button.preview').should('have.class', 'active'); 28 | cy.get('.EasyMDEContainer .editor-toolbar button.preview').click(); 29 | cy.get('.EasyMDEContainer .editor-toolbar button.preview').should('not.have.class', 'active'); 30 | cy.get('.EasyMDEContainer .editor-preview').should('not.be.visible'); 31 | }); 32 | -------------------------------------------------------------------------------- /cypress/e2e/1-default-editor/preview.cy.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | describe('Preview', () => { 4 | beforeEach(() => { 5 | cy.visit(__dirname + '/index.html'); 6 | }); 7 | 8 | it('can show a preview of markdown text', () => { 9 | cy.get('.EasyMDEContainer').should('be.visible'); 10 | cy.get('.EasyMDEContainer .editor-preview').should('not.be.visible'); 11 | 12 | // Enter markdown text. 13 | cy.get('.EasyMDEContainer .CodeMirror').type('# My Big Title'); 14 | cy.get('.EasyMDEContainer .CodeMirror').type('{enter}'); 15 | cy.get('.EasyMDEContainer .CodeMirror').type('This is some **important** text!'); 16 | 17 | cy.get('.EasyMDEContainer .CodeMirror-line').should('contain', '# My Big Title'); 18 | cy.get('.EasyMDEContainer .cm-header.cm-header-1').should('contain', '#'); 19 | cy.get('.EasyMDEContainer .cm-header.cm-header-1').should('contain', 'My Big Title'); 20 | 21 | cy.get('.EasyMDEContainer .CodeMirror-line').should('contain', 'This is some **important** text!'); 22 | cy.get('.EasyMDEContainer .cm-strong').should('contain', '**'); 23 | cy.get('.EasyMDEContainer .cm-strong').should('contain', 'important'); 24 | 25 | cy.previewOn(); 26 | 27 | // Check preview window for rendered markdown. 28 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

My Big Title

'); 29 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

This is some important text!

'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /cypress/e2e/4.image-rendering/image-rendering.cy.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | describe('Image rendering', () => { 4 | 5 | const imageUrl = 'https://picsum.photos/id/237/150'; 6 | 7 | beforeEach(() => { 8 | cy.visit(__dirname + '/index.html'); 9 | cy.intercept('GET', imageUrl).as('image'); 10 | }); 11 | 12 | it('must render an image inside the editor', () => { 13 | cy.get('.EasyMDEContainer').should('be.visible'); 14 | cy.get('#textarea').should('not.be.visible'); 15 | 16 | cy.get('.EasyMDEContainer .CodeMirror').type(imageUrl); 17 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}![Dog!]({end})'); 18 | 19 | cy.wait('@image'); 20 | 21 | cy.get(`.EasyMDEContainer [data-img-src="${imageUrl}"]`).should('be.visible'); 22 | 23 | cy.previewOn(); 24 | 25 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', `

Dog!

`); 26 | }); 27 | 28 | it('must be able to handle parentheses inside image alt text', () => { 29 | cy.get('.EasyMDEContainer').should('be.visible'); 30 | cy.get('#textarea').should('not.be.visible'); 31 | 32 | cy.get('.EasyMDEContainer .CodeMirror').type(imageUrl); 33 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}![Dog! (He\'s a good boy!)]({end})'); 34 | 35 | cy.wait('@image'); 36 | 37 | cy.get(`.EasyMDEContainer [data-img-src="${imageUrl}"]`).should('be.visible'); 38 | 39 | cy.previewOn(); 40 | 41 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', `

Dog! (He's a good boy!)

`); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "easymde", 3 | "version": "2.20.0", 4 | "description": "A simple, beautiful, and embeddable JavaScript Markdown editor that easy to use. Features include autosaving and spell checking.", 5 | "files": [ 6 | "dist/**/*", 7 | "src/**/*", 8 | "types/easymde.d.ts" 9 | ], 10 | "keywords": [ 11 | "embeddable", 12 | "markdown", 13 | "editor", 14 | "javascript", 15 | "fontawesome" 16 | ], 17 | "main": "src/js/easymde.js", 18 | "types": "types/easymde.d.ts", 19 | "license": "MIT", 20 | "author": "Jeroen Akkerman", 21 | "dependencies": { 22 | "@types/codemirror": "^5.60.10", 23 | "@types/marked": "^4.0.7", 24 | "codemirror": "^5.65.15", 25 | "codemirror-spell-checker": "1.1.2", 26 | "marked": "^4.1.0" 27 | }, 28 | "devDependencies": { 29 | "browserify": "^17.0.0", 30 | "cypress": "^13.2.0", 31 | "eslint": "^8.50.0", 32 | "eslint-plugin-cypress": "^2.15.1", 33 | "gulp": "^4.0.2", 34 | "gulp-clean-css": "^4.3.0", 35 | "gulp-concat": "^2.6.1", 36 | "gulp-eslint": "^6.0.0", 37 | "gulp-header": "^2.0.9", 38 | "gulp-rename": "^2.0.0", 39 | "gulp-terser": "^2.1.0", 40 | "gulp-uglify": "^3.0.2", 41 | "typescript": "^5.2.2", 42 | "vinyl-buffer": "^1.0.1", 43 | "vinyl-source-stream": "^2.0.0" 44 | }, 45 | "repository": "github:Ionaru/easy-markdown-editor", 46 | "scripts": { 47 | "prepare": "gulp", 48 | "test": "npm run lint && npm run test:types && npm run e2e", 49 | "lint": "gulp lint", 50 | "cypress:lint": "eslint cypress", 51 | "cypress:run": "cypress run", 52 | "e2e": "gulp && npm run cypress:lint && npm run cypress:run", 53 | "test:types": "tsc --project types/tsconfig.json" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thank you so much for your interest in contributing to EasyMDE! 4 | 5 | 6 | ## Asking questions, suggesting ideas or reporting bugs 7 | 8 | You can [submit an issue️](https://github.com/Ionaru/easy-markdown-editor/issues) on this GitHub repository. 9 | 10 | 11 | ## Coding 12 | 13 | ### 📦 Prerequisites 14 | 15 | To contribute code to this project you'll need an up-to-date LTS or current version of Node.js and npm. 16 | 17 | Please find information about the installation on [the official Node.js website](https://nodejs.org/en/download/). 18 | 19 | 20 | ### ⤴️ Workflow 21 | 22 | Please make sure any code you submit is compliant and compatible with this repository's [license](./LICENSE). 23 | 24 | #### Your first pull request 25 | 1. [Create a fork of this project](https://github.com/Ionaru/easy-markdown-editor/fork). 26 | 1. Clone your fork: `git clone https://github.com/YOUR_USERNAME/easy-markdown-editor.git`. 27 | 1. Add the original repository as remote to keep it up-to-date: `git remote add upstream https://github.com/Ionaru/easy-markdown-editor.git`. 28 | 1. Fetch the latest changes from upstream: `git fetch upstream`. 29 | 1. Run `npm ci` to install the required dependencies. 30 | 1. Create a new branch to work on: `git checkout -b MyNewFeatureName`. 31 | 1. Write your awesome improvement and commit your work. 32 | 1. Make sure your changes comply with the established code and tests succeed: `npm run test`. 33 | 1. Push your changes to GitHub: `git push origin`. 34 | 1. On GitHub, go to your forked branch, and click **New pull request**. 35 | 1. Choose the correct branches, add a description and submit your pull request! 36 | 37 | #### Continuing development 38 | To create more pull requests, please follow the steps below: 39 | 1. Go back to the master branch: `git checkout master`. 40 | 1. Fetch the upstream changes: `git fetch upstream`. 41 | 1. Update the master branch with upstream changes: `git merge upstream/master`. 42 | 1. Repeat ["Your first pull request"](#your-first-pull-request) from step 5. 43 | 44 | Thank you! 💜 45 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'); 4 | var cleanCSS = require('gulp-clean-css'); 5 | var terser = require('gulp-terser'); 6 | var concat = require('gulp-concat'); 7 | var header = require('gulp-header'); 8 | var buffer = require('vinyl-buffer'); 9 | var pkg = require('./package.json'); 10 | var eslint = require('gulp-eslint'); 11 | var browserify = require('browserify'); 12 | var source = require('vinyl-source-stream'); 13 | var rename = require('gulp-rename'); 14 | 15 | var banner = ['/**', 16 | ' * <%= pkg.name %> v<%= pkg.version %>', 17 | ' * Copyright <%= pkg.author %>', 18 | ' * @link https://github.com/ionaru/easy-markdown-editor', 19 | ' * @license <%= pkg.license %>', 20 | ' */', 21 | ''].join('\n'); 22 | 23 | 24 | var css_files = [ 25 | './node_modules/codemirror/lib/codemirror.css', 26 | './src/css/*.css', 27 | './node_modules/codemirror-spell-checker/src/css/spell-checker.css', 28 | ]; 29 | 30 | function lint() { 31 | return gulp.src('./src/js/**/*.js') 32 | .pipe(eslint()) 33 | .pipe(eslint.format()) 34 | .pipe(eslint.failAfterError()); 35 | } 36 | 37 | function scripts() { 38 | return browserify({entries: './src/js/easymde.js', standalone: 'EasyMDE'}).bundle() 39 | .pipe(source('easymde.min.js')) 40 | .pipe(buffer()) 41 | .pipe(terser()) 42 | .pipe(header(banner, {pkg: pkg})) 43 | .pipe(gulp.dest('./dist/')); 44 | } 45 | 46 | function styles() { 47 | return gulp.src(css_files) 48 | .pipe(concat('easymde.css')) 49 | .pipe(cleanCSS()) 50 | .pipe(rename('easymde.min.css')) 51 | .pipe(buffer()) 52 | .pipe(header(banner, {pkg: pkg})) 53 | .pipe(gulp.dest('./dist/')); 54 | } 55 | 56 | // Watch for file changes 57 | function watch() { 58 | gulp.watch('./src/js/**/*.js', scripts); 59 | gulp.watch(css_files, styles); 60 | } 61 | 62 | var build = gulp.parallel(gulp.series(lint, scripts), styles); 63 | 64 | gulp.task('default', build); 65 | gulp.task('watch', gulp.series(build, watch)); 66 | gulp.task('lint', lint); 67 | -------------------------------------------------------------------------------- /.github/workflows/cd.yaml: -------------------------------------------------------------------------------- 1 | name: Test & Deploy 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - master 8 | tags: 9 | - '*' 10 | pull_request: 11 | branches: 12 | - master 13 | 14 | jobs: 15 | 16 | audit: 17 | 18 | runs-on: ubuntu-latest 19 | 20 | steps: 21 | - uses: actions/setup-node@v4 22 | with: 23 | node-version: current 24 | 25 | - uses: actions/checkout@v4 26 | 27 | - run: npm audit --omit=dev 28 | 29 | test: 30 | 31 | needs: [ audit ] 32 | runs-on: ubuntu-latest 33 | 34 | strategy: 35 | matrix: 36 | node-version: [ '14', '16', '18' ] 37 | 38 | steps: 39 | - uses: actions/setup-node@v4 40 | with: 41 | node-version: ${{ matrix.node-version }} 42 | 43 | - uses: actions/checkout@v4 44 | 45 | - run: npm ci 46 | 47 | - name: Test 48 | run: npm test 49 | 50 | - uses: actions/upload-artifact@v4 51 | if: failure() 52 | with: 53 | name: cypress-screenshots-nodejs-${{ matrix.node-version }} 54 | path: cypress/screenshots 55 | retention-days: 7 56 | 57 | - uses: actions/upload-artifact@v4 58 | if: always() 59 | with: 60 | name: cypress-videos-nodejs-${{ matrix.node-version }} 61 | path: cypress/videos 62 | retention-days: 7 63 | 64 | deploy: 65 | 66 | needs: [ test ] 67 | runs-on: ubuntu-latest 68 | if: github.event_name == 'push' 69 | 70 | steps: 71 | - uses: actions/setup-node@v4 72 | with: 73 | node-version: current 74 | 75 | - uses: actions/checkout@v4 76 | 77 | - run: npm ci 78 | 79 | - name: Deploy @latest version to npm 80 | if: startsWith(github.ref, 'refs/tags/') 81 | uses: JS-DevTools/npm-publish@v1 82 | with: 83 | token: ${{ secrets.NPM_TOKEN }} 84 | 85 | - name: Update @next version 86 | if: startsWith(github.ref, 'refs/heads/') 87 | run: npm version prerelease --no-git-tag-version --preid "$GITHUB_RUN_NUMBER" 88 | 89 | - name: Deploy @next version to npm 90 | if: startsWith(github.ref, 'refs/heads/') 91 | uses: JS-DevTools/npm-publish@v1 92 | with: 93 | tag: next 94 | token: ${{ secrets.NPM_TOKEN }} 95 | check-version: false 96 | -------------------------------------------------------------------------------- /cypress/e2e/1-default-editor/statusbar.cy.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | describe('Default statusbar', () => { 4 | beforeEach(() => { 5 | cy.visit(__dirname + '/index.html'); 6 | }); 7 | 8 | it('loads the editor with default statusbar', () => { 9 | cy.get('.EasyMDEContainer').should('be.visible'); 10 | cy.get('.EasyMDEContainer .editor-statusbar').should('be.visible'); 11 | 12 | cy.get('.EasyMDEContainer .editor-statusbar .autosave').should('be.empty'); 13 | 14 | cy.get('.EasyMDEContainer .editor-statusbar .lines').before('content').should('contain', 'lines: '); 15 | cy.get('.EasyMDEContainer .editor-statusbar .lines').should('contain', '1'); 16 | 17 | cy.get('.EasyMDEContainer .editor-statusbar .words').before('content').should('contain', 'words: '); 18 | cy.get('.EasyMDEContainer .editor-statusbar .words').should('contain', '0'); 19 | 20 | cy.get('.EasyMDEContainer .editor-statusbar .cursor').should('contain', '1:1'); 21 | }); 22 | 23 | it('updates the statusbar when typing', () => { 24 | cy.get('.EasyMDEContainer').should('be.visible'); 25 | cy.get('.EasyMDEContainer .editor-statusbar').should('be.visible'); 26 | 27 | cy.get('.EasyMDEContainer .CodeMirror').type('Hello'); 28 | 29 | cy.get('.EasyMDEContainer .editor-statusbar .autosave').should('be.empty'); 30 | 31 | cy.get('.EasyMDEContainer .editor-statusbar .lines').should('contain', '1'); 32 | cy.get('.EasyMDEContainer .editor-statusbar .words').should('contain', '1'); 33 | cy.get('.EasyMDEContainer .editor-statusbar .cursor').should('contain', '1:6'); 34 | 35 | cy.get('.EasyMDEContainer .CodeMirror').type(' World'); 36 | 37 | cy.get('.EasyMDEContainer .editor-statusbar .lines').should('contain', '1'); 38 | cy.get('.EasyMDEContainer .editor-statusbar .words').should('contain', '2'); 39 | cy.get('.EasyMDEContainer .editor-statusbar .cursor').should('contain', '1:12'); 40 | 41 | cy.get('.EasyMDEContainer .CodeMirror').type('{enter}'); 42 | 43 | cy.get('.EasyMDEContainer .editor-statusbar .lines').should('contain', '2'); 44 | cy.get('.EasyMDEContainer .editor-statusbar .words').should('contain', '2'); 45 | cy.get('.EasyMDEContainer .editor-statusbar .cursor').should('contain', '2:1'); 46 | 47 | cy.get('.EasyMDEContainer .CodeMirror').type('This is a sample text.{enter}We\'re testing the statusbar.{enter}Did it work?'); 48 | 49 | cy.get('.EasyMDEContainer .editor-statusbar .autosave').should('be.empty'); 50 | cy.get('.EasyMDEContainer .editor-statusbar .lines').before('content').should('contain', 'lines: '); 51 | cy.get('.EasyMDEContainer .editor-statusbar .lines').should('contain', '4'); 52 | cy.get('.EasyMDEContainer .editor-statusbar .words').before('content').should('contain', 'words: '); 53 | cy.get('.EasyMDEContainer .editor-statusbar .words').should('contain', '15'); 54 | cy.get('.EasyMDEContainer .editor-statusbar .cursor').should('contain', '4:13'); 55 | }); 56 | }); 57 | -------------------------------------------------------------------------------- /types/easymde-test.ts: -------------------------------------------------------------------------------- 1 | // Create new instance 2 | import EasyMDE = require('./easymde'); 3 | 4 | const editor = new EasyMDE({ 5 | autoDownloadFontAwesome: false, 6 | element: document.getElementById('mdEditor')!, 7 | hideIcons: ['side-by-side', 'fullscreen'], 8 | inputStyle: 'textarea', 9 | shortcuts: { 10 | drawTable: 'Cmd-Alt-T', 11 | toggleFullScreen: null, 12 | }, 13 | previewClass: 'my-custom-class', 14 | spellChecker: false, 15 | onToggleFullScreen: (full: boolean) => { 16 | console.log('FullscreenToggled', full); 17 | }, 18 | theme: 'someOtherTheme', 19 | minHeight: '200px', 20 | }); 21 | 22 | // Editor functions 23 | const value = editor.value() as string; 24 | editor.value(value.toUpperCase()); 25 | 26 | const sbs = editor.isSideBySideActive() as boolean; 27 | const fullscreen = editor.isFullscreenActive() as boolean; 28 | 29 | // Access to codemirror object 30 | editor.codemirror.setOption('readOnly', true); 31 | 32 | // Static properties 33 | EasyMDE.toggleItalic = (editor: EasyMDE) => { 34 | console.log('SomeButtonOverride'); 35 | }; 36 | 37 | const editor2 = new EasyMDE({ 38 | autoDownloadFontAwesome: undefined, 39 | previewClass: ['my-custom-class', 'some-other-class'], 40 | nativeSpellcheck: true, 41 | unorderedListStyle: '-', 42 | inputStyle: 'contenteditable', 43 | toolbar: [ 44 | { 45 | name: 'bold', 46 | action: EasyMDE.toggleBold, 47 | className: 'fa fas fa-bolt', 48 | title: 'Bold', 49 | }, 50 | '|', 51 | 'undo', 52 | { 53 | name: 'alert', 54 | action: (editor: EasyMDE) => { 55 | alert('This is from a custom button action!'); 56 | // Custom functions have access to the `editor` instance. 57 | }, 58 | className: 'fa fas fa-star', 59 | title: 'A Custom Button', 60 | noDisable: undefined, 61 | noMobile: false, 62 | attributes: { 63 | 'data-custom': 'attribute', 64 | } 65 | }, 66 | '|', 67 | { 68 | name: 'link', 69 | action: 'https://github.com/Ionaru/easy-markdown-editor', 70 | className: 'fa fab fa-github', 71 | title: 'A Custom Link', 72 | noDisable: true, 73 | noMobile: true, 74 | }, 75 | 'preview', 76 | { 77 | name: 'links', 78 | className: 'fa fas fa-arrow-down', 79 | title: 'A Custom Link', 80 | children: [ 81 | { 82 | name: 'link', 83 | action: 'https://github.com/Ionaru/easy-markdown-editor', 84 | className: 'fa fab fa-github', 85 | title: 'A Custom Link', 86 | noDisable: true, 87 | noMobile: true, 88 | }, 89 | 'preview', 90 | { 91 | name: 'bold', 92 | action: EasyMDE.toggleBold, 93 | className: 'fa fas fa-bold', 94 | title: 'Bold', 95 | attributes: { 96 | 'data-custom': 'some value', 97 | 'data-custom-2': 'another value', 98 | } 99 | }, 100 | ], 101 | }, 102 | ], 103 | }); 104 | 105 | editor2.clearAutosavedValue(); 106 | editor2.updateStatusBar('upload-image', 'Drag & drop images!'); 107 | 108 | EasyMDE.togglePreview(editor2); 109 | EasyMDE.toggleSideBySide(editor2); 110 | 111 | const editorImages = new EasyMDE({ 112 | uploadImage: true, 113 | previewImagesInEditor: false, 114 | imageAccept: 'image/png, image/bmp', 115 | imageCSRFToken: undefined, 116 | unorderedListStyle: '+', 117 | imageMaxSize: 10485760, 118 | imageUploadEndpoint: 'https://my.domain/image-upload/', 119 | imageTexts: { 120 | sbInit: 'Drag & drop images!', 121 | sbOnDragEnter: 'Let it go, let it go', 122 | sbOnDrop: 'Uploading...', 123 | sbProgress: 'Uploading... (#progress#)', 124 | sbOnUploaded: 'Upload complete!', 125 | sizeUnits: 'b,Kb,Mb', 126 | }, 127 | errorMessages: { 128 | noFileGiven: 'Please select a file', 129 | typeNotAllowed: 'This file type is not allowed!', 130 | fileTooLarge: 'Image too big', 131 | importError: 'Something went oops!', 132 | }, 133 | errorCallback: errorMessage => { 134 | console.error(errorMessage); 135 | }, 136 | }); 137 | 138 | const editorImagesCustom = new EasyMDE({ 139 | uploadImage: true, 140 | imageAccept: 'image/png, image/bmp', 141 | imageCSRFToken: undefined, 142 | imageMaxSize: 10485760, 143 | imageUploadFunction: (file: File, onSuccess, onError) => { 144 | console.log(file); 145 | onSuccess('http://image.url/9.png'); 146 | onError('Failed because reasons.'); 147 | }, 148 | imageTexts: { 149 | sbInit: 'Drag & drop images!', 150 | sbOnDragEnter: 'Let it go, let it go', 151 | sbOnDrop: 'Uploading...', 152 | sbProgress: 'Uploading... (#progress#)', 153 | sbOnUploaded: 'Upload complete!', 154 | sizeUnits: 'b,Kb,Mb', 155 | }, 156 | errorMessages: { 157 | noFileGiven: 'Please select a file', 158 | typeNotAllowed: 'This file type is not allowed!', 159 | fileTooLarge: 'Image too big', 160 | importError: 'Something went oops!', 161 | }, 162 | errorCallback: errorMessage => { 163 | console.error(errorMessage); 164 | }, 165 | renderingConfig: { 166 | codeSyntaxHighlighting: true, 167 | markedOptions: { 168 | silent: true, 169 | highlight(code: string, lang: string, callback?: (error: (any | undefined), code: string) => void): string { 170 | return 'something'; 171 | }, 172 | }, 173 | }, 174 | promptTexts: { 175 | image: 'Insert URL', 176 | }, 177 | syncSideBySidePreviewScroll: true, 178 | }); 179 | 180 | new EasyMDE({ 181 | toolbarButtonClassPrefix: 'mde', 182 | sideBySideFullscreen: true, 183 | lineNumbers: false, 184 | unorderedListStyle: '*', 185 | autosave: { 186 | enabled: true, 187 | delay: 2000, 188 | submit_delay: 10000, 189 | uniqueId: 'abc', 190 | timeFormat: { 191 | locale: 'en-GB', 192 | format: { 193 | month: 'long', 194 | }, 195 | }, 196 | text: 'Stored: ', 197 | }, 198 | }); 199 | 200 | new EasyMDE({ 201 | sideBySideFullscreen: false, 202 | lineNumbers: true, 203 | maxHeight: '500px', 204 | toolbar: [ 205 | 'bold', 206 | 'italic', 207 | 'heading', 208 | '|', 209 | 'quote', 210 | 'unordered-list', 211 | 'ordered-list', 212 | 'table', 213 | 'upload-image', 214 | '|', 215 | 'link', 216 | ], 217 | }); 218 | 219 | new EasyMDE({ 220 | direction: 'ltr', 221 | }); 222 | 223 | new EasyMDE({ 224 | direction: 'rtl', 225 | }); 226 | 227 | new EasyMDE({ 228 | previewRender: (plainText: string) => { 229 | return '
' + plainText + '
'; 230 | } 231 | }); 232 | 233 | new EasyMDE({ 234 | previewRender: (plainText: string, preview) => { 235 | preview.innerHTML = '
' + plainText + '
'; 236 | return null; 237 | } 238 | }); 239 | -------------------------------------------------------------------------------- /types/easymde.d.ts: -------------------------------------------------------------------------------- 1 | // This file is based on https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/simplemde/index.d.ts, 2 | // which is written by Scalesoft and licensed under the MIT license: 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | 22 | /// 23 | 24 | import { marked } from 'marked'; 25 | 26 | interface ArrayOneOrMore extends Array { 27 | 0: T; 28 | } 29 | 30 | type ToolbarButton = 31 | 'bold' 32 | | 'italic' 33 | | 'quote' 34 | | 'unordered-list' 35 | | 'ordered-list' 36 | | 'link' 37 | | 'image' 38 | | 'upload-image' 39 | | 'strikethrough' 40 | | 'code' 41 | | 'table' 42 | | 'redo' 43 | | 'heading' 44 | | 'undo' 45 | | 'heading-bigger' 46 | | 'heading-smaller' 47 | | 'heading-1' 48 | | 'heading-2' 49 | | 'heading-3' 50 | | 'clean-block' 51 | | 'horizontal-rule' 52 | | 'preview' 53 | | 'side-by-side' 54 | | 'fullscreen' 55 | | 'guide'; 56 | 57 | declare namespace EasyMDE { 58 | 59 | interface TimeFormatOptions { 60 | locale?: string | string[]; 61 | format?: Intl.DateTimeFormatOptions; 62 | } 63 | 64 | interface AutoSaveOptions { 65 | enabled?: boolean; 66 | delay?: number; 67 | submit_delay?: number; 68 | uniqueId: string; 69 | timeFormat?: TimeFormatOptions; 70 | text?: string; 71 | } 72 | 73 | interface BlockStyleOptions { 74 | bold?: string; 75 | code?: string; 76 | italic?: string; 77 | } 78 | 79 | interface CustomAttributes { 80 | [key: string]: string; 81 | } 82 | 83 | interface InsertTextOptions { 84 | horizontalRule?: ReadonlyArray; 85 | image?: ReadonlyArray; 86 | link?: ReadonlyArray; 87 | table?: ReadonlyArray; 88 | } 89 | 90 | interface ParsingOptions { 91 | allowAtxHeaderWithoutSpace?: boolean; 92 | strikethrough?: boolean; 93 | underscoresBreakWords?: boolean; 94 | } 95 | 96 | interface PromptTexts { 97 | image?: string; 98 | link?: string; 99 | } 100 | 101 | interface RenderingOptions { 102 | codeSyntaxHighlighting?: boolean; 103 | hljs?: any; 104 | markedOptions?: marked.MarkedExtension; 105 | sanitizerFunction?: (html: string) => string; 106 | singleLineBreaks?: boolean; 107 | } 108 | 109 | interface Shortcuts { 110 | [action: string]: string | undefined | null; 111 | 112 | toggleBlockquote?: string | null; 113 | toggleBold?: string | null; 114 | cleanBlock?: string | null; 115 | toggleHeadingSmaller?: string | null; 116 | toggleItalic?: string | null; 117 | drawLink?: string | null; 118 | toggleUnorderedList?: string | null; 119 | togglePreview?: string | null; 120 | toggleCodeBlock?: string | null; 121 | drawImage?: string | null; 122 | toggleOrderedList?: string | null; 123 | toggleHeadingBigger?: string | null; 124 | toggleSideBySide?: string | null; 125 | toggleFullScreen?: string | null; 126 | } 127 | 128 | interface StatusBarItem { 129 | className: string; 130 | defaultValue: (element: HTMLElement) => void; 131 | onUpdate: (element: HTMLElement) => void; 132 | } 133 | 134 | interface ToolbarDropdownIcon { 135 | name: string; 136 | children: ArrayOneOrMore; 137 | className: string; 138 | title: string; 139 | noDisable?: boolean; 140 | noMobile?: boolean; 141 | } 142 | 143 | interface ToolbarIcon { 144 | name: string; 145 | action: string | ((editor: EasyMDE) => void); 146 | className: string; 147 | title: string; 148 | noDisable?: boolean; 149 | noMobile?: boolean; 150 | icon?: string; 151 | attributes?: CustomAttributes; 152 | } 153 | 154 | interface ImageTextsOptions { 155 | sbInit?: string; 156 | sbOnDragEnter?: string; 157 | sbOnDrop?: string; 158 | sbProgress?: string; 159 | sbOnUploaded?: string; 160 | sizeUnits?: string; 161 | } 162 | 163 | interface ImageErrorTextsOptions { 164 | noFileGiven?: string; 165 | typeNotAllowed?: string; 166 | fileTooLarge?: string; 167 | importError?: string; 168 | } 169 | 170 | interface OverlayModeOptions { 171 | mode: CodeMirror.Mode; 172 | combine?: boolean; 173 | } 174 | 175 | interface SpellCheckerOptions { 176 | codeMirrorInstance: CodeMirror.Editor; 177 | } 178 | 179 | interface Options { 180 | autoDownloadFontAwesome?: boolean; 181 | autofocus?: boolean; 182 | autosave?: AutoSaveOptions; 183 | autoRefresh?: boolean | { delay: number; }; 184 | blockStyles?: BlockStyleOptions; 185 | element?: HTMLElement; 186 | forceSync?: boolean; 187 | hideIcons?: ReadonlyArray; 188 | indentWithTabs?: boolean; 189 | initialValue?: string; 190 | insertTexts?: InsertTextOptions; 191 | lineNumbers?: boolean; 192 | lineWrapping?: boolean; 193 | minHeight?: string; 194 | maxHeight?: string; 195 | parsingConfig?: ParsingOptions; 196 | placeholder?: string; 197 | previewClass?: string | ReadonlyArray; 198 | previewImagesInEditor?: boolean; 199 | imagesPreviewHandler?: (src: string) => string, 200 | previewRender?: (markdownPlaintext: string, previewElement: HTMLElement) => string | null; 201 | promptURLs?: boolean; 202 | renderingConfig?: RenderingOptions; 203 | shortcuts?: Shortcuts; 204 | showIcons?: ReadonlyArray; 205 | spellChecker?: boolean | ((options: SpellCheckerOptions) => void); 206 | inputStyle?: 'textarea' | 'contenteditable'; 207 | nativeSpellcheck?: boolean; 208 | sideBySideFullscreen?: boolean; 209 | status?: boolean | ReadonlyArray; 210 | styleSelectedText?: boolean; 211 | tabSize?: number; 212 | toolbar?: boolean | ReadonlyArray<'|' | ToolbarButton | ToolbarIcon | ToolbarDropdownIcon>; 213 | toolbarTips?: boolean; 214 | toolbarButtonClassPrefix?: string; 215 | onToggleFullScreen?: (goingIntoFullScreen: boolean) => void; 216 | theme?: string; 217 | scrollbarStyle?: string; 218 | unorderedListStyle?: '*' | '-' | '+'; 219 | 220 | uploadImage?: boolean; 221 | imageMaxSize?: number; 222 | imageAccept?: string; 223 | imageUploadFunction?: (file: File, onSuccess: (url: string) => void, onError: (error: string) => void) => void; 224 | imageUploadEndpoint?: string; 225 | imagePathAbsolute?: boolean; 226 | imageCSRFToken?: string; 227 | imageCSRFName?: string; 228 | imageCSRFHeader?: boolean; 229 | imageTexts?: ImageTextsOptions; 230 | imageInputName?: string 231 | errorMessages?: ImageErrorTextsOptions; 232 | errorCallback?: (errorMessage: string) => void; 233 | 234 | promptTexts?: PromptTexts; 235 | syncSideBySidePreviewScroll?: boolean; 236 | 237 | overlayMode?: OverlayModeOptions; 238 | 239 | direction?: 'ltr' | 'rtl'; 240 | } 241 | } 242 | 243 | declare class EasyMDE { 244 | constructor(options?: EasyMDE.Options); 245 | 246 | value(): string; 247 | value(val: string): void; 248 | 249 | codemirror: CodeMirror.Editor; 250 | 251 | cleanup(): void; 252 | 253 | toTextArea(): void; 254 | 255 | isPreviewActive(): boolean; 256 | 257 | isSideBySideActive(): boolean; 258 | 259 | isFullscreenActive(): boolean; 260 | 261 | clearAutosavedValue(): void; 262 | 263 | updateStatusBar(itemName: string, content: string): void; 264 | 265 | static toggleBold: (editor: EasyMDE) => void; 266 | static toggleItalic: (editor: EasyMDE) => void; 267 | static toggleStrikethrough: (editor: EasyMDE) => void; 268 | static toggleHeadingSmaller: (editor: EasyMDE) => void; 269 | static toggleHeadingBigger: (editor: EasyMDE) => void; 270 | static toggleHeading1: (editor: EasyMDE) => void; 271 | static toggleHeading2: (editor: EasyMDE) => void; 272 | static toggleHeading3: (editor: EasyMDE) => void; 273 | static toggleHeading4: (editor: EasyMDE) => void; 274 | static toggleHeading5: (editor: EasyMDE) => void; 275 | static toggleHeading6: (editor: EasyMDE) => void; 276 | static toggleCodeBlock: (editor: EasyMDE) => void; 277 | static toggleBlockquote: (editor: EasyMDE) => void; 278 | static toggleUnorderedList: (editor: EasyMDE) => void; 279 | static toggleOrderedList: (editor: EasyMDE) => void; 280 | static cleanBlock: (editor: EasyMDE) => void; 281 | static drawLink: (editor: EasyMDE) => void; 282 | static drawImage: (editor: EasyMDE) => void; 283 | static drawUploadedImage: (editor: EasyMDE) => void; 284 | static drawTable: (editor: EasyMDE) => void; 285 | static drawHorizontalRule: (editor: EasyMDE) => void; 286 | static togglePreview: (editor: EasyMDE) => void; 287 | static toggleSideBySide: (editor: EasyMDE) => void; 288 | static toggleFullScreen: (editor: EasyMDE) => void; 289 | static undo: (editor: EasyMDE) => void; 290 | static redo: (editor: EasyMDE) => void; 291 | } 292 | 293 | export as namespace EasyMDE; 294 | export = EasyMDE; 295 | -------------------------------------------------------------------------------- /src/css/easymde.css: -------------------------------------------------------------------------------- 1 | .EasyMDEContainer { 2 | display: block; 3 | } 4 | 5 | .CodeMirror-rtl pre { 6 | direction: rtl; 7 | } 8 | 9 | .EasyMDEContainer.sided--no-fullscreen { 10 | display: flex; 11 | flex-direction: row; 12 | flex-wrap: wrap; 13 | } 14 | 15 | .EasyMDEContainer .CodeMirror { 16 | box-sizing: border-box; 17 | height: auto; 18 | border: 1px solid #ced4da; 19 | border-bottom-left-radius: 4px; 20 | border-bottom-right-radius: 4px; 21 | padding: 10px; 22 | font: inherit; 23 | z-index: 0; 24 | word-wrap: break-word; 25 | } 26 | 27 | .EasyMDEContainer .CodeMirror-scroll { 28 | cursor: text; 29 | } 30 | 31 | .EasyMDEContainer .CodeMirror-fullscreen { 32 | background: #fff; 33 | position: fixed !important; 34 | top: 50px; 35 | left: 0; 36 | right: 0; 37 | bottom: 0; 38 | height: auto; 39 | z-index: 8; 40 | border-right: none !important; 41 | border-bottom-right-radius: 0 !important; 42 | } 43 | 44 | .EasyMDEContainer .CodeMirror-sided { 45 | width: 50% !important; 46 | } 47 | 48 | .EasyMDEContainer.sided--no-fullscreen .CodeMirror-sided { 49 | border-right: none !important; 50 | border-bottom-right-radius: 0; 51 | position: relative; 52 | flex: 1 1 auto; 53 | } 54 | 55 | .EasyMDEContainer .CodeMirror-placeholder { 56 | opacity: .5; 57 | } 58 | 59 | .EasyMDEContainer .CodeMirror-focused .CodeMirror-selected { 60 | background: #d9d9d9; 61 | } 62 | 63 | .editor-toolbar { 64 | position: relative; 65 | -webkit-user-select: none; 66 | -moz-user-select: none; 67 | -ms-user-select: none; 68 | -o-user-select: none; 69 | user-select: none; 70 | padding: 9px 10px; 71 | border-top: 1px solid #ced4da; 72 | border-left: 1px solid #ced4da; 73 | border-right: 1px solid #ced4da; 74 | border-top-left-radius: 4px; 75 | border-top-right-radius: 4px; 76 | } 77 | 78 | .editor-toolbar.fullscreen { 79 | width: 100%; 80 | height: 50px; 81 | padding-top: 10px; 82 | padding-bottom: 10px; 83 | box-sizing: border-box; 84 | background: #fff; 85 | border: 0; 86 | position: fixed; 87 | top: 0; 88 | left: 0; 89 | opacity: 1; 90 | z-index: 9; 91 | } 92 | 93 | .editor-toolbar.fullscreen::before { 94 | width: 20px; 95 | height: 50px; 96 | background: -moz-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%); 97 | background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 1)), color-stop(100%, rgba(255, 255, 255, 0))); 98 | background: -webkit-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%); 99 | background: -o-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%); 100 | background: -ms-linear-gradient(left, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%); 101 | background: linear-gradient(to right, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0) 100%); 102 | position: fixed; 103 | top: 0; 104 | left: 0; 105 | margin: 0; 106 | padding: 0; 107 | } 108 | 109 | .editor-toolbar.fullscreen::after { 110 | width: 20px; 111 | height: 50px; 112 | background: -moz-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%); 113 | background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 0)), color-stop(100%, rgba(255, 255, 255, 1))); 114 | background: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%); 115 | background: -o-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%); 116 | background: -ms-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%); 117 | background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 1) 100%); 118 | position: fixed; 119 | top: 0; 120 | right: 0; 121 | margin: 0; 122 | padding: 0; 123 | } 124 | 125 | .EasyMDEContainer.sided--no-fullscreen .editor-toolbar { 126 | width: 100%; 127 | } 128 | 129 | .editor-toolbar button, .editor-toolbar .easymde-dropdown { 130 | background: transparent; 131 | display: inline-block; 132 | text-align: center; 133 | text-decoration: none !important; 134 | height: 30px; 135 | margin: 0; 136 | padding: 0; 137 | border: 1px solid transparent; 138 | border-radius: 3px; 139 | cursor: pointer; 140 | } 141 | 142 | .editor-toolbar button { 143 | font-weight: bold; 144 | min-width: 30px; 145 | padding: 0 6px; 146 | white-space: nowrap; 147 | } 148 | 149 | .editor-toolbar button.active, 150 | .editor-toolbar button:hover { 151 | background: #fcfcfc; 152 | border-color: #95a5a6; 153 | } 154 | 155 | .editor-toolbar i.separator { 156 | display: inline-block; 157 | width: 0; 158 | border-left: 1px solid #d9d9d9; 159 | border-right: 1px solid #fff; 160 | color: transparent; 161 | text-indent: -10px; 162 | margin: 0 6px; 163 | } 164 | 165 | .editor-toolbar button:after { 166 | font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; 167 | font-size: 65%; 168 | vertical-align: text-bottom; 169 | position: relative; 170 | top: 2px; 171 | } 172 | 173 | .editor-toolbar button.heading-1:after { 174 | content: "1"; 175 | } 176 | 177 | .editor-toolbar button.heading-2:after { 178 | content: "2"; 179 | } 180 | 181 | .editor-toolbar button.heading-3:after { 182 | content: "3"; 183 | } 184 | 185 | .editor-toolbar button.heading-bigger:after { 186 | content: "▲"; 187 | } 188 | 189 | .editor-toolbar button.heading-smaller:after { 190 | content: "▼"; 191 | } 192 | 193 | .editor-toolbar.disabled-for-preview button:not(.no-disable) { 194 | opacity: .6; 195 | pointer-events: none; 196 | } 197 | 198 | @media only screen and (max-width: 700px) { 199 | .editor-toolbar i.no-mobile { 200 | display: none; 201 | } 202 | } 203 | 204 | .editor-statusbar { 205 | padding: 8px 10px; 206 | font-size: 12px; 207 | color: #959694; 208 | text-align: right; 209 | } 210 | 211 | .EasyMDEContainer.sided--no-fullscreen .editor-statusbar { 212 | width: 100%; 213 | } 214 | 215 | .editor-statusbar span { 216 | display: inline-block; 217 | min-width: 4em; 218 | margin-left: 1em; 219 | } 220 | 221 | .editor-statusbar .lines:before { 222 | content: 'lines: ' 223 | } 224 | 225 | .editor-statusbar .words:before { 226 | content: 'words: ' 227 | } 228 | 229 | .editor-statusbar .characters:before { 230 | content: 'characters: ' 231 | } 232 | 233 | .editor-preview-full { 234 | position: absolute; 235 | width: 100%; 236 | height: 100%; 237 | top: 0; 238 | left: 0; 239 | z-index: 7; 240 | overflow: auto; 241 | display: none; 242 | box-sizing: border-box; 243 | } 244 | 245 | .editor-preview-side { 246 | position: fixed; 247 | bottom: 0; 248 | width: 50%; 249 | top: 50px; 250 | right: 0; 251 | z-index: 9; 252 | overflow: auto; 253 | display: none; 254 | box-sizing: border-box; 255 | border: 1px solid #ddd; 256 | word-wrap: break-word; 257 | } 258 | 259 | .editor-preview-active-side { 260 | display: block 261 | } 262 | 263 | .EasyMDEContainer.sided--no-fullscreen .editor-preview-active-side { 264 | flex: 1 1 auto; 265 | height: auto; 266 | position: static; 267 | } 268 | 269 | .editor-preview-active { 270 | display: block 271 | } 272 | 273 | .editor-preview { 274 | padding: 10px; 275 | background: #fafafa; 276 | } 277 | 278 | .editor-preview > p { 279 | margin-top: 0 280 | } 281 | 282 | .editor-preview pre { 283 | background: #eee; 284 | margin-bottom: 10px; 285 | } 286 | 287 | .editor-preview table td, 288 | .editor-preview table th { 289 | border: 1px solid #ddd; 290 | padding: 5px; 291 | } 292 | 293 | .cm-s-easymde .cm-tag { 294 | color: #63a35c; 295 | } 296 | 297 | .cm-s-easymde .cm-attribute { 298 | color: #795da3; 299 | } 300 | 301 | .cm-s-easymde .cm-string { 302 | color: #183691; 303 | } 304 | 305 | .cm-s-easymde .cm-header-1 { 306 | font-size: calc(1.375rem + 1.5vw); 307 | } 308 | 309 | .cm-s-easymde .cm-header-2 { 310 | font-size: calc(1.325rem + .9vw); 311 | } 312 | 313 | .cm-s-easymde .cm-header-3 { 314 | font-size: calc(1.3rem + .6vw); 315 | } 316 | 317 | .cm-s-easymde .cm-header-4 { 318 | font-size: calc(1.275rem + .3vw); 319 | } 320 | 321 | .cm-s-easymde .cm-header-5 { 322 | font-size: 1.25rem; 323 | } 324 | 325 | .cm-s-easymde .cm-header-6 { 326 | font-size: 1rem; 327 | } 328 | 329 | .cm-s-easymde .cm-header-1, 330 | .cm-s-easymde .cm-header-2, 331 | .cm-s-easymde .cm-header-3, 332 | .cm-s-easymde .cm-header-4, 333 | .cm-s-easymde .cm-header-5, 334 | .cm-s-easymde .cm-header-6 { 335 | margin-bottom: .5rem; 336 | line-height: 1.2; 337 | } 338 | 339 | .cm-s-easymde .cm-comment { 340 | background: rgba(0, 0, 0, .05); 341 | border-radius: 2px; 342 | } 343 | 344 | .cm-s-easymde .cm-link { 345 | color: #7f8c8d; 346 | } 347 | 348 | .cm-s-easymde .cm-url { 349 | color: #aab2b3; 350 | } 351 | 352 | .cm-s-easymde .cm-quote { 353 | color: #7f8c8d; 354 | font-style: italic; 355 | } 356 | 357 | .editor-toolbar .easymde-dropdown { 358 | position: relative; 359 | background: linear-gradient(to bottom right, #fff 0%, #fff 84%, #333 50%, #333 100%); 360 | border-radius: 0; 361 | border: 1px solid #fff; 362 | } 363 | 364 | .editor-toolbar .easymde-dropdown:hover { 365 | background: linear-gradient(to bottom right, #fff 0%, #fff 84%, #333 50%, #333 100%); 366 | } 367 | 368 | .easymde-dropdown-content { 369 | display: block; 370 | visibility: hidden; 371 | position: absolute; 372 | background-color: #f9f9f9; 373 | box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); 374 | padding: 8px; 375 | z-index: 2; 376 | top: 30px; 377 | } 378 | 379 | .easymde-dropdown:active .easymde-dropdown-content, 380 | .easymde-dropdown:focus .easymde-dropdown-content, 381 | .easymde-dropdown:focus-within .easymde-dropdown-content { 382 | visibility: visible; 383 | } 384 | 385 | .easymde-dropdown-content button { 386 | display: block; 387 | } 388 | 389 | span[data-img-src]::after { 390 | content: ''; 391 | /*noinspection CssUnresolvedCustomProperty, added through JS*/ 392 | background-image: var(--bg-image); 393 | display: block; 394 | max-height: 100%; 395 | max-width: 100%; 396 | background-size: contain; 397 | height: 0; 398 | /*noinspection CssUnresolvedCustomProperty, added through JS*/ 399 | padding-top: var(--height); 400 | /*noinspection CssUnresolvedCustomProperty, added through JS*/ 401 | width: var(--width); 402 | background-repeat: no-repeat; 403 | } 404 | -------------------------------------------------------------------------------- /cypress/e2e/2-url-prompt/url-prompt.cy.js: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | describe('URL prompts', () => { 4 | beforeEach(() => { 5 | cy.visit(__dirname + '/index.html'); 6 | }); 7 | 8 | it('must show the correct text for a link prompt', () => { 9 | cy.get('.EasyMDEContainer').should('be.visible'); 10 | cy.get('#textarea').should('not.be.visible'); 11 | 12 | cy.window().then(($win) => { 13 | const stub = cy.stub($win, 'prompt'); 14 | cy.get('button.link').click(); 15 | cy.get('button.link').then(() => { 16 | expect(stub).to.be.calledWith('URL for the link:', 'https://'); 17 | }); 18 | }); 19 | }); 20 | 21 | it('must show the correct text for an image prompt', () => { 22 | cy.get('.EasyMDEContainer').should('be.visible'); 23 | cy.get('#textarea').should('not.be.visible'); 24 | 25 | cy.window().then(($win) => { 26 | const stub = cy.stub($win, 'prompt'); 27 | cy.get('button.image').click(); 28 | cy.get('button.image').then(() => { 29 | expect(stub).to.be.calledWith('URL of the image:', 'https://'); 30 | }); 31 | }); 32 | }); 33 | 34 | it('must enter a link correctly through a prompt', () => { 35 | cy.get('.EasyMDEContainer').should('be.visible'); 36 | cy.get('#textarea').should('not.be.visible'); 37 | 38 | cy.window().then(($win) => { 39 | cy.stub($win, 'prompt').returns('https://example.com'); 40 | cy.get('button.link').click(); 41 | }); 42 | cy.get('.EasyMDEContainer .CodeMirror').contains('[](https://example.com)'); 43 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}{rightarrow}Link to a website!'); 44 | 45 | cy.previewOn(); 46 | 47 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

Link to a website!

'); 48 | }); 49 | 50 | it('can use the prompt multiple times', () => { 51 | cy.get('.EasyMDEContainer').should('be.visible'); 52 | cy.get('#textarea').should('not.be.visible'); 53 | 54 | cy.window().then(($win) => { 55 | const stub = cy.stub($win, 'prompt'); 56 | stub.returns('https://example.com'); 57 | cy.get('button.link').click(); 58 | cy.get('button.link').then(() => { 59 | expect(stub).to.be.calledWith('URL for the link:', 'https://'); 60 | stub.restore(); 61 | }); 62 | }); 63 | cy.get('.EasyMDEContainer .CodeMirror').contains('[](https://example.com)'); 64 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}{rightarrow}Link to a website!{end}{enter}'); 65 | 66 | cy.window().then(($win) => { 67 | const stub = cy.stub($win, 'prompt'); 68 | stub.returns('https://example.eu'); 69 | cy.get('button.link').click(); 70 | cy.get('button.link').then(() => { 71 | expect(stub).to.be.calledWith('URL for the link:', 'https://'); 72 | stub.restore(); 73 | }); 74 | }); 75 | cy.get('.EasyMDEContainer .CodeMirror').contains('[](https://example.eu)'); 76 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}{rightarrow}Link to a second website!'); 77 | 78 | cy.get('.EasyMDEContainer .CodeMirror').contains('[Link to a website!](https://example.com)'); 79 | cy.get('.EasyMDEContainer .CodeMirror').contains('[Link to a second website!](https://example.eu)'); 80 | 81 | cy.previewOn(); 82 | 83 | cy.get('.EasyMDEContainer .editor-preview').should( 84 | 'contain.html', 85 | '

Link to a website!
Link to a second website!

', 86 | ); 87 | }); 88 | 89 | it('must be able to deal with parameters in links', () => { 90 | cy.get('.EasyMDEContainer').should('be.visible'); 91 | cy.get('#textarea').should('not.be.visible'); 92 | 93 | cy.window().then(($win) => { 94 | cy.stub($win, 'prompt').returns('https://example.com?some=param&moo=cow'); 95 | cy.get('button.link').click(); 96 | }); 97 | cy.get('.EasyMDEContainer .CodeMirror').contains('[](https://example.com?some=param&moo=cow)'); 98 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}{rightarrow}Link to a website!'); 99 | 100 | cy.previewOn(); 101 | 102 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

Link to a website!

'); 103 | }); 104 | 105 | it('must be able to deal with brackets in links', () => { 106 | cy.get('.EasyMDEContainer').should('be.visible'); 107 | cy.get('#textarea').should('not.be.visible'); 108 | 109 | cy.window().then(($win) => { 110 | cy.stub($win, 'prompt').returns('https://example.com?some=[]param'); 111 | cy.get('button.link').click(); 112 | }); 113 | cy.get('.EasyMDEContainer .CodeMirror').contains('[](https://example.com?some=%5B%5Dparam)'); 114 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}{rightarrow}Link to a website!'); 115 | 116 | cy.previewOn(); 117 | 118 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

Link to a website!

'); 119 | }); 120 | 121 | it('must be able to deal with parentheses in links', () => { 122 | cy.get('.EasyMDEContainer').should('be.visible'); 123 | cy.get('#textarea').should('not.be.visible'); 124 | 125 | cy.window().then(($win) => { 126 | cy.stub($win, 'prompt').returns('https://example.com?some=(param)'); 127 | cy.get('button.link').click(); 128 | }); 129 | cy.get('.EasyMDEContainer .CodeMirror').contains('[](https://example.com?some=\\(param\\))'); 130 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}{rightarrow}Link to a website!'); 131 | 132 | cy.previewOn(); 133 | 134 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

Link to a website!

'); 135 | }); 136 | 137 | it('must be able to deal with parentheses in links (multiple)', () => { 138 | cy.get('.EasyMDEContainer').should('be.visible'); 139 | cy.get('#textarea').should('not.be.visible'); 140 | 141 | cy.window().then(($win) => { 142 | cy.stub($win, 'prompt').returns('https://example.com?some=(param1,param2)&more=(param3,param4)&end=true'); 143 | cy.get('button.link').click(); 144 | }); 145 | cy.get('.EasyMDEContainer .CodeMirror').contains('[](https://example.com?some=\\(param1,param2\\)&more=\\(param3,param4\\)&end=true)'); 146 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}{rightarrow}Link to a website!'); 147 | 148 | cy.previewOn(); 149 | 150 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

Link to a website!

'); 151 | }); 152 | 153 | it('must be able to deal with unbalanced parentheses in links (opening)', () => { 154 | cy.get('.EasyMDEContainer').should('be.visible'); 155 | cy.get('#textarea').should('not.be.visible'); 156 | 157 | cy.window().then(($win) => { 158 | cy.stub($win, 'prompt').returns('https://example.com?some=(param'); 159 | cy.get('button.link').click(); 160 | }); 161 | cy.get('.EasyMDEContainer .CodeMirror').contains('[](https://example.com?some=\\(param)'); 162 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}{rightarrow}Link to a website!'); 163 | 164 | cy.previewOn(); 165 | 166 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

Link to a website!

'); 167 | }); 168 | 169 | it('must be able to deal with unbalanced parentheses in links (closing)', () => { 170 | cy.get('.EasyMDEContainer').should('be.visible'); 171 | cy.get('#textarea').should('not.be.visible'); 172 | 173 | cy.window().then(($win) => { 174 | cy.stub($win, 'prompt').returns('https://example.com?some=)param'); 175 | cy.get('button.link').click(); 176 | }); 177 | cy.get('.EasyMDEContainer .CodeMirror').contains('[](https://example.com?some=\\)param)'); 178 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}{rightarrow}Link to a website!'); 179 | 180 | cy.previewOn(); 181 | 182 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

Link to a website!

'); 183 | }); 184 | 185 | it('must be able to deal with inequality symbols in links', () => { 186 | cy.get('.EasyMDEContainer').should('be.visible'); 187 | cy.get('#textarea').should('not.be.visible'); 188 | 189 | cy.window().then(($win) => { 190 | cy.stub($win, 'prompt').returns('https://example.com?some=Link to a website!

'); 199 | }); 200 | 201 | it('must be able to deal with emoji in links', () => { 202 | cy.get('.EasyMDEContainer').should('be.visible'); 203 | cy.get('#textarea').should('not.be.visible'); 204 | 205 | cy.window().then(($win) => { 206 | cy.stub($win, 'prompt').returns('https://example.com?some=👷‍♂️'); 207 | cy.get('button.link').click(); 208 | }); 209 | cy.get('.EasyMDEContainer .CodeMirror').contains('[](https://example.com?some=%F0%9F%91%B7%E2%80%8D%E2%99%82%EF%B8%8F'); 210 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}{rightarrow}Link to a 👌 website!'); 211 | 212 | cy.previewOn(); 213 | 214 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

Link to a 👌 website!

'); 215 | }); 216 | 217 | it('must be able to deal with spaces in links', () => { 218 | cy.get('.EasyMDEContainer').should('be.visible'); 219 | cy.get('#textarea').should('not.be.visible'); 220 | 221 | cy.window().then(($win) => { 222 | cy.stub($win, 'prompt').returns('https://example.com?some=very special param'); 223 | cy.get('button.link').click(); 224 | }); 225 | cy.get('.EasyMDEContainer .CodeMirror').contains('[](https://example.com?some=very%20special%20param'); 226 | cy.get('.EasyMDEContainer .CodeMirror').type('{home}{rightarrow}Link to a website!'); 227 | 228 | cy.previewOn(); 229 | 230 | cy.get('.EasyMDEContainer .editor-preview').should('contain.html', '

Link to a website!

'); 231 | }); 232 | }); 233 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # EasyMDE Changelog 2 | All notable changes to EasyMDE will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | 8 | ## [2.20.0] - 2025-03-04 9 | ### Added 10 | - Support for `marked` extensions (Thanks to [@codingjoe], [#611], [#514]). 11 | 12 | ## [2.19.0] - 2025-02-18 13 | ### Added 14 | - `updateStatusBar` type to typescript definitions (Thanks to [@borodean], [#519]). 15 | - `"upload-image"` option to the `ToolbarButton` typescript definitions (Thanks to [@borodean], [#520]). 16 | - `imageInputName` option to set a custom "name" attribute for the image input (Thanks to [@robinvandernoord], [#573]). 17 | 18 | ### Fixed 19 | - Relative image paths using the stylesheet as the source instead of the document (Thanks to [@p1gp1g], [#591]). 20 | - Excessive memory usage with the `previewImagesInEditor` option (Thanks to [@p1gp1g], [#592]). 21 | - Parentheses in the alt text of images causing the image not to load then using `previewImagesInEditor` (Thanks to [@mayraamaral], [#608]). 22 | 23 | ## [2.18.0] - 2022-09-20 24 | ### Added 25 | - `toolbarButtonClassPrefix` option to resolve conflicts with Bootstrap classes ([#493]). 26 | 27 | ## [2.17.0] - 2022-08-20 28 | ### Added 29 | - Improved CSRF support for uploading images (Thanks to [@ZsgsDesign], [#394]). 30 | - Option to register an image preview handler: `imagesPreviewHandler` (Thanks to [@diego-gw], [#411]). 31 | - Support for `.webp` image formats (Thanks to [@sghoweri], [#417]). 32 | - `toggleHeading` methods for headings 4, 5 and 6 (Thanks to [@vanillajonathan], [#449] and [#492]). 33 | - Support for `.gif`, `.avif` and `.apng` image formats (Thanks to [@vanillajonathan], [#450], [#458] and [#459]). 34 | - Keyboard shortcuts for `toggleHeading` methods (Thanks to [@vanillajonathan], [#451]). 35 | - `iconClassMap` option to specify icon class names for toolbar buttons (Thanks to [@vanillajonathan], [#454]). 36 | - `role="toolbar"` on the toolbar element (Thanks to [@vanillajonathan], [#455]). 37 | - Support for text buttons in the toolbar (Thanks to [@vanillajonathan], [#461]). 38 | - `aria-label` attribute for toolbar buttons (uses the `title` option) (Thanks to [@vanillajonathan], [#463]). 39 | - `role="application"` on the editor container element (Thanks to [@vanillajonathan], [#464]). 40 | - Option to not overwrite the preview HTML by returning `null` from `previewRender` (Thanks to [@LevitatingOrange], [#471]). 41 | 42 | ### Fixed 43 | - Hyperlink doubling (Thanks to [@danielok1993], [#95]). 44 | - URLs with certain characters entered through prompts causing invalid markdown (Thanks to [@Zignature], [#393]). 45 | - Autofocus option not working properly ([#399]). 46 | - Inconsistent border colour (Thanks to [@vanillajonathan], [#466]). 47 | - Invalid regex on Safari browsers ([#478]) 48 | - `hideIcons` option type (Thanks to [@LoyalPotato], [#488]). 49 | 50 | ### Changed 51 | - Editor now uses responsive font sizes (Thanks to [@vanillajonathan], [#452]). 52 | 53 | ### Documentation 54 | - Added several improvements to README (Thanks to [@vanillajonathan], [#436], [#438], [#440], [#444]). 55 | - Fixed typo in README (Thanks to [@kicksent], [#484]). 56 | - Added missing icon for `upload-image` in README (Thanks to [@hlf20010508], [#486]). 57 | 58 | ## [2.16.1] - 2022-01-14 59 | ### Fixed 60 | - Incorrect initial line and column count in status bar. 61 | - Security issue in `marked` dependency. 62 | 63 | ## [2.16.0] - 2022-01-11 64 | ### Added 65 | - `direction` option to enable RTL mode (Thanks to [@souljuse], [#358]). 66 | - `attributes` option to add custom attributes to toolbar buttons (Thanks to [@Zignature], [#388]). 67 | - `unorderedListStyle` option to change the character used for unordered lists (Thanks to [@Zignature], [#389]). 68 | 69 | ### Fixed 70 | - Image extension detection when extension is uppercase (Thanks to [@ukjinjang], [#357]). 71 | - Submenu actions not working in Chromium Browsers (Thanks to [@Offerel], [@robjean9] and [@kelvinj], [#364]). 72 | - Incorrect line and column count in status bar (Thanks to [@Zignature], [#384]). 73 | 74 | ## [2.15.0] - 2021-04-22 75 | ### Added 76 | - `imagePathAbsolute` option to return the absolute path when uploading an image (Thanks to [@wwsalmon], [#313]). 77 | 78 | ### Fixed 79 | - `ToolbarIcon` typings, added `icon` (Thanks to [@ChronosMasterOfAllTime], [#308]). 80 | - Image link extension when it was not the last part of the URL (Thanks to [@deerboy], [#311]). 81 | - Preview mode did not stay enabled when toggling to fullscreen (Thanks to [@smundro], [#316]). 82 | - Required typings not being included in `dependencies` (Thanks to [@marekdedic], [#322]). 83 | 84 | ## [2.14.0] - 2021-02-14 85 | ### Added 86 | - The `scrollbarStyle` option to change the style of the scrollbar (Thanks to [@danice], [#250]). 87 | 88 | ### Fixed 89 | - Issues with images not displaying correctly in the preview screen (Thanks to [@ivictbor], [#253]). 90 | - An error when both `sideBySideFullscreen` and `status` were set to `false` (Thanks to [@joahim], [#272]). 91 | - Editor trying to display non-image files (Thanks to [@Juupaa], [#277]) 92 | - Unneeded call to `window.removeEventListener` (Thanks to [@emirotin], [#280]) 93 | - Spell checker (Thanks to [@Fanvadar], [#284]). 94 | - Focus issues with toolbar dropdown menus (Thanks to [@Situphen], [#285]). 95 | - Interaction between the `sideBySideFullscreen` and the preview state (Thanks to [@smundro], [#286]) 96 | - Refactored strange method of padding the toolbar into regular padding (Thanks to [@sn3p], [#293]). 97 | - Security issue in `marked` dependency (Thanks to [@dependabot], [#298]). 98 | 99 | ## [2.13.0] - 2020-11-11 100 | ### Added 101 | - CodeMirror autorefresh plugin and autoRefresh option (Thanks to [@mbolli], [#249]). 102 | - `lineNumbers` option to display line numbers in the editor (Thanks to [@nhymxu], [#267]). 103 | 104 | ### Fixed 105 | - CSS scoping issues when the editor is used in combination with other CodeMirror instances ([#252]). 106 | 107 | ## [2.12.1] - 2020-10-06 108 | ### Changed 109 | - Set `previewImagesInEditor` option to `false` by default ([#251]). 110 | 111 | ## [2.12.0] - 2020-09-29 112 | ### Added 113 | - `this` context in imageUploadFunction (Thanks to [@JoshuaLicense], [#225]). 114 | - `previewImagesInEditor` option to display images in editor mode (Thanks to [@ivictbor], [#235]). 115 | - `overlayMode` options to supply an additional codemirror mode (Thanks to [@czynskee], [#244]). 116 | 117 | ### Fixed 118 | - Corrected default size units from `b,Kb,Mb` to ` B, KB, MB` ([#239]). 119 | - Max height less than min height (Thanks to [@nick-denry], [#222]). 120 | - toTextArea issue (Thanks to [@nick-denry], [#223]). 121 | - Error when updateStatusBar was called during image upload, but the status bar is disabled (Thanks to [@JoshuaLicense], [#224]). 122 | 123 | ## [2.11.0] - 2020-07-16 124 | ### Added 125 | - Support for Node.js 14. 126 | - Preview without fullscreen (Thanks to [@nick-denry], [#196]). 127 | 128 | ### Fixed 129 | - Fix cursor displayed position on activity (Thanks to [@firm1], [#184]). 130 | - Checkboxes always have bullets in front of them ([#136]). 131 | - Save the text only when modifying the content of the easymde instance (Thanks to [@firm1], [#181]). 132 | 133 | ## [2.10.1] - 2020-04-06 134 | ### Fixed 135 | - Typescript error when entering certain strings for toolbar buttons ([#178]). 136 | 137 | ## [2.10.0] - 2020-04-02 138 | ### Added 139 | - `inputStyle` and `nativeSpellcheck` options to manage the native language of the browser (Thanks to [@firm1], [#143]). 140 | - Group buttons in drop-down lists by adding a sub-option `children` for the items in the toolbar (Thanks to [@firm1], [#141]). 141 | - `sanitizerFunction` option to allow custom HTML sanitizing in the markdown preview (Thanks to [@adamb70], [#147]). 142 | - Time formatting and custom text options for the autosave message (Thanks to [@dima-bzz], [#170]). 143 | 144 | ### Changed 145 | - Delay before assuming that submit of the form as failed is `autosave.submit_delay` instead of `autosave.delay` (Thanks to [@Situphen], [#139]). 146 | - Add `watch` task for gulp (Thanks to [@A-312], [#150]). 147 | 148 | ### Fixed 149 | - Issue with Marked when using IE11 and webpack (Thanks to [@felipefdl], [#169]). 150 | - Updated codemirror to version 5.52.2 (Thanks to [@A-312], [#173]). 151 | - Editor displaying on top of other elements on a webpage (Thanks to [@StefKors], [#175]). 152 | 153 | ## [2.9.0] - 2020-01-13 154 | ### Added 155 | - Missing minHeight option in type definition (Thanks to [@t49tran], [#123]). 156 | - Other missing type definitions ([#126]). 157 | 158 | ### Changed 159 | - The editor will remove its saved contents when the editor is emptied, allowing to reload a default value (Thanks to [@Situphen], [#132]). 160 | 161 | ## [2.8.0] - 2019-08-20 162 | ### Added 163 | - Upload images functionality (Thanks to [@roipoussiere] and [@JeroenvO], [#71], [#101]). 164 | - Allow custom image upload function (Thanks to [@sperezp], [#106]). 165 | - More polish to the upload images functionality (Thanks to [@jfly], [#109]). 166 | - Improved React compatibility (Thanks to [@richtera], [#97]). 167 | 168 | ### Fixed 169 | - Missing link in dist file header. 170 | 171 | ## [2.7.0] - 2019-07-13 172 | ### Added 173 | - `previewClass` option for overwriting the preview screen class ([#99]). 174 | 175 | ### Fixed 176 | - Updated dependencies to resolve potential security issue. 177 | - Resolved small code style issues shown by new eslint rules. 178 | 179 | ## [2.6.1] - 2019-06-17 180 | ### Fixed 181 | - Error when toggling between ordered and unordered lists (Thanks to [@roryok], [#93]). 182 | - Keyboard shortcuts for custom actions not working (Thanks to [@ysykzheng], [#75]). 183 | 184 | ## [2.6.0] - 2019-04-15 185 | ### Added 186 | - Contributing guide (Thanks to [@roipoussiere], [#54]). 187 | - Issue templates. 188 | - Standardized changelog file. 189 | 190 | ### Changed 191 | - Finish rewrite of README (Thanks to [@roipoussiere], [#54]). 192 | - Image and link prompt fill with "https://" by default. 193 | - Link to markdown guide to . 194 | 195 | ### Fixed 196 | - Backwards compatibility in the API with SimpleMDE 1.0.0 ([#41]). 197 | - Automatic publish of master branch to `@next` 198 | 199 | ### Removed 200 | - Distribution files from source-control. 201 | 202 | ## [2.5.1] - 2019-01-17 203 | ### Fixed 204 | - `role="button"` needed to be `type="button"` ([#45]). 205 | 206 | ## [2.5.0] - 2019-01-17 207 | ### Added 208 | - Typescript support (Thanks to [@FranklinWhale], [#44]). 209 | - `role="button"` to toolbar buttons ([#38]). 210 | 211 | ### Fixed 212 | - Eraser icon not working with FontAwesome 5. 213 | 214 | ## [2.4.2] - 2018-11-09 215 | ### Added 216 | - Node.js 11 support. 217 | 218 | ### Fixed 219 | - Header button icons not showing sub-icons with FontAwesome 5. 220 | - Inconsistent autosave behaviour when submitting a form (Thanks to [@Furgas] and [@adamb70], [#31]). 221 | 222 | ## [2.4.1] - 2018-10-15 223 | ### Added 224 | - `fa-redo` class to redo button for FA5 compatibility (Thanks to [@Summon528], [#27]). 225 | 226 | ## [2.4.0] - 2018-10-15 227 | ### Added 228 | - Theming support (Thanks to [@LeviticusMB], [#17]). 229 | - onToggleFullscreen event hook (Thanks to [@n-3-0], [#16]). 230 | 231 | ### Fixed 232 | - Fullscreen not working with `toolbar: false` (Thanks to [@aphitiel], [#19]). 233 | 234 | ## [2.2.2] - 2019-07-03 235 | ### Fixed 236 | - Automatic publish only publishing tags. 237 | 238 | ## [2.2.1] - 2019-06-29 239 | ### Changed 240 | - Attempt automatic publish `@next` version on npm. 241 | - Links in the preview window will open in a new tab by default. 242 | 243 | ### Fixed 244 | - Multi-text select issue by disabling multi-select in the editor ([#10]). 245 | - `main` file in package.json (Thanks to [@sne11ius], [#11]). 246 | 247 | ## [2.0.1] - 2018-05-13 248 | ### Changed 249 | - Rewrote part of the documentation for EasyMDE. 250 | - Updated gulp to version 4.0.0. 251 | 252 | ### Fixed 253 | - Icons for `heading-smaller`, `heading-bigger`, `heading-1`, `heading-2` and `heading-3` not showing ([#9]). 254 | 255 | ## [2.0.0] - 2018-04-23 256 | Project forked from [SimpleMDE](https://github.com/sparksuite/simplemde-markdown-editor) 257 | 258 | ### BREAKING CHANGES 259 | - Dropped Bower support. 260 | - Dropped support for older Node.js versions. 261 | 262 | ### Added 263 | - FontAwesome 5 support. 264 | - Support for newer Node.js versions. 265 | 266 | ### Changed 267 | - Packages are now version-locked. 268 | - Simplified build script. 269 | - Markdown guide button is no longer disabled in preview mode. 270 | 271 | ### Fixed 272 | - Cursor not always showing in "text" mode over the edit field 273 | 274 | 275 | [#611]: https://github.com/Ionaru/easy-markdown-editor/issues/611 276 | [#514]: https://github.com/Ionaru/easy-markdown-editor/issues/514 277 | [#493]: https://github.com/Ionaru/easy-markdown-editor/issues/493 278 | [#478]: https://github.com/Ionaru/easy-markdown-editor/issues/478 279 | [#399]: https://github.com/Ionaru/easy-markdown-editor/issues/399 280 | [#252]: https://github.com/Ionaru/easy-markdown-editor/issues/252 281 | [#251]: https://github.com/Ionaru/easy-markdown-editor/issues/251 282 | [#239]: https://github.com/Ionaru/easy-markdown-editor/issues/239 283 | [#178]: https://github.com/Ionaru/easy-markdown-editor/issues/178 284 | [#136]: https://github.com/Ionaru/easy-markdown-editor/issues/136 285 | [#126]: https://github.com/Ionaru/easy-markdown-editor/issues/126 286 | [#99]: https://github.com/Ionaru/easy-markdown-editor/issues/99 287 | [#45]: https://github.com/Ionaru/easy-markdown-editor/issues/45 288 | [#44]: https://github.com/Ionaru/easy-markdown-editor/issues/44 289 | [#41]: https://github.com/Ionaru/easy-markdown-editor/issues/41 290 | [#38]: https://github.com/Ionaru/easy-markdown-editor/issues/38 291 | [#17]: https://github.com/Ionaru/easy-markdown-editor/issues/17 292 | [#16]: https://github.com/Ionaru/easy-markdown-editor/issues/16 293 | [#11]: https://github.com/Ionaru/easy-markdown-editor/issues/11 294 | [#10]: https://github.com/Ionaru/easy-markdown-editor/issues/10 295 | [#9]: https://github.com/Ionaru/easy-markdown-editor/issues/9 296 | 297 | 298 | [#608]: https://github.com/Ionaru/easy-markdown-editor/pull/608 299 | [#592]: https://github.com/Ionaru/easy-markdown-editor/pull/592 300 | [#591]: https://github.com/Ionaru/easy-markdown-editor/pull/591 301 | [#573]: https://github.com/Ionaru/easy-markdown-editor/pull/573 302 | [#520]: https://github.com/Ionaru/easy-markdown-editor/pull/520 303 | [#519]: https://github.com/Ionaru/easy-markdown-editor/pull/519 304 | [#492]: https://github.com/Ionaru/easy-markdown-editor/pull/492 305 | [#488]: https://github.com/Ionaru/easy-markdown-editor/pull/488 306 | [#486]: https://github.com/Ionaru/easy-markdown-editor/pull/486 307 | [#484]: https://github.com/Ionaru/easy-markdown-editor/pull/484 308 | [#479]: https://github.com/Ionaru/easy-markdown-editor/pull/479 309 | [#471]: https://github.com/Ionaru/easy-markdown-editor/pull/471 310 | [#467]: https://github.com/Ionaru/easy-markdown-editor/pull/467 311 | [#466]: https://github.com/Ionaru/easy-markdown-editor/pull/466 312 | [#464]: https://github.com/Ionaru/easy-markdown-editor/pull/464 313 | [#463]: https://github.com/Ionaru/easy-markdown-editor/pull/463 314 | [#461]: https://github.com/Ionaru/easy-markdown-editor/pull/461 315 | [#459]: https://github.com/Ionaru/easy-markdown-editor/pull/459 316 | [#458]: https://github.com/Ionaru/easy-markdown-editor/pull/458 317 | [#455]: https://github.com/Ionaru/easy-markdown-editor/pull/455 318 | [#454]: https://github.com/Ionaru/easy-markdown-editor/pull/454 319 | [#452]: https://github.com/Ionaru/easy-markdown-editor/pull/452 320 | [#451]: https://github.com/Ionaru/easy-markdown-editor/pull/451 321 | [#450]: https://github.com/Ionaru/easy-markdown-editor/pull/450 322 | [#449]: https://github.com/Ionaru/easy-markdown-editor/pull/449 323 | [#444]: https://github.com/Ionaru/easy-markdown-editor/pull/444 324 | [#440]: https://github.com/Ionaru/easy-markdown-editor/pull/440 325 | [#438]: https://github.com/Ionaru/easy-markdown-editor/pull/438 326 | [#436]: https://github.com/Ionaru/easy-markdown-editor/pull/436 327 | [#417]: https://github.com/Ionaru/easy-markdown-editor/pull/417 328 | [#411]: https://github.com/Ionaru/easy-markdown-editor/pull/411 329 | [#394]: https://github.com/Ionaru/easy-markdown-editor/pull/394 330 | [#393]: https://github.com/Ionaru/easy-markdown-editor/pull/393 331 | [#389]: https://github.com/Ionaru/easy-markdown-editor/pull/389 332 | [#388]: https://github.com/Ionaru/easy-markdown-editor/pull/388 333 | [#384]: https://github.com/Ionaru/easy-markdown-editor/pull/384 334 | [#364]: https://github.com/Ionaru/easy-markdown-editor/pull/364 335 | [#358]: https://github.com/Ionaru/easy-markdown-editor/pull/358 336 | [#357]: https://github.com/Ionaru/easy-markdown-editor/pull/357 337 | [#322]: https://github.com/Ionaru/easy-markdown-editor/pull/322 338 | [#316]: https://github.com/Ionaru/easy-markdown-editor/pull/316 339 | [#313]: https://github.com/Ionaru/easy-markdown-editor/pull/313 340 | [#311]: https://github.com/Ionaru/easy-markdown-editor/pull/311 341 | [#308]: https://github.com/Ionaru/easy-markdown-editor/pull/308 342 | [#298]: https://github.com/Ionaru/easy-markdown-editor/pull/298 343 | [#293]: https://github.com/Ionaru/easy-markdown-editor/pull/293 344 | [#286]: https://github.com/Ionaru/easy-markdown-editor/pull/286 345 | [#285]: https://github.com/Ionaru/easy-markdown-editor/pull/285 346 | [#284]: https://github.com/Ionaru/easy-markdown-editor/pull/284 347 | [#280]: https://github.com/Ionaru/easy-markdown-editor/pull/280 348 | [#277]: https://github.com/Ionaru/easy-markdown-editor/pull/277 349 | [#272]: https://github.com/Ionaru/easy-markdown-editor/pull/272 350 | [#267]: https://github.com/Ionaru/easy-markdown-editor/pull/267 351 | [#253]: https://github.com/Ionaru/easy-markdown-editor/pull/253 352 | [#250]: https://github.com/Ionaru/easy-markdown-editor/pull/250 353 | [#249]: https://github.com/Ionaru/easy-markdown-editor/pull/249 354 | [#244]: https://github.com/Ionaru/easy-markdown-editor/pull/244 355 | [#235]: https://github.com/Ionaru/easy-markdown-editor/pull/235 356 | [#225]: https://github.com/Ionaru/easy-markdown-editor/pull/225 357 | [#224]: https://github.com/Ionaru/easy-markdown-editor/pull/224 358 | [#223]: https://github.com/Ionaru/easy-markdown-editor/pull/223 359 | [#222]: https://github.com/Ionaru/easy-markdown-editor/pull/222 360 | [#196]: https://github.com/Ionaru/easy-markdown-editor/pull/196 361 | [#184]: https://github.com/Ionaru/easy-markdown-editor/pull/184 362 | [#181]: https://github.com/Ionaru/easy-markdown-editor/pull/181 363 | [#175]: https://github.com/Ionaru/easy-markdown-editor/pull/175 364 | [#173]: https://github.com/Ionaru/easy-markdown-editor/pull/173 365 | [#170]: https://github.com/Ionaru/easy-markdown-editor/pull/170 366 | [#169]: https://github.com/Ionaru/easy-markdown-editor/pull/169 367 | [#150]: https://github.com/Ionaru/easy-markdown-editor/pull/150 368 | [#147]: https://github.com/Ionaru/easy-markdown-editor/pull/147 369 | [#143]: https://github.com/Ionaru/easy-markdown-editor/pull/143 370 | [#141]: https://github.com/Ionaru/easy-markdown-editor/pull/141 371 | [#139]: https://github.com/Ionaru/easy-markdown-editor/pull/139 372 | [#132]: https://github.com/Ionaru/easy-markdown-editor/pull/132 373 | [#123]: https://github.com/Ionaru/easy-markdown-editor/pull/123 374 | [#109]: https://github.com/Ionaru/easy-markdown-editor/pull/109 375 | [#106]: https://github.com/Ionaru/easy-markdown-editor/pull/106 376 | [#101]: https://github.com/Ionaru/easy-markdown-editor/pull/101 377 | [#97]: https://github.com/Ionaru/easy-markdown-editor/pull/97 378 | [#95]: https://github.com/Ionaru/easy-markdown-editor/pull/95 379 | [#93]: https://github.com/Ionaru/easy-markdown-editor/pull/93 380 | [#75]: https://github.com/Ionaru/easy-markdown-editor/pull/75 381 | [#71]: https://github.com/Ionaru/easy-markdown-editor/pull/71 382 | [#54]: https://github.com/Ionaru/easy-markdown-editor/pull/54 383 | [#31]: https://github.com/Ionaru/easy-markdown-editor/pull/31 384 | [#27]: https://github.com/Ionaru/easy-markdown-editor/pull/27 385 | [#19]: https://github.com/Ionaru/easy-markdown-editor/pull/19 386 | 387 | 388 | [@dependabot]: https://github.com/dependabot 389 | [@wwsalmon]: https://github.com/wwsalmon 390 | [@ChronosMasterOfAllTime]: https://github.com/ChronosMasterOfAllTime 391 | [@deerboy]: https://github.com/deerboy 392 | [@marekdedic]: https://github.com/marekdedic 393 | [@emirotin]: https://github.com/emirotin 394 | [@smundro]: https://github.com/smundro 395 | [@Juupaa]: https://github.com/Juupaa 396 | [@Fanvadar]: https://github.com/Fanvadar 397 | [@danice]: https://github.com/danice 398 | [@joahim]: https://github.com/joahim 399 | [@nhymxu]: https://github.com/nhymxu 400 | [@mbolli]: https://github.com/mbolli 401 | [@ivictbor]: https://github.com/ivictbor 402 | [@JoshuaLicense]: https://github.com/JoshuaLicense 403 | [@czynskee]: https://github.com/czynskee 404 | [@nick-denry]: https://github.com/nick-denry 405 | [@StefKors]: https://github.com/StefKors 406 | [@felipefdl]: https://github.com/felipefdl 407 | [@A-312]: https://github.com/A-312 408 | [@dima-bzz]: https://github.com/dima-bzz 409 | [@firm1]: https://github.com/firm1 410 | [@Situphen]: https://github.com/Situphen 411 | [@t49tran]: https://github.com/t49tran 412 | [@richtera]: https://github.com/richtera 413 | [@jfly]: https://github.com/jfly 414 | [@sperezp]: https://github.com/sperezp 415 | [@JeroenvO]: https://github.com/JeroenvO 416 | [@sn3p]: https://github.com/sn3p 417 | [@roryok]: https://github.com/roryok 418 | [@ysykzheng]: https://github.com/ysykzheng 419 | [@roipoussiere]: https://github.com/roipoussiere 420 | [@FranklinWhale]: https://github.com/FranklinWhale 421 | [@Furgas]: https://github.com/Furgas 422 | [@adamb70]: https://github.com/adamb70 423 | [@Summon528]: https://github.com/Summon528 424 | [@LeviticusMB]: https://github.com/LeviticusMB 425 | [@n-3-0]: https://github.com/n-3-0 426 | [@aphitiel]: https://github.com/aphitiel 427 | [@sne11ius]: https://github.com/sne11ius 428 | [@souljuse]: https://github.com/souljuse 429 | [@ukjinjang]: https://github.com/ukjinjang 430 | [@robjean9]: https://github.com/robjean9 431 | [@Offerel]: https://github.com/Offerel 432 | [@Zignature]: https://github.com/Zignature 433 | [@kelvinj]: https://github.com/kelvinj 434 | [@diego-gw]: https://github.com/diego-gw 435 | [@danielok1993]: https://github.com/danielok1993 436 | [@vanillajonathan]: https://github.com/vanillajonathan 437 | [@LevitatingOrange]: https://github.com/LevitatingOrange 438 | [@LoyalPotato]: https://github.com/LoyalPotato 439 | [@kicksent]: https://github.com/kicksent 440 | [@hlf20010508]: https://github.com/hlf20010508 441 | [@ZsgsDesign]: https://github.com/ZsgsDesign 442 | [@sghoweri]: https://github.com/sghoweri 443 | [@borodean]: https://github.com/borodean 444 | [@robinvandernoord]: https://github.com/robinvandernoord 445 | [@p1gp1g]: https://github.com/p1gp1g 446 | [@mayraamaral]: https://github.com/mayraamaral 447 | [@codingjoe]: https://github.com/codingjoe 448 | 449 | 450 | [Unreleased]: https://github.com/Ionaru/easy-markdown-editor/compare/2.20.0...HEAD 451 | [2.20.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.19.0...2.20.0 452 | [2.19.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.18.0...2.19.0 453 | [2.18.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.17.0...2.18.0 454 | [2.17.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.16.1...2.17.0 455 | [2.16.1]: https://github.com/Ionaru/easy-markdown-editor/compare/2.16.0...2.16.1 456 | [2.16.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.15.0...2.16.0 457 | [2.15.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.14.0...2.15.0 458 | [2.14.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.13.0...2.14.0 459 | [2.13.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.12.1...2.13.0 460 | [2.12.1]: https://github.com/Ionaru/easy-markdown-editor/compare/2.12.0...2.12.1 461 | [2.12.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.11.0...2.12.0 462 | [2.11.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.10.1...2.11.0 463 | [2.10.1]: https://github.com/Ionaru/easy-markdown-editor/compare/2.10.0...2.10.1 464 | [2.10.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.9.0...2.10.0 465 | [2.9.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.8.0...2.9.0 466 | [2.8.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.7.0...2.8.0 467 | [2.7.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.6.1...2.7.0 468 | [2.6.1]: https://github.com/Ionaru/easy-markdown-editor/compare/2.6.0...2.6.1 469 | [2.6.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.5.1...2.6.0 470 | [2.5.1]: https://github.com/Ionaru/easy-markdown-editor/compare/2.5.0...2.5.1 471 | [2.5.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.4.2...2.5.0 472 | [2.4.2]: https://github.com/Ionaru/easy-markdown-editor/compare/2.4.1...2.4.2 473 | [2.4.1]: https://github.com/Ionaru/easy-markdown-editor/compare/2.4.0...2.4.1 474 | [2.4.0]: https://github.com/Ionaru/easy-markdown-editor/compare/2.2.2...2.4.0 475 | [2.2.2]: https://github.com/Ionaru/easy-markdown-editor/compare/2.2.1...2.2.2 476 | [2.2.1]: https://github.com/Ionaru/easy-markdown-editor/compare/2.0.1...2.2.1 477 | [2.0.1]: https://github.com/Ionaru/easy-markdown-editor/compare/2.0.0...2.0.1 478 | [2.0.0]: https://github.com/Ionaru/easy-markdown-editor/compare/1.11.2...2.0.0 479 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasyMDE - Markdown Editor 2 | 3 | [![npm version](https://img.shields.io/npm/v/easymde.svg?style=for-the-badge)](https://www.npmjs.com/package/easymde) 4 | [![npm @next version](https://img.shields.io/npm/v/easymde/next.svg?style=for-the-badge)](https://www.npmjs.com/package/easymde/v/next) 5 | [![npm @v3-alpha version](https://img.shields.io/npm/v/easymde/v3-alpha.svg?style=for-the-badge)](https://www.npmjs.com/package/easymde/v/v3-alpha) 6 | [![Build Status](https://img.shields.io/github/actions/workflow/status/ionaru/easy-markdown-editor/cd.yaml?branch=master&style=for-the-badge)](https://github.com/Ionaru/easy-markdown-editor/actions?query=branch%3Amaster) 7 | 8 | > This repository is a fork of 9 | [SimpleMDE, made by Sparksuite](https://github.com/sparksuite/simplemde-markdown-editor/). 10 | Go to the [dedicated section](#simplemde-fork) for more information. 11 | 12 | A drop-in JavaScript text area replacement for writing beautiful and understandable Markdown. 13 | EasyMDE allows users who may be less experienced with Markdown to use familiar toolbar buttons and shortcuts. 14 | 15 | 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. 16 | 17 | EasyMDE also features both built-in auto saving and spell checking. 18 | The editor is entirely customizable, from theming to toolbar buttons and javascript hooks. 19 | 20 | [**Try the demo**](https://stackblitz.com/edit/easymde/) 21 | 22 | [![Preview](https://user-images.githubusercontent.com/3472373/51319377-26fe6e00-1a5d-11e9-8cc6-3137a566796d.png)](https://stackblitz.com/edit/easymde/) 23 | 24 | 25 | ## Quick access 26 | 27 | - [EasyMDE - Markdown Editor](#easymde---markdown-editor) 28 | - [Quick access](#quick-access) 29 | - [Install EasyMDE](#install-easymde) 30 | - [How to use](#how-to-use) 31 | - [Loading the editor](#loading-the-editor) 32 | - [Editor functions](#editor-functions) 33 | - [Configuration](#configuration) 34 | - [Options list](#options-list) 35 | - [Options example](#options-example) 36 | - [Toolbar icons](#toolbar-icons) 37 | - [Toolbar customization](#toolbar-customization) 38 | - [Keyboard shortcuts](#keyboard-shortcuts) 39 | - [Advanced use](#advanced-use) 40 | - [Event handling](#event-handling) 41 | - [Removing EasyMDE from text area](#removing-easymde-from-text-area) 42 | - [Useful methods](#useful-methods) 43 | - [How it works](#how-it-works) 44 | - [SimpleMDE fork](#simplemde-fork) 45 | - [Hacking EasyMDE](#hacking-easymde) 46 | - [Contributing](#contributing) 47 | - [License](#license) 48 | 49 | 50 | ## Install EasyMDE 51 | 52 | Via [npm](https://www.npmjs.com/package/easymde): 53 | 54 | ``` 55 | npm install easymde 56 | ``` 57 | 58 | Via the *UNPKG* CDN: 59 | 60 | ```html 61 | 62 | 63 | ``` 64 | 65 | Or *jsDelivr*: 66 | ```html 67 | 68 | 69 | ``` 70 | 71 | ## How to use 72 | 73 | ### Loading the editor 74 | 75 | After installing and/or importing the module, you can load EasyMDE onto the first `textarea` element on the web page: 76 | 77 | ```html 78 | 79 | 82 | ``` 83 | 84 | Alternatively you can select a specific `textarea`, via JavaScript: 85 | 86 | ```html 87 | 88 | 91 | ``` 92 | 93 | ### Editor functions 94 | 95 | Use `easyMDE.value()` to get the content of the editor: 96 | 97 | ```html 98 | 101 | ``` 102 | 103 | Use `easyMDE.value(val)` to set the content of the editor: 104 | 105 | ```html 106 | 109 | ``` 110 | 111 | 112 | ## Configuration 113 | 114 | ### Options list 115 | 116 | - **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. 117 | - **autofocus**: If set to `true`, focuses the editor automatically. Defaults to `false`. 118 | - **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.* 119 | - **enabled**: If set to `true`, saves the text automatically. Defaults to `false`. 120 | - **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10 seconds). 121 | - **submit_delay**: Delay before assuming that submit of the form failed and saving the text, in milliseconds. Defaults to `autosave.delay` or `10000` (10 seconds). 122 | - **uniqueId**: You must set a unique string identifier so that EasyMDE can autosave. Something that separates this from other instances of EasyMDE elsewhere on your website. 123 | - **timeFormat**: Set DateTimeFormat. More information see [DateTimeFormat instances](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat). Default `locale: en-US, format: hour:minute`. 124 | - **text**: Set text for autosave. 125 | - **autoRefresh**: Useful, when initializing the editor in a hidden DOM node. If set to `{ delay: 300 }`, it will check every 300 ms if the editor is visible and if positive, call CodeMirror's [`refresh()`](https://codemirror.net/doc/manual.html#refresh). 126 | - **blockStyles**: Customize how certain buttons that style blocks of text behave. 127 | - **bold**: Can be set to `**` or `__`. Defaults to `**`. 128 | - **code**: Can be set to ```` ``` ```` or `~~~`. Defaults to ```` ``` ````. 129 | - **italic**: Can be set to `*` or `_`. Defaults to `*`. 130 | - **unorderedListStyle**: can be `*`, `-` or `+`. Defaults to `*`. 131 | - **scrollbarStyle**: Chooses a scrollbar implementation. The default is "native", showing native scrollbars. The core library also provides the "null" style, which completely hides the scrollbars. Addons can implement additional scrollbar models. 132 | - **element**: The DOM element for the `textarea` element to use. Defaults to the first `textarea` element on the page. 133 | - **forceSync**: If set to `true`, force text changes made in EasyMDE to be immediately stored in original text area. Defaults to `false`. 134 | - **hideIcons**: An array of icon names to hide. Can be used to hide specific icons shown by default without completely customizing the toolbar. 135 | - **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`. 136 | - **initialValue**: If set, will customize the initial value of the editor. 137 | - **previewImagesInEditor**: - EasyMDE will show preview of images, `false` by default, preview for images will appear only for images on separate lines. 138 | - **imagesPreviewHandler**: - A custom function for handling the preview of images. Takes the parsed string between the parantheses of the image markdown `![]( )` as argument and returns a string that serves as the `src` attribute of the `` tag in the preview. Enables dynamic previewing of images in the frontend without having to upload them to a server, allows copy-pasting of images to the editor with preview. 139 | - **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://)"]`. 140 | - horizontalRule 141 | - image 142 | - link 143 | - table 144 | - **lineNumbers**: If set to `true`, enables line numbers in the editor. 145 | - **lineWrapping**: If set to `false`, disable line wrapping. Defaults to `true`. 146 | - **minHeight**: Sets the minimum height for the composition area, before it starts auto-growing. Should be a string containing a valid CSS value like `"500px"`. Defaults to `"300px"`. 147 | - **maxHeight**: Sets fixed height for the composition area. `minHeight` option will be ignored. Should be a string containing a valid CSS value like `"500px"`. Defaults to `undefined`. 148 | - **onToggleFullScreen**: A function that gets called when the editor's full screen mode is toggled. The function will be passed a boolean as parameter, `true` when the editor is currently going into full screen mode, or `false`. 149 | - **parsingConfig**: Adjust settings for parsing the Markdown during editing (not previewing). 150 | - **allowAtxHeaderWithoutSpace**: If set to `true`, will render headers without a space after the `#`. Defaults to `false`. 151 | - **strikethrough**: If set to `false`, will not process GFM strikethrough syntax. Defaults to `true`. 152 | - **underscoresBreakWords**: If set to `true`, let underscores be a delimiter for separating words. Defaults to `false`. 153 | - **overlayMode**: Pass a custom codemirror [overlay mode](https://codemirror.net/doc/manual.html#modeapi) to parse and style the Markdown during editing. 154 | - **mode**: A codemirror mode object. 155 | - **combine**: If set to `false`, will *replace* CSS classes returned by the default Markdown mode. Otherwise the classes returned by the custom mode will be combined with the classes returned by the default mode. Defaults to `true`. 156 | - **placeholder**: If set, displays a custom placeholder message. 157 | - **previewClass**: A string or array of strings that will be applied to the preview screen when activated. Defaults to `"editor-preview"`. 158 | - **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews. 159 | - **promptURLs**: If set to `true`, a JS alert window appears asking for the link or image URL. Defaults to `false`. 160 | - **promptTexts**: Customize the text used to prompt for URLs. 161 | - **image**: The text to use when prompting for an image's URL. Defaults to `URL of the image:`. 162 | - **link**: The text to use when prompting for a link's URL. Defaults to `URL for the link:`. 163 | - **iconClassMap**: Used to specify the icon class names for the various toolbar buttons. 164 | - **uploadImage**: If set to `true`, enables the image upload functionality, which can be triggered by drag and drop, copy-paste and through the browse-file window (opened when the user click on the *upload-image* icon). Defaults to `false`. 165 | - **imageMaxSize**: Maximum image size in bytes, checked before upload (note: never trust client, always check the image size at server-side). Defaults to `1024 * 1024 * 2` (2 MB). 166 | - **imageAccept**: A comma-separated list of mime-types used to check image type before upload (note: never trust client, always check file types at server-side). Defaults to `image/png, image/jpeg`. 167 | - **imageUploadFunction**: A custom function for handling the image upload. Using this function will render the options `imageMaxSize`, `imageAccept`, `imageUploadEndpoint` and `imageCSRFToken` ineffective. 168 | - The function gets a file and `onSuccess` and `onError` callback functions as parameters. `onSuccess(imageUrl: string)` and `onError(errorMessage: string)` 169 | - **imageUploadEndpoint**: The endpoint where the images data will be sent, via an asynchronous *POST* request. The server is supposed to save this image, and return a JSON response. 170 | - if the request was successfully processed (HTTP 200 OK): `{"data": {"filePath": ""}}` where *filePath* is the path of the image (absolute if `imagePathAbsolute` is set to true, relative if otherwise); 171 | - otherwise: `{"error": ""}`, where *errorCode* can be `noFileGiven` (HTTP 400 Bad Request), `typeNotAllowed` (HTTP 415 Unsupported Media Type), `fileTooLarge` (HTTP 413 Payload Too Large) or `importError` (see *errorMessages* below). If *errorCode* is not one of the *errorMessages*, it is alerted unchanged to the user. This allows for server-side error messages. 172 | No default value. 173 | - **imagePathAbsolute**: If set to `true`, will treat `imageUrl` from `imageUploadFunction` and *filePath* returned from `imageUploadEndpoint` as an absolute rather than relative path, i.e. not prepend `window.location.origin` to it. 174 | - **imageCSRFToken**: CSRF token to include with AJAX call to upload image. For various instances like Django, Spring and Laravel. 175 | - **imageCSRFName**: CSRF token filed name to include with AJAX call to upload image, applied when `imageCSRFToken` has value, defaults to `csrfmiddlewaretoken`. 176 | - **imageCSRFHeader**: If set to `true`, passing CSRF token via header. Defaults to `false`, which pass CSRF through request body. 177 | - **imageTexts**: Texts displayed to the user (mainly on the status bar) for the import image feature, where `#image_name#`, `#image_size#` and `#image_max_size#` will replaced by their respective values, that can be used for customization or internationalization: 178 | - **sbInit**: Status message displayed initially if `uploadImage` is set to `true`. Defaults to `Attach files by drag and dropping or pasting from clipboard.`. 179 | - **sbOnDragEnter**: Status message displayed when the user drags a file to the text area. Defaults to `Drop image to upload it.`. 180 | - **sbOnDrop**: Status message displayed when the user drops a file in the text area. Defaults to `Uploading images #images_names#`. 181 | - **sbProgress**: Status message displayed to show uploading progress. Defaults to `Uploading #file_name#: #progress#%`. 182 | - **sbOnUploaded**: Status message displayed when the image has been uploaded. Defaults to `Uploaded #image_name#`. 183 | - **sizeUnits**: A comma-separated list of units used to display messages with human-readable file sizes. Defaults to ` B, KB, MB` (example: `218 KB`). You can use `B,KB,MB` instead if you prefer without whitespaces (`218KB`). 184 | - **errorMessages**: Errors displayed to the user, using the `errorCallback` option, where `#image_name#`, `#image_size#` and `#image_max_size#` will replaced by their respective values, that can be used for customization or internationalization: 185 | - **noFileGiven**: The server did not receive any file from the user. Defaults to `You must select a file.`. 186 | - **typeNotAllowed**: The user send a file type which doesn't match the `imageAccept` list, or the server returned this error code. Defaults to `This image type is not allowed.`. 187 | - **fileTooLarge**: The size of the image being imported is bigger than the `imageMaxSize`, or if the server returned this error code. Defaults to `Image #image_name# is too big (#image_size#).\nMaximum file size is #image_max_size#.`. 188 | - **importError**: An unexpected error occurred when uploading the image. Defaults to `Something went wrong when uploading the image #image_name#.`. 189 | - **errorCallback**: A callback function used to define how to display an error message. Defaults to `(errorMessage) => alert(errorMessage)`. 190 | - **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing). 191 | - **codeSyntaxHighlighting**: If set to `true`, will highlight using [highlight.js](https://github.com/isagalaev/highlight.js). Defaults to `false`. To use this feature you must include highlight.js on your page or pass in using the `hljs` option. For example, include the script and the CSS files like:
``
`` 192 | - **hljs**: An injectible instance of [highlight.js](https://github.com/isagalaev/highlight.js). If you don't want to rely on the global namespace (`window.hljs`), you can provide an instance here. Defaults to `undefined`. 193 | - **markedOptions**: Set the internal Markdown renderer's [options](https://marked.js.org/#/USING_ADVANCED.md#options). Other `renderingConfig` options will take precedence. 194 | - **singleLineBreaks**: If set to `false`, disable parsing [GitHub Flavored Markdown](https://github.github.com/gfm/) (GFM) single line breaks. Defaults to `true`. 195 | - **sanitizerFunction**: Custom function for sanitizing the HTML output of Markdown renderer. 196 | - **shortcuts**: Keyboard shortcuts associated with this instance. Defaults to the [array of shortcuts](#keyboard-shortcuts). 197 | - **showIcons**: An array of icon names to show. Can be used to show specific icons hidden by default without completely customizing the toolbar. 198 | - **spellChecker**: If set to `false`, disable the spell checker. Defaults to `true`. Optionally pass a CodeMirrorSpellChecker-compliant function. 199 | - **inputStyle**: `textarea` or `contenteditable`. Defaults to `textarea` for desktop and `contenteditable` for mobile. `contenteditable` option is necessary to enable nativeSpellcheck. 200 | - **nativeSpellcheck**: If set to `false`, disable native spell checker. Defaults to `true`. 201 | - **sideBySideFullscreen**: If set to `false`, allows side-by-side editing without going into fullscreen. Defaults to `true`. 202 | - **status**: If set to `false`, hide the status bar. Defaults to the array of built-in status bar items. 203 | - 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. 204 | - **styleSelectedText**: If set to `false`, remove the `CodeMirror-selectedtext` class from selected lines. Defaults to `true`. 205 | - **syncSideBySidePreviewScroll**: If set to `false`, disable syncing scroll in side by side mode. Defaults to `true`. 206 | - **tabSize**: If set, customize the tab size. Defaults to `2`. 207 | - **theme**: Override the theme. Defaults to `easymde`. 208 | - **toolbar**: If set to `false`, hide the toolbar. Defaults to the [array of icons](#toolbar-icons). 209 | - **toolbarTips**: If set to `false`, disable toolbar button tips. Defaults to `true`. 210 | - **toolbarButtonClassPrefix**: Adds a prefix to the toolbar button classes when set. For example, a value of `"mde"` results in `"mde-bold"` for the Bold button. 211 | - **direction**: `rtl` or `ltr`. Changes text direction to support right-to-left languages. Defaults to `ltr`. 212 | 213 | 214 | ### Options example 215 | 216 | Most options demonstrate the non-default behavior: 217 | 218 | ```js 219 | const editor = new EasyMDE({ 220 | autofocus: true, 221 | autosave: { 222 | enabled: true, 223 | uniqueId: "MyUniqueID", 224 | delay: 1000, 225 | submit_delay: 5000, 226 | timeFormat: { 227 | locale: 'en-US', 228 | format: { 229 | year: 'numeric', 230 | month: 'long', 231 | day: '2-digit', 232 | hour: '2-digit', 233 | minute: '2-digit', 234 | }, 235 | }, 236 | text: "Autosaved: " 237 | }, 238 | blockStyles: { 239 | bold: "__", 240 | italic: "_", 241 | }, 242 | unorderedListStyle: "-", 243 | element: document.getElementById("MyID"), 244 | forceSync: true, 245 | hideIcons: ["guide", "heading"], 246 | indentWithTabs: false, 247 | initialValue: "Hello world!", 248 | insertTexts: { 249 | horizontalRule: ["", "\n\n-----\n\n"], 250 | image: ["![](http://", ")"], 251 | link: ["[", "](https://)"], 252 | table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"], 253 | }, 254 | lineWrapping: false, 255 | minHeight: "500px", 256 | parsingConfig: { 257 | allowAtxHeaderWithoutSpace: true, 258 | strikethrough: false, 259 | underscoresBreakWords: true, 260 | }, 261 | placeholder: "Type here...", 262 | 263 | previewClass: "my-custom-styling", 264 | previewClass: ["my-custom-styling", "more-custom-styling"], 265 | 266 | previewRender: (plainText) => customMarkdownParser(plainText), // Returns HTML from a custom parser 267 | previewRender: (plainText, preview) => { // Async method 268 | setTimeout(() => { 269 | preview.innerHTML = customMarkdownParser(plainText); 270 | }, 250); 271 | 272 | // If you return null, the innerHTML of the preview will not 273 | // be overwritten. Useful if you control the preview node's content via 274 | // vdom diffing. 275 | // return null; 276 | 277 | return "Loading..."; 278 | }, 279 | promptURLs: true, 280 | promptTexts: { 281 | image: "Custom prompt for URL:", 282 | link: "Custom prompt for URL:", 283 | }, 284 | renderingConfig: { 285 | singleLineBreaks: false, 286 | codeSyntaxHighlighting: true, 287 | sanitizerFunction: (renderedHTML) => { 288 | // Using DOMPurify and only allowing tags 289 | return DOMPurify.sanitize(renderedHTML, {ALLOWED_TAGS: ['b']}) 290 | }, 291 | }, 292 | shortcuts: { 293 | drawTable: "Cmd-Alt-T" 294 | }, 295 | showIcons: ["code", "table"], 296 | spellChecker: false, 297 | status: false, 298 | status: ["autosave", "lines", "words", "cursor"], // Optional usage 299 | status: ["autosave", "lines", "words", "cursor", { 300 | className: "keystrokes", 301 | defaultValue: (el) => { 302 | el.setAttribute('data-keystrokes', 0); 303 | }, 304 | onUpdate: (el) => { 305 | const keystrokes = Number(el.getAttribute('data-keystrokes')) + 1; 306 | el.innerHTML = `${keystrokes} Keystrokes`; 307 | el.setAttribute('data-keystrokes', keystrokes); 308 | }, 309 | }], // Another optional usage, with a custom status bar item that counts keystrokes 310 | styleSelectedText: false, 311 | sideBySideFullscreen: false, 312 | syncSideBySidePreviewScroll: false, 313 | tabSize: 4, 314 | toolbar: false, 315 | toolbarTips: false, 316 | toolbarButtonClassPrefix: "mde", 317 | }); 318 | ``` 319 | 320 | 321 | ### Toolbar icons 322 | 323 | 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 JavaScript. "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 key bind 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)"). 324 | 325 | Additionally, you can add a separator between any icons by adding `"|"` to the toolbar array. 326 | 327 | Name | Action | Tooltip
Class 328 | :--- | :----- | :-------------- 329 | bold | toggleBold | Bold
fa fa-bold 330 | italic | toggleItalic | Italic
fa fa-italic 331 | strikethrough | toggleStrikethrough | Strikethrough
fa fa-strikethrough 332 | heading | toggleHeadingSmaller | Heading
fa fa-header 333 | heading-smaller | toggleHeadingSmaller | Smaller Heading
fa fa-header 334 | heading-bigger | toggleHeadingBigger | Bigger Heading
fa fa-lg fa-header 335 | heading-1 | toggleHeading1 | Big Heading
fa fa-header header-1 336 | heading-2 | toggleHeading2 | Medium Heading
fa fa-header header-2 337 | heading-3 | toggleHeading3 | Small Heading
fa fa-header header-3 338 | code | toggleCodeBlock | Code
fa fa-code 339 | quote | toggleBlockquote | Quote
fa fa-quote-left 340 | unordered-list | toggleUnorderedList | Generic List
fa fa-list-ul 341 | ordered-list | toggleOrderedList | Numbered List
fa fa-list-ol 342 | clean-block | cleanBlock | Clean block
fa fa-eraser 343 | link | drawLink | Create Link
fa fa-link 344 | image | drawImage | Insert Image
fa fa-picture-o 345 | upload-image | drawUploadedImage | Raise browse-file window
fa fa-image 346 | table | drawTable | Insert Table
fa fa-table 347 | horizontal-rule | drawHorizontalRule | Insert Horizontal Line
fa fa-minus 348 | preview | togglePreview | Toggle Preview
fa fa-eye no-disable 349 | side-by-side | toggleSideBySide | Toggle Side by Side
fa fa-columns no-disable no-mobile 350 | fullscreen | toggleFullScreen | Toggle Fullscreen
fa fa-arrows-alt no-disable no-mobile 351 | guide | [This link](https://www.markdownguide.org/basic-syntax/) | Markdown Guide
fa fa-question-circle 352 | undo | undo | Undo
fa fa-undo 353 | redo | redo | Redo
fa fa-redo 354 | 355 | 356 | ### Toolbar customization 357 | 358 | Customize the toolbar using the `toolbar` option. 359 | 360 | Only the order of existing buttons: 361 | 362 | ```js 363 | const easyMDE = new EasyMDE({ 364 | toolbar: ["bold", "italic", "heading", "|", "quote"] 365 | }); 366 | ``` 367 | 368 | All information and/or add your own icons or text 369 | 370 | ```js 371 | const easyMDE = new EasyMDE({ 372 | toolbar: [ 373 | { 374 | name: "bold", 375 | action: EasyMDE.toggleBold, 376 | className: "fa fa-bold", 377 | title: "Bold", 378 | }, 379 | "italic", // shortcut to pre-made button 380 | { 381 | name: "custom", 382 | action: (editor) => { 383 | // Add your own code 384 | }, 385 | className: "fa fa-star", 386 | text: "Starred", 387 | title: "Custom Button", 388 | attributes: { // for custom attributes 389 | id: "custom-id", 390 | "data-value": "custom value" // HTML5 data-* attributes need to be enclosed in quotation marks ("") because of the dash (-) in its name. 391 | } 392 | }, 393 | "|" // Separator 394 | // [, ...] 395 | ] 396 | }); 397 | ``` 398 | 399 | Put some buttons on dropdown menu 400 | 401 | ```js 402 | const easyMDE = new EasyMDE({ 403 | toolbar: [{ 404 | name: "heading", 405 | action: EasyMDE.toggleHeadingSmaller, 406 | className: "fa fa-header", 407 | title: "Headers", 408 | }, 409 | "|", 410 | { 411 | name: "others", 412 | className: "fa fa-blind", 413 | title: "others buttons", 414 | children: [ 415 | { 416 | name: "image", 417 | action: EasyMDE.drawImage, 418 | className: "fa fa-picture-o", 419 | title: "Image", 420 | }, 421 | { 422 | name: "quote", 423 | action: EasyMDE.toggleBlockquote, 424 | className: "fa fa-percent", 425 | title: "Quote", 426 | }, 427 | { 428 | name: "link", 429 | action: EasyMDE.drawLink, 430 | className: "fa fa-link", 431 | title: "Link", 432 | } 433 | ] 434 | }, 435 | // [, ...] 436 | ] 437 | }); 438 | ``` 439 | 440 | ### Keyboard shortcuts 441 | 442 | EasyMDE 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: 443 | 444 | Shortcut (Windows / Linux) | Shortcut (macOS) | Action 445 | :--- | :--- | :--- 446 | Ctrl-' | Cmd-' | "toggleBlockquote" 447 | Ctrl-B | Cmd-B | "toggleBold" 448 | Ctrl-E | Cmd-E | "cleanBlock" 449 | Ctrl-H | Cmd-H | "toggleHeadingSmaller" 450 | Ctrl-I | Cmd-I | "toggleItalic" 451 | Ctrl-K | Cmd-K | "drawLink" 452 | Ctrl-L | Cmd-L | "toggleUnorderedList" 453 | Ctrl-P | Cmd-P | "togglePreview" 454 | Ctrl-Alt-C | Cmd-Alt-C | "toggleCodeBlock" 455 | Ctrl-Alt-I | Cmd-Alt-I | "drawImage" 456 | Ctrl-Alt-L | Cmd-Alt-L | "toggleOrderedList" 457 | Shift-Ctrl-H | Shift-Cmd-H | "toggleHeadingBigger" 458 | F9 | F9 | "toggleSideBySide" 459 | F11 | F11 | "toggleFullScreen" 460 | Ctrl-Alt-1 | Cmd-Alt-1 | "toggleHeading1" 461 | Ctrl-Alt-2 | Cmd-Alt-2 | "toggleHeading2" 462 | Ctrl-Alt-3 | Cmd-Alt-3 | "toggleHeading3" 463 | Ctrl-Alt-4 | Cmd-Alt-4 | "toggleHeading4" 464 | Ctrl-Alt-5 | Cmd-Alt-5 | "toggleHeading5" 465 | Ctrl-Alt-6 | Cmd-Alt-6 | "toggleHeading6" 466 | 467 | Here is how you can change a few, while leaving others untouched: 468 | 469 | ```js 470 | const editor = new EasyMDE({ 471 | shortcuts: { 472 | "toggleOrderedList": "Ctrl-Alt-K", // alter the shortcut for toggleOrderedList 473 | "toggleCodeBlock": null, // unbind Ctrl-Alt-C 474 | "drawTable": "Cmd-Alt-T", // bind Cmd-Alt-T to drawTable action, which doesn't come with a default shortcut 475 | } 476 | }); 477 | ``` 478 | 479 | 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. 480 | 481 | The list of actions that can be bound is the same as the list of built-in actions available for [toolbar buttons](#toolbar-icons). 482 | 483 | 484 | ## Advanced use 485 | 486 | ### Event handling 487 | 488 | You can catch the following list of events: https://codemirror.net/doc/manual.html#events 489 | 490 | ```js 491 | const easyMDE = new EasyMDE(); 492 | easyMDE.codemirror.on("change", () => { 493 | console.log(easyMDE.value()); 494 | }); 495 | ``` 496 | 497 | 498 | ### Removing EasyMDE from text area 499 | 500 | You can revert to the initial text area by calling the `toTextArea` method. Note that this clears up the autosave (if enabled) associated with it. The text area will retain any text from the destroyed EasyMDE instance. 501 | 502 | ```js 503 | const easyMDE = new EasyMDE(); 504 | // ... 505 | easyMDE.toTextArea(); 506 | easyMDE = null; 507 | ``` 508 | 509 | If you need to remove registered event listeners (when the editor is not needed anymore), call `easyMDE.cleanup()`. 510 | 511 | 512 | ### Useful methods 513 | 514 | The following self-explanatory methods may be of use while developing with EasyMDE. 515 | 516 | ```js 517 | const easyMDE = new EasyMDE(); 518 | easyMDE.isPreviewActive(); // returns boolean 519 | easyMDE.isSideBySideActive(); // returns boolean 520 | easyMDE.isFullscreenActive(); // returns boolean 521 | easyMDE.clearAutosavedValue(); // no returned value 522 | ``` 523 | 524 | 525 | ## How it works 526 | 527 | EasyMDE is a continuation of SimpleMDE. 528 | 529 | SimpleMDE began as an improvement of [lepture's Editor project](https://github.com/lepture/editor), but has now taken on an identity of its own. It is bundled with [CodeMirror](https://github.com/codemirror/codemirror) and depends on [Font Awesome](http://fontawesome.io). 530 | 531 | 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](https://github.com/chjj/marked) using GitHub Flavored Markdown (GFM). 532 | 533 | 534 | ## SimpleMDE fork 535 | 536 | I originally made this fork to implement FontAwesome 5 compatibility into SimpleMDE. When that was done I submitted a [pull request](https://github.com/sparksuite/simplemde-markdown-editor/pull/666), which has not been accepted yet. This, and the project being inactive since May 2017, triggered me to make more changes and try to put new life into the project. 537 | 538 | Changes include: 539 | * FontAwesome 5 compatibility 540 | * Guide button works when editor is in preview mode 541 | * Links are now `https://` by default 542 | * Small styling changes 543 | * Support for Node 8 and beyond 544 | * Lots of refactored code 545 | * Links in preview will open in a new tab by default 546 | * TypeScript support 547 | 548 | My intention is to continue development on this project, improving it and keeping it alive. 549 | 550 | 551 | ## Hacking EasyMDE 552 | 553 | You may want to edit this library to adapt its behavior to your needs. This can be done in some quick steps: 554 | 555 | 1. Follow the [prerequisites](./CONTRIBUTING.md#prerequisites) and [installation](./CONTRIBUTING.md#installation) instructions in the contribution guide; 556 | 2. Do your changes; 557 | 3. Run `gulp` command, which will generate files: `dist/easymde.min.css` and `dist/easymde.min.js`; 558 | 4. Copy-paste those files to your code base, and you are done. 559 | 560 | 561 | ## Contributing 562 | 563 | Want to contribute to EasyMDE? Thank you! We have a [contribution guide](./CONTRIBUTING.md) just for you! 564 | 565 | 566 | ## License 567 | 568 | This project is released under the [MIT License](./LICENSE). 569 | 570 | - Copyright (c) 2015 Sparksuite, Inc. 571 | - Copyright (c) 2017 Jeroen Akkerman. 572 | --------------------------------------------------------------------------------