vue-simplemde

SimpleMDE Configuration

// Most options demonstrate the non-default behavior
export default {
  data () {
    return {
      configs: {
        autofocus: true,
        autosave: {
          enabled: true,
          uniqueId: 'MyUniqueID',
          delay: 1000
        },
        blockStyles: {
          bold: '__',
          italic: '_'
        },
        element: document.getElementById('MyID'),
        forceSync: true,
        hideIcons: ['guide', 'heading'],
        indentWithTabs: false,
        initialValue: 'Hello world!',
        insertTexts: {
          horizontalRule: ['', '\n\n-----\n\n'],
          image: ['![](http://', ')'],
          link: ['[', '](http://)'],
          table: ['', '\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text     | Text      | Text     |\n\n']
        },
        lineWrapping: false,
        parsingConfig: {
          allowAtxHeaderWithoutSpace: true,
          strikethrough: false,
          underscoresBreakWords: true
        },
        placeholder: 'Type here...',
        previewRender: function(plainText) {
          return customMarkdownParser(plainText) // Returns HTML from a custom parser
        },
        previewRender: function(plainText, preview) { // Async method
          setTimeout(function(){
            preview.innerHTML = customMarkdownParser(plainText)
          }, 250)

          return 'Loading...'
        },
        promptURLs: true,
        renderingConfig: {
          singleLineBreaks: false,
          codeSyntaxHighlighting: true
        },
        shortcuts: {
          drawTable: 'Cmd-Alt-T'
        },
        showIcons: ['code', 'table'],
        spellChecker: false,
        status: false,
        status: ['autosave', 'lines', 'words', 'cursor'], // Optional usage
        status: ['autosave', 'lines', 'words', 'cursor', {
          className: 'keystrokes',
          defaultValue: function(el) {
            this.keystrokes = 0
            el.innerHTML = '0 Keystrokes'
          },
          onUpdate: function(el) {
            el.innerHTML = ++this.keystrokes + ' Keystrokes'
          }
        }], // Another optional usage, with a custom status bar item that counts keystrokes
        styleSelectedText: false,
        tabSize: 4,
        toolbar: false,
        toolbarTips: false
      }
    }
  }
}

Toolbar icons

Below are the built-in toolbar icons (only some of which are enabled by default), which can be reorganized however you like. ‘Name’ is the name of the icon, referenced in the JS. ‘Action’ is either a function or a URL to open. ‘Class’ is the class given to the icon. ‘Tooltip’ is the small tooltip that appears via the title=' attribute. Note that shortcut hints are added automatically and reflect the specified action if it has a keybind assigned to it (i.e. with the value of action set to bold and that of tooltip set to Bold, the final text the user will see would be ‘Bold (Ctrl-B)’).

Additionally, you can add a separator between any icons by adding '|' to the toolbar array.

Name Action Tooltip
Class
bold toggleBold Bold
fa fa-bold
italic toggleItalic Italic
fa fa-italic
strikethrough toggleStrikethrough Strikethrough
fa fa-strikethrough
heading toggleHeadingSmaller Heading
fa fa-header
heading-smaller toggleHeadingSmaller Smaller Heading
fa fa-header
heading-bigger toggleHeadingBigger Bigger Heading
fa fa-lg fa-header
heading-1 toggleHeading1 Big Heading
fa fa-header fa-header-x fa-header-1
heading-2 toggleHeading2 Medium Heading
fa fa-header fa-header-x fa-header-2
heading-3 toggleHeading3 Small Heading
fa fa-header fa-header-x fa-header-3
code toggleCodeBlock Code
fa fa-code
quote toggleBlockquote Quote
fa fa-quote-left
unordered-list toggleUnorderedList Generic List
fa fa-list-ul
ordered-list toggleOrderedList Numbered List
fa fa-list-ol
clean-block cleanBlock Clean block
fa fa-eraser fa-clean-block
link drawLink Create Link
fa fa-link
image drawImage Insert Image
fa fa-picture-o
table drawTable Insert Table
fa fa-table
horizontal-rule drawHorizontalRule Insert Horizontal Line
fa fa-minus
preview togglePreview Toggle Preview
fa fa-eye no-disable
side-by-side toggleSideBySide Toggle Side by Side
fa fa-columns no-disable no-mobile
fullscreen toggleFullScreen Toggle Fullscreen
fa fa-arrows-alt no-disable no-mobile
guide This link Markdown Guide
fa fa-question-circle

Customize the toolbar using the toolbar option like:

// Customize only the order of existing buttons
export default {
  data () {
    return {
      configs: {
        toolbar: ['bold', 'italic', 'heading', '|', 'quote']
      }
    }
  }
}

// Customize all information and/or add your own icons
export default {
  data () {
    return {
      configs: {
        toolbar: [{
            name: 'bold',
            action: SimpleMDE.toggleBold,
            className: 'fa fa-bold',
            title: 'Bold'
          },
          {
            name: 'custom',
            action: function customFunction(editor){
              // Add your own code
            },
            className: 'fa fa-star',
            title: 'Custom Button'
          },
          '|' // Separator
          ...
        ]
      }
    }
  }
}

Keyboard shortcuts

SimpleMDE comes with an array of predefined keyboard shortcuts, but they can be altered with a configuration option. The list of default ones is as follows:

Shortcut Action
Cmd-‘ ‘toggleBlockquote’
Cmd-B ‘toggleBold’
Cmd-E ‘cleanBlock’
Cmd-H ‘toggleHeadingSmaller’
Cmd-I ‘toggleItalic’
Cmd-K ‘drawLink’
Cmd-L ‘toggleUnorderedList’
Cmd-P ‘togglePreview’
Cmd-Alt-C ‘toggleCodeBlock’
Cmd-Alt-I ‘drawImage’
Cmd-Alt-L ‘toggleOrderedList’
Shift-Cmd-H ‘toggleHeadingBigger’
F9 ‘toggleSideBySide’
F11 ‘toggleFullScreen’

Here is how you can change a few, while leaving others untouched:

export default {
  data () {
    return {
      configs: {
        shortcuts: {
          'toggleOrderedList': 'Ctrl-Alt-K', // alter the shortcut for toggleOrderedList
          'toggleCodeBlock': null, // unbind Ctrl-Alt-C
          'drawTable': 'Cmd-Alt-T' // bind Cmd-Alt-T to drawTable action, which doesn't come with a default shortcut
        }
      }
    }
  }
}

Shortcuts are automatically converted between platforms. If you define a shortcut as ‘Cmd-B’, on PC that shortcut will be changed to ‘Ctrl-B’. Conversely, a shortcut defined as ‘Ctrl-B’ will become ‘Cmd-B’ for Mac users.

The list of actions that can be bound is the same as the list of built-in actions available for toolbar buttons.

Height

To change the minimum height (before it starts auto-growing):

.markdown-editor .CodeMirror, .markdown-editor .CodeMirror-scroll {
  min-height: 200px;
}

Or, you can keep the height static:

.markdown-editor .CodeMirror {
  height: 300px;
}