Display HTML comment lines (<! - ->) in HTML files

I create a source code search engine and I return the results on an HTML page (more precisely, aspx, but the presentation logic is in HTML).

When someone searches for a line, I also return the entire line of code where this line can be found in the file. However, some lines of code come from HTML / aspx files, and these lines contain special HTML () comments.

When I try to print this line on an HTML page, it interprets it as a comment and does not display it on the screen .... how can I solve this solution so that it really displays?

Any help would be appreciated. Thank.

+3
source share
4 answers

, HTML-, HTML-. , ( , ), , <script> .

(aspx,

.NET HTML , , HTMLEncode. - , HTML- , Literal literalmode encode.

HTML)

, , innerHTML script, HTML-, JS :

// HTML-encode a string for use in text content or an attribute value delimited by
// double-quotes
//
function HTMLEncode(s) {
    return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
}

, , DOM , HTML-. ( element.textContent=, element.innerText IE, .)

+2

HTML . , < &lt;

+6

XML CDATA :

<![CDATA[ 
  some text with <!-- comments -->
]]>;
-1

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


All Articles