ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 问题 Problem 你需要使用字符实体来替换HTML标签: You need to replace HTML tags with named entities: `<br/> => &lt;br/&gt;` ## 办法 Solution ~~~ htmlEncode = (str) -> str.replace /[&<>"']/g, ($0) -> "&" + {"&":"amp", "<":"lt", ">":"gt", '"':"quot", "'":"#39"}[$0] + ";" htmlEncode('<a href="http://bn.com">Barnes & Noble</a>') # => '&lt;a href=&quot;http://bn.com&quot;&gt;Barnes &amp; Noble&lt;/a&gt;' ~~~ ## 讨论 Discussion 可能还有比上面方法更好的实现。 There are probably better ways to implement the above method.