从 Chatbot 返回渲染 HTML
Returning Rendered HTML from Chatbot
我正在使用 liouh (https://github.com/liouh/chat-bot) 的聊天机器人。当我尝试 return 一个 URL 时,它给了我 unrendered/raw HTML 而不是 link。在下面的 Google 情况下,我如何 return 呈现 link?谢谢
function chatBot() {
// current user input
this.input;
this.respondTo = function(input) {
this.input = input.toLowerCase();
if(this.match('link to google'))
return "<a href='http://google.com'>Google.com</a>";
if(this.input == 'noop')
return;
return "I dont know the answer to '" + input + "'. You can teach me that via the link at the top of this page.";
}
this.match = function(regex) {
return new RegExp(regex).test(this.input);
}
}
index.js
的第 54 行似乎需要更改
中的代码
line.find('.text').text(text);
到
line.find('.text').html(text);
这会将收到的回复附加为 HTML 而不是纯文本。
我正在使用 liouh (https://github.com/liouh/chat-bot) 的聊天机器人。当我尝试 return 一个 URL 时,它给了我 unrendered/raw HTML 而不是 link。在下面的 Google 情况下,我如何 return 呈现 link?谢谢
function chatBot() {
// current user input
this.input;
this.respondTo = function(input) {
this.input = input.toLowerCase();
if(this.match('link to google'))
return "<a href='http://google.com'>Google.com</a>";
if(this.input == 'noop')
return;
return "I dont know the answer to '" + input + "'. You can teach me that via the link at the top of this page.";
}
this.match = function(regex) {
return new RegExp(regex).test(this.input);
}
}
index.js
的第 54 行似乎需要更改
line.find('.text').text(text);
到
line.find('.text').html(text);
这会将收到的回复附加为 HTML 而不是纯文本。