Intelligent HTML Coding

I'm looking for a better way to do some kind of smart HTML encoding. For example:

From: <a>Next >></a> to: <a>Next gt;gt;</a>
From: <p><a><b><< Prev</b></a><br/><a>Next >></a></p> to: <p><a><b>&lt;&lt; Prev</b></a><br/><a>Next gt;gt;</a></p>

This way, only part of the non-XML / HTML text will be encoded as if HtmlEncode was being called.

Any suggestions?

EDIT: this should be as easy as possible. Incoming text will come from users who do not know the HTML encoding.

+3
source share
5 answers

Yes: never write HTML in your source code. Instead, work with the API as a DOM, which takes care of all the encoding issues for you.

+6
source

# ( ), HTML Agility Pack. HTML. , , , , .

, JQuery. . HTML jQuery.

+2

, . ( , , .)

unencoded >> << HTML, , , <> <b>, . (, XSS.)

, HTML. , , . .

: , , HTML . , HTML, , - HTML- . HTML , , , HTML. , , .

0

tidy.net? , , , , -, . DLL , , .

, . ( , ), , , , . , , - , .

0

I would probably try to write a good regex for this. Are you doing this in code behind (C #) or client side with JavaScript?

http://www.regular-expressions.info/

-4
source

Source: https://habr.com/ru/post/1714304/


All Articles