simpleMDE设置值无法正确解析

时间:2017-12-15 12:18:41

标签: javascript simplemde

我在我的表单中使用simple markdown editor,如

<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
```");

但这甚至不能在textarea中加载插件。

此外,设置值为value('this is simple text');时效果正常。

如何在编辑器中设置降价语法?

1 个答案:

答案 0 :(得分:1)

您可以使用ES6 Template literals

尝试这样的操作

&#13;
&#13;
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
  \`\`\`
`);
&#13;
<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>
&#13;
&#13;
&#13;

或者为ES5执行类似的操作:

&#13;
&#13;
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");
&#13;
<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>
&#13;
&#13;
&#13;