0

我在我的表单中使用简单的降价编辑器,比如

<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');工作正常。

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

4

1 回答 1

1

您可以使用ES6 模板文字尝试这样的事情

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>

或者为 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>

于 2017-12-15T12:31:09.093 回答