使用Javascript和自动刷新将文本转换为HTML

时间:2017-09-21 12:37:14

标签: javascript html

我有一个脚本从文本文件中提取信息并以html格式显示。 我提取的文本采用这种格式,每个事件都有行更改。

rpl <- unlist( lapply( waydf$geometry$coordinates , nrow ) ) # row per line
 waydf <- waydf[ rpl > 1 , ]

library(parallel)
cl <- makeCluster(detectCores())
cl <- clusterEvalQ(cl, { library(sf) })  # you need to export packages as well
# cl <- clusterExport(cl, "st_linestring")  # each worker is a new environment, you will need to export variables/functions to
ll <- parallel::parLapply(cl, waydf$geometry$coordinates, function(i) st_linestring)    # if st_linestring takes arguments then st_linestring(x)
stopCluster(cl)

outdf <- sf::st_sf(
line_geometry = sf::st_sfc( ll , crs = epsg ) ,
osm_id = waydf$id
)

当我运行我的脚本时,在我的html页面中会发现这样:

2017-09-20 19:01:13 INFO应用程序 - 启动应用程序2017-09-20 19:01:13 INFO应用程序 - 没有活动的配置文件集,回退到默认配置文件:默认2017-09-20 19: 01:22 INFO应用程序 - 在10.177秒内启动应用程序(JVM运行12.187)2017-09-20 19:22:32 INFO Util - 检测到配置更改。

任何人都知道它是否可以像在网站上的文本文件中那样完全取代? 谢谢tyou。

2017-09-20 19:01:13 INFO Application - Starting Application 
2017-09-20 19:01:13 INFO Application - No active profile set, 
2017-09-20 19:01:22 INFO Application - Started Application in 10.177 seconds
2017-09-20 19:22:32 INFO Util - Detected configuration changes

2 个答案:

答案 0 :(得分:0)

您可以将响应放在<pre>标记中(保留行间距和中断),或者,如果您愿意,可以使用以下Regex表达式插入<br />标记:

replace(/\n/g, "<br />");

答案 1 :(得分:0)

您可以替换换行符:

replace(/(\n|\r)/g,'<br />'));

另见: javascript replace line breaks AND special characters