question about posting code

For all coding issues - MODers and programmers, HTML and more.

Moderators: Jeff250, fliptw

Post Reply
User avatar
Isaac
DBB Artist
DBB Artist
Posts: 7649
Joined: Mon Aug 01, 2005 8:47 am
Location: 🍕

question about posting code

Post 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.
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-★ ·:*¨༺꧁༺ :E ༻꧂༻¨*:·.★-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
User avatar
Jeff250
DBB Master
DBB Master
Posts: 6511
Joined: Sun Sep 05, 1999 2:01 am
Location: ❄️❄️❄️

Re: question about posting code

Post 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.
User avatar
Isaac
DBB Artist
DBB Artist
Posts: 7649
Joined: Mon Aug 01, 2005 8:47 am
Location: 🍕

Re: question about posting code

Post 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.
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-★ ·:*¨༺꧁༺ :E ༻꧂༻¨*:·.★-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
User avatar
Sirius
DBB Master
DBB Master
Posts: 5616
Joined: Fri May 28, 1999 2:01 am
Location: Bellevue, WA
Contact:

Re: question about posting code

Post 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...
User avatar
Jeff250
DBB Master
DBB Master
Posts: 6511
Joined: Sun Sep 05, 1999 2:01 am
Location: ❄️❄️❄️

Re: question about posting code

Post 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.
User avatar
Isaac
DBB Artist
DBB Artist
Posts: 7649
Joined: Mon Aug 01, 2005 8:47 am
Location: 🍕

Re: question about posting code

Post 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!
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-★ ·:*¨༺꧁༺ :E ༻꧂༻¨*:·.★-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
User avatar
Sirius
DBB Master
DBB Master
Posts: 5616
Joined: Fri May 28, 1999 2:01 am
Location: Bellevue, WA
Contact:

Re: question about posting code

Post by Sirius »

Jeff250 wrote:The worst is when a file has mixed tabs and spaces... gah.
Yes. Hate.
Post Reply