[英]How to render tinyMCE content as
I am learning node.js/express/mongoDB and I am creating a blog.我正在学习 node.js/express/mongoDB 并且正在创建一个博客。 I used tinyMCE as the editor but I cannot figure out how to render my input as html.
我使用 tinyMCE 作为编辑器,但我不知道如何将我的输入呈现为 html。 Instead it is displaying the tags around my content.
相反,它在我的内容周围显示标签。 How can I display it as html?
如何将其显示为 html?
output with no HTML output 没有 HTML
here is my code for my show page这是我的显示页面的代码
<div class="row">
<div class="col-6 offset-3">
<%= blog.body %>
</div>
</div>
</div>
here is my blog creation code这是我的博客创建代码
<div class="form-group">
<!-- use TINYMCE for textarea -->
<label for="blogContent">Blog Content</label>
<textarea class="form-control" name="blog[body]" id="editor" cols="30" rows="10" type="hidden"></textarea>
</div>
<input class="btn btn-primary mb-3" type="submit">
</form>
</div>
</div>
<% include modal.ejs %>
<script>
tinymce.init({
selector: '#editor',
plugins: [
"image",
],
});
</script>
Try this, it works perfectly for me. 试试这个,对我来说非常合适。 Note, I'm not using node and know very little about it, so adjust accordingly.
请注意,我没有使用节点,对此了解甚少,因此请进行相应调整。
HTML: HTML:
<textarea id="edit" class="mceEditor"></textarea>
Initialization of Tiny MCE: Tiny MCE的初始化:
tinyMCE.init({
// General options
mode : "specific_textareas",
editor_selector : "mceEditor",
plugins: 'autoresize'
});
Retrieve HTML From TinyMCE: 从TinyMCE检索HTML:
let content = tinyMCE.get('edit').getContent();
Using this <%=
ejs tag, you escape the HTML code.使用这个
<%=
ejs 标签,您可以转义 HTML 代码。 So HTML is not rendered, that's why you see displayed HTML tags.因此不会呈现 HTML,这就是您看到显示的 HTML 标签的原因。
If you want to unescape the HTML code, use the <%-
tag.如果要取消转义 HTML 代码,请使用
<%-
标签。
<%- blog.body %>
More info here https://ejs.co/更多信息在这里https://ejs.co/
I had the same problem, you should use the <%-
instead of <%=
tag for rendering HTML.我有同样的问题,你应该使用
<%-
而不是<%=
标签来渲染 HTML。 Good Luck!祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.