💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
## 问题 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.