Is there a HTML/CSS way to display HTML tags without parsing?

Viewed 33578

Is there any way that I could display HTML tags without parsing? Tags like XMP worked before perfectly but now it's replaced with PRE that isn't so cool. Take a look at this example:

//This used to NOT PARSE HTML even if you used standard < and >.
<XMP>
<a hred="http://example.com">Link</a>
</XMP>

//New PRE tag requires &lt; and &gt; as replacement for < and >.
<PRE>
&#60;a href="http://example.com"&#62;Link&#60;/A&#62;
</PRE>

What I'm looking for is equivalent of old XMP tag. New PRE tag will parse code.

9 Answers

And then... a few years go by, I have the same problem while converting my blog from wordpress to a vuejs spa backed by lambda and dynamodb.

And the answer is; at least in my situation. Escape the entity.

&lt; becomes &amp;lt;

&gt; becomes &amp;gt;

etc. etc.

Hope this helps.

If you want to be more complex, another way is to create a custom tag using jQuery. For this example, I used <noparse>.

$('noparse').each(function(){
    if($(this).attr('tagchecked') != 'true'){ //checks if already changed tag
        $(this).text($(this).html()).attr('tagchecked', 'true'); //makes the html into plaintext
    }
});

JSFiddle here

Related