ispiro
ispiro

Reputation: 27633

Automatically escape <'s and >'s

I want to show text on a web page without having to remember to go over it and check if there are any <'s and >'s in it, so simply copying the text from, say, notepad to visual studio isn’t good.

So I tried "paste alternate" but it adds line breaks, and keeps the original fonts etc. All I want is the text itself.

Is there an automatic way - via CSS or Visual Studio perhaps?

Upvotes: 0

Views: 82

Answers (2)

cjds
cjds

Reputation: 8426

Found an answer that uses jQuery.

Use the .text() function.

Will return all the text present in the HTML.

http://api.jquery.com/text/

For example ($('<p>test</p>').text());

will produce test

EDIT

For string substitution you can try the javascript replace method. Call it on document load. It should solve the problem

str.replace(">","&gt;");

Upvotes: 0

gustaf r
gustaf r

Reputation: 1234

Regex search+replace: s/</&lt;/ and s/>/&gt;/

Upvotes: 1

Related Questions