SimpleMDE.JS 轻松打造一个类似简书的纯前端MarkDown语法编辑器

KittyBasil 发布于1年前
0 条问题


将个人博客 的文章语法用markdown实现。




<!DOCTYPE html>
<html lang="zh-CN">
    <meta charset="UTF-8">
    <link href="" rel="stylesheet">
<script src=""></script>
    var simplemde = new SimpleMDE();




<!DOCTYPE html>
<html lang="zh-CN">
    <meta charset="UTF-8">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
    <link href="" rel="stylesheet">
<script src=""></script>
<script src=""></script>
    var simplemde = new SimpleMDE({
        element: document.querySelector('textarea'),
        autoDownloadFontAwesome:false,//true从默认地址引入fontawesome依赖 false需自行引入(国内用bootcdn更快点)
        autosave: {
            enabled: true,
            uniqueId: "SimpleMDE",
            delay: 1000,
        blockStyles: {
            bold: "**",
            italic: "*",
            code: "```"
        forceSync: true,
        hideIcons: false,
        indentWithTabs: true,
        lineWrapping: true,
            singleLineBreaks: false,
            codeSyntaxHighlighting: true // 需要highlight依赖
        showIcons: true,
        spellChecker: true
    // 默认开启预览模式




  1. 启用预览模式
  2. 启用自动保存(每秒保存到localstorage,防刷新后丢失)
  3. 启用代码高亮
  4. 启用自定义地址的font-awesome




autoDownloadFontAwesome: If set to true, force downloads Font Awesome (used for icons). If set to false, prevents downloading. Defaults to undefined, which will intelligently check whether Font Awesome has already been included, then download accordingly.
autofocus: If set to true, autofocuses the editor. Defaults to false.
autosave: Saves the text that's being written and will load it back in the future. It will forget the text when the form it's contained in is submitted.

  • enabled: If set to true, autosave the text. Defaults to false.
  • delay: Delay between saves, in milliseconds. Defaults to 10000 (10s).
  • uniqueId: You must set a unique string identifier so that SimpleMDE can autosave. Something that separates this from other instances of SimpleMDE elsewhere on your website.

blockStyles: Customize how certain buttons that style blocks of text behave.

  • bold Can be set to ** or __. Defaults to **.
  • code Can be set to ``` or ~~~. Defaults to ``` .
  • italic Can be set to * or _. Defaults to *.

element: The DOM element for the textarea to use. Defaults to the first textarea on the page.
forceSync: If set to true, force text changes made in SimpleMDE to be immediately stored in original textarea. Defaults to false.
hideIcons: An array of icon names to hide. Can be used to hide specific icons shown by default without completely customizing the toolbar.
indentWithTabs: If set to false, indent using spaces instead of tabs. Defaults to true.
initialValue: If set, will customize the initial value of the editor.
insertTexts: Customize how certain buttons that insert text behave. Takes an array with two elements. The first element will be the text inserted before the cursor or highlight, and the second element will be inserted after. For example, this is the default link value: ["[", "](http://)"].

  • horizontalRule
  • image
  • link
  • table

lineWrapping: If set to false, disable line wrapping. Defaults to true.
parsingConfig: Adjust settings for parsing the Markdown during editing (not previewing).

  • allowAtxHeaderWithoutSpace: If set to true, will render headers without a space after the #. Defaults to false.
  • strikethrough: If set to false, will not process GFM strikethrough syntax. Defaults to true.
  • underscoresBreakWords: If set to true, let underscores be a delimiter for separating words. Defaults to false.

placeholder: Custom placeholder that should be displayed
previewRender: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
promptURLs: If set to true, a JS alert window appears asking for the link or image URL. Defaults to false.
renderingConfig: Adjust settings for parsing the Markdown during previewing (not editing).

  • singleLineBreaks: If set to false, disable parsing GFM single line breaks. Defaults to true.
  • codeSyntaxHighlighting: If set to true, will highlight using highlight.js. Defaults to false. To use this feature you must include highlight.js on your page. For example, include the script and the CSS files like:
    <script src=""></script>
    <link rel="stylesheet" href="">

shortcuts: Keyboard shortcuts associated with this instance. Defaults to the array of shortcuts.
showIcons: An array of icon names to show. Can be used to show specific icons hidden by default without completely customizing the toolbar.
spellChecker: If set to false, disable the spell checker. Defaults to true.
status: If set to false, hide the status bar. Defaults to the array of built-in status bar items.

  • Optionally, you can set an array of status bar items to include, and in what order. You can even define your own custom status bar items.

styleSelectedText: If set to false, remove the CodeMirror-selectedtext class from selected lines. Defaults to true.
tabSize: If set, customize the tab size. Defaults to 2.
toolbar: If set to false, hide the toolbar. Defaults to the array of icons.
toolbarTips: If set to false, disable toolbar button tips. Defaults to true.





查看原文: SimpleMDE.JS 轻松打造一个类似简书的纯前端MarkDown语法编辑器

  • bigmeercat
  • greenfrog
  • yellowpeacock
  • silverostrich
  • goldenladybug
  • yellowostrich
  • purplemeercat
  • smallrabbit
需要 登录 后回复方可回复, 如果你还没有账号你可以 注册 一个帐号。