Page 1 of 1

question about posting code

Posted: Tue Sep 13, 2011 10:27 am
by Isaac
What's the standard way to show code on a website with having it be parsed? ( think that's the word i want)

What do here http://testing.isaacg.net/commentboxa/ seems to work on some browsers. Other times it looks like a waterfall of broken blocks of code, instead of code in one big square or stack of even squares.

Re: question about posting code

Posted: Tue Sep 13, 2011 2:09 pm
by Jeff250
Do you mean such that it preserves whitespace? Use <pre></pre>. Make sure to escape any special HTML characters inside of the <pre></pre>. Also, tabs are evil. Use some power of two # of spaces instead, say 4. Almost all text editors support this.

Re: question about posting code

Posted: Tue Sep 13, 2011 3:36 pm
by Isaac
Thanks, I'll check that out. Also, I just realized that < characters are converted into that &223kj23k stuff on our code blocks:

Code: Select all

<b>This is some code.</b>
I guess that's what I should be doing. Then I could just use regular divs.

Re: question about posting code

Posted: Tue Sep 13, 2011 6:40 pm
by Sirius
Spaces are a good way to break your spacebar (that may be a bit of an exaggeration), but luckily many editors also automagically convert between one and the other depending on preferences/the format of the rest of the file/etc. It does help that a space is always one character in fixed-width, whereas tabs seem to be rendered by some things as 4 and others as 8. VS's "tabify"/"untabify" commands can be handy like that... not that I'm even sure that's a real word, but hey, you get the point...

Re: question about posting code

Posted: Tue Sep 13, 2011 8:33 pm
by Jeff250
To clarify, by "tab," I mean the '\t' character. The key is fine, as long as it isn't outputting '\t' characters. :-P This is what I meant by text editor support--that they support using spaces for indentation when you press the tab key.

The worst is when a file has mixed tabs and spaces... gah.

Isaac, if I recall, the only two characters you have to worry about escaping inside of pre's are '<' and '&', since the rest can't become special without those two first, but if you're dealing with dynamic content, it's best to just use a library function for the escaping.

Re: question about posting code

Posted: Tue Sep 13, 2011 8:58 pm
by Isaac
Thanks guys. The changes to my text editors, for the tab thing, is a quick fix. As for the < and &, that should also be pretty easy to fix.

Oh and jeff:
Image
I know MySQL fundamentals.

I'm finding it really user friendly and the 5.1 user manual really easy to follow. I'm now friends with the mysql terminal. So I've moved on to the python mysqldb module to continue my mysql practice. All of this is on my own laptop, not my webserver. The Ubuntu repos did make installing everything really easy. I'll eventually make a new ajax chat application with this in the near future. Lots of fun!

Re: question about posting code

Posted: Tue Sep 13, 2011 11:11 pm
by Sirius
Jeff250 wrote:The worst is when a file has mixed tabs and spaces... gah.
Yes. Hate.