简体   繁体   中英

Escape !- -! inside strings in javascript

I have a javascript conversion tool for moving XML into Fitnesse tables running on a Fitnesse Static Page, in which I use !- and -! around CamelCase and xmlns to avoid Fitnesse from processing them. Ironically, the use of these is causing Fitnesse to interpret them when I run the conversion tool (I take a big string var and do a $("#div").html(output); which is causing some funkiness with Fitnesse.

I have the javascript running inside !- and -!, and when building these fitnesse tables, I set it up like this:

|key|!-CamelCaseValue-!|

The javascript looks like this:

output += "!-" + currentValue + "-!";

Fitnesse looks like it is ending the script here. How can I escape these?

Option 1

var startToken = "!" + "-";
var endToken  = "-" + "!";

output += startToken + currentValue + endToken;

Option 2

output += "!\-" + currentValue + "-\!";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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