Robolisk
Robolisk

Reputation: 1792

How to add html code to a website but not have it actually turn to code?

I'm not sure how to describe this one. Basicly I want to show the coding of my website, in my website. So I'm not sure what tag to put. I've done some googling but i'm not even sure what I'm Googleing. I've found these tags, but none of them seemed to work. I found the script tag which I found out isn't what I needed and the code tag but that didn't do what I wanted. Anyone know what to do? Thanks in advance

Upvotes: 2

Views: 191

Answers (4)

ryanggfx
ryanggfx

Reputation: 108

take a look at this, i think it may be what you are looking for. http://code.google.com/p/google-code-prettify/

Upvotes: 0

Marc B
Marc B

Reputation: 360842

write the < as &lt; and the > as &gt; (their character entity equivalents). This will prevent the browser from interpreting them as tags.

So instead of

<p>This is an <i>example</i> of html.<p>

You'd write

&lt;p&gt;This is an &lt;i&gt;example&lt;/i&gt; of html.&lt;/p&gt;

Tedious, but necessary. Technically speaking, a > is only seen as a tag closer if it was preceded by a < somewhere, so you MIGHT be able to get by with just doing < -> &lt;, but it's safer to write out both characters in entity format.

Once that's done you may want to wrap it with the <pre> tag (as in preformatted) which will cause the spacing and line breaks to be rendered just as they appear in your source code.

Upvotes: 3

gunan
gunan

Reputation: 927

I am not sure if you can do it with a simple tag, but I use this php library to convert my code to nice html code http://qbnz.com/highlighter/

Upvotes: 0

esqew
esqew

Reputation: 44710

Utilize the HTML entity for each applicable symbol. Alternatively, you could use PHP and run the string through htmlentities.

Upvotes: 1

Related Questions