twikoojs / twikoo

💬 一个简洁、安全、免费的静态网站评论系统 | A simple, safe, free comment system.
http://twikoo.js.org
MIT License
1.4k stars 264 forks source link

commentText 返回数据优化 #681

Closed weekdaycare closed 2 months ago

weekdaycare commented 2 months ago

使用 getRecentComment 获取最新评论时调用 commentText 时,当用户评论 <a href="...">...</a> 等其他由代码块包裹住的 HTML 元素时,函数只会去掉 <code></code> 标签使得 commentText 变成含有html代码纯文本格式,不知能否优化一下相关逻辑,或者使其输出转义后的字符?

imaegoo commented 2 months ago

commentText 是文本格式的评论内容,如果需要插入到 html,需要自行转义或者去掉标签的。参考 butterfly 主题的做法:

https://github.com/jerryc127/hexo-theme-butterfly/blob/dev/layout/includes/third-party/newest-comments/twikoo-comment.pug#L9C24-L9C47

.replace(/<[^>]+>/g,"")
weekdaycare commented 2 months ago

好的👌