Search code examples
javascriptsimplemde

simpleMDE set value not parsing properly


I'm using simple markdown editor this in my form like

<textarea id="editor-board">
<script>
var simplemde = new SimpleMDE({ element: $("#editor-area")[0] });

simplemde.value("# How are
**This is bold** This is normal
_This is italic_ This is normal
```
commands goes here
demo commands
sudo apt update
```");

But this is not even loading plugin in textarea.

Wherease, on setting value to be value('this is simple text'); works fine.

How to set the markdown syntax in the editor?


Solution

  • You can try something like this using ES6 Template literals

    var simplemde = new SimpleMDE();
    
    simplemde.value(`# How are
      **This is bold** This is normal
      _This is italic_ This is normal
      \`\`\`
      commands goes here
      demo commands
      sudo apt update
      \`\`\`
    `);
    <script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
    <link href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <p><textarea rows="5" name="text"></textarea></p>

    OR do something like this for ES5:

    var simplemde = new SimpleMDE();
    
    simplemde.value("# How are\n  **This is bold** This is normal\n  _This is italic_ This is normal\n  ```\n  commands goes here\n  demo commands\n  sudo apt update\n  ```\n");
    <script src="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
    <link href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <p><textarea rows="5" name="text"></textarea></p>