简体   繁体   English

如何以使链接可点击的方式安全地将文本转换为 html 代码?

[英]How to safely convert text to html code in a way that makes links clickable?

Example input:示例输入:

Hello. Please go to example.com! <script>/*this should not be executed*/</script>

Example output:示例 output:

Hello: Please go to <a href="http.//example.com">example.com</a>! &ltscript&gt/*this should not be executed*/&lt/script&gt

I am using Javascript.我正在使用 Javascript。 If this is already answered, please give me a link.如果这已经回答,请给我一个链接。

Apparently, https://linkify.js.org/ works the way I wanted.显然, https://linkify.js.org/按我想要的方式工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM