Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 你如何处理图书馆中的换行问题;胡子表情_Javascript_Html - Fatal编程技术网

Javascript 你如何处理图书馆中的换行问题;胡子表情

Javascript 你如何处理图书馆中的换行问题;胡子表情,javascript,html,Javascript,Html,一些库和框架使用{{foo}}将数据插入HTML。这通常会插入内容为foo的textNode 所以如果你有用户创建的内容,比如 message='Hello\nWorld!'; //or message='Hello<br>World!'; message='Hello\nWorld!'; //或 message='HelloWorld!'; 如何在{{message}中显示新行?我意识到,大多数库中都有允许插入HTML的选项,但是您需要担心如何清理内容。有什么办法吗?您可以使用

一些库和框架使用
{{foo}}
将数据插入HTML。这通常会插入内容为
foo
textNode

所以如果你有用户创建的内容,比如

message='Hello\nWorld!';
//or
message='Hello<br>World!';
message='Hello\nWorld!';
//或
message='Hello
World!';

如何在
{{message}
中显示新行?我意识到,大多数库中都有允许插入HTML的选项,但是您需要担心如何清理内容。有什么办法吗?

您可以使用三个大括号在变量中输出html
{{{{message}}

好吧,要么允许html(坏),要么自己清理和格式化内容。考虑使用一些众所周知的格式,如标记,以允许用户编写丰富的文本,而不允许他们HTML。有现成的使用JS编写的解析器/编译器。