Reputation: 3782
Quick question, If I want to document some code on a basic HTML and put that within a CODE tag, how can I quickly convert the code between those tags when the page renders to display properly? I know I can write a javascript find and replace and search through the string over and over until its done replacing all the characters, but is there a better way?
Or, is there a jQuery way to do it if I need to use javascript?
Upvotes: 2
Views: 2723
Reputation: 1211
Sounds like you may be looking for syntax highlighting. Take a look at google's syntax highlihter
Upvotes: 2
Reputation: 12039
I think the <code>
tag is more for displaying with a certain font, rather than layout. <code>
seems to just use a monospaced font.
You might be looking for the <pre>
tag (for pre formatted). That will preserve line breaks and spaces.
Unless the code you are trying to display is HTML code itself, then I think you'd have to change all the <
's to <
's ahead of time
Upvotes: 7