我正在尝试在节点红色中使用rss解析器并将输入作为格式化消息转发到松弛:
node-red export:
[{"id":"f6ecdf35.256ab","type":"template","z":"1573541c.6cc74c","name":"Blog post","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{article.author}} has published an article: *{{article.title}}*\n{{article.link}}","output":"str","x":580,"y":640,"wires":[["ffcd3009.7a20c","799b343a.f89a2c"]]},{"id":"4f9293db.e8614c","type":"feedparse","z":"1573541c.6cc74c","name":"reddit news","url":"http://www.reddit.com/r/news/.rss","interval":"60","x":390,"y":640,"wires":[["f6ecdf35.256ab"]]},{"id":"ffcd3009.7a20c","type":"slack","z":"1573541c.6cc74c","name":"","channelURL":"https://hooks.slack.com/services/REMOVED","username":"rss bot","emojiIcon":":robot_face:","channel":"test","x":750,"y":640,"wires":[]},{"id":"799b343a.f89a2c","type":"debug","z":"1573541c.6cc74c","name":"","active":true,"console":"false","complete":"true","x":750,"y":700,"wires":[]}]
模板如下:
{{article.author}} has published an article: *{{article.title}}*
{{article.link}}
我期待得到:
/u/casac8 has published an article: *Guy who left manure at Treasury Secretary Mnuchin's house has come forward, cites First Amendment*
https://www.reddit.com/r/news/comments/7m0ag1/guy_who_left_manure_at_treasury_secretary/
但模板返回:
/u/casac8 has published an article: *Guy who left manure at Treasury Secretary Mnuchin's house has come forward, cites First Amendment*
https://www.reddit.com/r/news/comments/7m0ag1/guy_who_left_manure_at_treasury_secretary/
如何让模板节点返回未转义的utf8字符串?
我现在的解决方法是将其转换回来的函数节点:
function parseHtmlEntities(str) {
return str.replace(/&#x([0-9a-f]{1,3});/gi, function(match, numStr) {
var num = parseInt(numStr, 16);
return String.fromCharCode(num);
});
}
msg.payload = parseHtmlEntities(msg.payload);
return msg;
答案 0 :(得分:1)
正如模板节点的侧栏帮助中所提到的,为了避免转义html实体,你应该使用三个大括号:
{{{article.author}}}