gpt4 book ai didi

JavaScript 插件,用于查找纯文本中的图像链接并将它们转换为 Angular js 中的 HTML

转载 作者:行者123 更新时间:2023-12-05 01:17:24 27 4
gpt4 key购买 nike

关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

3年前关闭。




Improve this question




我有一种情况,如果聊天消息带有图像链接,我需要显示图像,目前我只显示图像链接。

一个解决方案我认为我会检查 lastIndexOf('.') 并获取扩展名并在 ng-if 中匹配它,但我觉得这不是一个很好的解决方案。
因此,我正在寻找任何为我做的库或 Angular 内置模块,就像:

linkify(Linkify is a JavaScript plugin for finding links in plain-text and converting them to HTML tags)

最佳答案

imgify(text) {
const regexp = /\b(https?:\/\/\S+(?:png|jpe?g|gif)\S*)\b/ig;
const replace = "<br><img src='$1'>";
return text.replace(regexp, replace);
}

关于JavaScript 插件,用于查找纯文本中的图像链接并将它们转换为 Angular js 中的 HTML <img>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38349684/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com