我正在使用 WMD 编辑器。 This一个。
工作正常。但问题是,我想让它与编辑表单一起使用。
现在我得到的是 html 而不是 markdown 文本。 我的代码如下在我的编辑页面中。
<div id="wmd-editor" class="wmd-panel">
<div id="wmd-button-bar"></div>
<textarea id="wmd-input"><?php echo $row['description']?></textarea>
</div>
<div id="wmd-preview" class="wmd-panel"></div>
<div id="wmd-output" class="wmd-panel"></div>
不确定这里出了什么问题。
最佳答案
首先:存储库没有维护(并且显然已经超过 7 年没有更新),因此您应该考虑切换到事件分支。 WMD 更名为Page Down
但您可以使用许多替代编辑器。
如timclutton评论说您可能正在将 HTML 存储在数据库中。 WMD 不支持从 HTML 到 Markdown 的转换。因此,最好的解决方案是将内容存储为 Markdown。
为此,请更改您的创建页面。由于我没有代码,我只会给您一个示例来说明它的外观:
<form action="/create" method="POST">
<div id="wmd-editor" class="wmd-panel">
<div id="wmd-button-bar"></div>
<textarea name="content" id="wmd-input"></textarea>
</div>
<div id="wmd-preview" class="wmd-panel"></div>
<div id="wmd-output" class="wmd-panel"></div>
<button type="submit">Send</button>
</form>
服务器端现在可以存储 $_POST['content']
的内容在您的数据库中,然后按照您现在的方式将其输出到编辑页面。
最后来自 Page Down wiki 的安全说明:
It should be noted that Markdown is not safe as far as user-entered input goes. Pretty much anything is valid in Markdown, in particular something like
<script>doEvil();</script>
. This PageDown repository includes the two plugins that Stack Exchange uses to sanitize the user's input; see the description of Markdown.Sanitizer.js below.
关于php - WMD 编辑器无法以编辑形式工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37407049/