Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 434
Atadj Avatar asked Jul 26 '12 16:07

Atadj


People also ask

How do I display HTML code without rendering?

You can show HTML tags as plain text in HTML on a website or webpage by replacing < with &lt; or &60; and > with &gt; or &62; on each HTML tag that you want to be visible. Ordinarily, HTML tags are not visible to the reader on the browser.

How do I view the HTML code of a website?

To view only the source code, press Ctrl + U on your computer's keyboard. Right-click a blank part of the web page and select View source from the pop-up menu that appears.

What is XMP tag in HTML?

Summary. The <xmp> HTML element renders text between the start and end tags without interpreting the HTML in between and using a monospaced font. The HTML2 specification recommended that it should be rendered wide enough to allow 80 characters per line. Note: Do not use this element.


2 Answers

You can use a script element with its type set to denote plain text, and set its display property to block. This only affects the parsing behavior: no markup (tags or entity or character references) is recognized, except for the end tag of the element itself </script>. (So it is not quite the same as xmp, where the recognized tag is </xmp>.) You can separately make white space handling similar to that of xmp and pre and/or set the font the monospace as in those elements by default.

Example:

<style>     script {         display: block;     } </style> 

Then within document body:

<script type="text/plain">     <i>&eacute;</i> </script> 

Tested on newest versions of IE, Chrome, Firefox, Opera. Didn’t work in IE 8 and IE 7 emulation on IE 9, but that’s probably a bug in the emulation.

However, I don’t see why you would use this instead of xmp, which hasn’t stopped working. It’s not in the specs, but if you are worried about that, you should have always been worried. Mentioned in HTML 2.0 (the first HTML spec ever) as avoidable, it was deprecated in HTML 3.2 and completely removed in HTML 4.0 (long ago: in 1997).

The xmp is making a comeback rather than dying. The W3C HTML5 (characterized as the current HTML specification by W3C staff) declares xmp as obsolete and non-conforming, but it also imposes a requirement on browsers: “User agents must treat xmp elements in a manner equivalent to pre elements in terms of semantics and for purposes of rendering. (The parser has special behavior for this element though.)” The old parsing behavior is thus not explicitly required, but clearly implied.

like image 144
Jukka K. Korpela Avatar answered Sep 22 '22 19:09

Jukka K. Korpela


I personally think using the <code> </code> tags only works in Dream Weaver and the tag <xmp> </xmp> never stopped working unless you put in </xmp> it works fine. Using <textarea> </textarea> makes it so that others can edit your code on the website or the page so I recommend that the tag <xmp> </xmp> is still used and that that tag still lives on.

like image 21
Sean Cassiere Avatar answered Sep 21 '22 19:09

Sean Cassiere