Cradle/Express/EJS将html转换为其实体 [英] Cradle / Express / EJS convert html to its entities

查看:133
本文介绍了Cradle/Express/EJS将html转换为其实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在博客上使用了具有Express和EJS的Cradle.也许我错过了smth,但是其中一些将html实体转换为等效实体.

I'm using Cradle with Express and EJS on my blog. Maybe i am missing smth but some of them converts html entities to its equivalents.

我在doc.quote字段中有html,并且在这段代码之后它发生了变化

I have html in doc.quote field and after this piece of code it changes

quotesDb.view('list/by_date', {
    'startkey' : {},
    'endkey' : null,
    'descending' : true
}, function(err, res) {
    if (err) {
        r.send();
        return;
    }

    r.partial('quotes', {'quotes' : res}, function(err, str) {
        console.log(str);
        sendResponse('content', str);
    });
});

quotes.ejs:

quotes.ejs:

<% for (var i=0; i<quotes.length; i++) { %>
    <div>
        <%=quotes[i].value.quote%>
    </div>
    <div class="date">
        <%=(new Date(quotes[i].value.ts*1000)).toLocaleDateString()%><% if (quotes[i].value.author) { %>, <%=quotes[i].value.author%><% } %>
    </div>
<% } %>

"res"变量是具有内容"字段(具有html)的对象的数组.但是在渲染"str"后,将"quotes [i] .value.quote"符号转换为它的实体,说< br>.到& lt; br& gt;

"res" variable is array which has objects with "content" field (which has html). But after rendering "str" has "quotes[i].value.quote" symbols converted to its entities, say <br> to &lt ; br &gt ;

推荐答案

在这里找到了答案: http://groups.google.com/group/express-js/browse_thread/thread/f488d19a1604c30e?pli = 1

The answer was found here: http://groups.google.com/group/express-js/browse_thread/thread/f488d19a1604c30e?pli=1

对于带有转义的渲染:

<%=var%>


对于不逃避的渲染:


For rendering without escaping:

<%-var%>

这篇关于Cradle/Express/EJS将html转换为其实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆