[英]How to escape non-standard (invalid) HTML tags?
I get a response from API that might contain HTML tags and I need to render those tags and I use angular directive [innerHTML]
and it works perfectly, for the most part, the problem starts when the string is something like this:我收到来自 API 的响应,其中可能包含 HTML 标签,我需要渲染这些标签,我使用 angular 指令
[innerHTML]
并且它在字符串开始时完美运行,大多数情况下,问题是这样的:
Test string, I am saying <hello>
[innerHTML]
treats <hello>
as a valid HTML tag and the output on the screen is something like this: [innerHTML]
将<hello>
视为有效的 HTML 标记,屏幕上的 output 如下所示:
Test string, I am saying
<hello>
is not a standard HTML tag and if there is a non-standard HTML tag in the string I want to escape those tags and this should be the output: <hello>
不是标准的 HTML 标签,如果字符串中有非标准的 HTML 标签,我想转义这些标签,这应该是 output:
Test string, I am saying <hello>
Any library to accomplish this task, I want to know if there is any pre-existing solution for this?任何图书馆来完成这项任务,我想知道是否有任何预先存在的解决方案?
Quote the character <
in front of hello as <
将 hello 前面的字符
<
引用为<
. .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.