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: 7127
Joined: Mon Aug 01, 2005 8:47 am
Location: Ơ̸̦͇̲̬̭̱̰͎̞͈̣͎͚̳ͬ͋̃̀̇͊͂͋͐ͦ̽ͣ̂ͥ͊̅̀̚͠ B̶͖̯͉̜̰̲̓̔͋̈́ͅ È̯ Y̪̤̼͉̠̙͝

question about posting code

Post by Isaac » Tue Sep 13, 2011 10:27 am

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.
s☼-£♦и̫͍ͥ̍ͪ͌̓͗͡о̡̹̱͊̅ͮ̓̕͢б̧̝̻̪̤̳̜͐̓̉ͤ͢͜ ͙̬͙̆̑ͮ̐ͭ̾̂́͘i̎̌̾̓̽̀̈̓̀҉͉̙̦͎̘̝͕f̻͕͔̘ͣͣ̓͊̿͢͜ ͍͔͈͕̮̫ͣ̆ͮ̊͋/♂6Æ!♪╩"▲L└уͭ̂͐̇҉̴̣̼̞̠̯͓̺̞ф̜̊͌̈́̋̏̐́ц̨͔̮̿̇ ̨̛͖̙͖̖̮̗̱ͩ̆͞ͅа̥͇̞̖͚̟̅͐ͤ͞͠͠э̜̘̩̳̬͔̾ͯ̀ͫ̒̐̿ͅͅг̭̖̀ͦ̒̑ͥ̌ͮͫ͞ё͔̟̃ͬ̾̓͟ё̦̞̙̫͔̩͑̀͂ͯ̄̔̃̑̀͠ͅͅ
User avatar
Jeff250
DBB Master
DBB Master
Posts: 6387
Joined: Sun Sep 05, 1999 2:01 am
Location: ☃☃☃

Re: question about posting code

Post by Jeff250 » Tue Sep 13, 2011 2:09 pm

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: 7127
Joined: Mon Aug 01, 2005 8:47 am
Location: Ơ̸̦͇̲̬̭̱̰͎̞͈̣͎͚̳ͬ͋̃̀̇͊͂͋͐ͦ̽ͣ̂ͥ͊̅̀̚͠ B̶͖̯͉̜̰̲̓̔͋̈́ͅ È̯ Y̪̤̼͉̠̙͝

Re: question about posting code

Post by Isaac » Tue Sep 13, 2011 3:36 pm

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.
s☼-£♦и̫͍ͥ̍ͪ͌̓͗͡о̡̹̱͊̅ͮ̓̕͢б̧̝̻̪̤̳̜͐̓̉ͤ͢͜ ͙̬͙̆̑ͮ̐ͭ̾̂́͘i̎̌̾̓̽̀̈̓̀҉͉̙̦͎̘̝͕f̻͕͔̘ͣͣ̓͊̿͢͜ ͍͔͈͕̮̫ͣ̆ͮ̊͋/♂6Æ!♪╩"▲L└уͭ̂͐̇҉̴̣̼̞̠̯͓̺̞ф̜̊͌̈́̋̏̐́ц̨͔̮̿̇ ̨̛͖̙͖̖̮̗̱ͩ̆͞ͅа̥͇̞̖͚̟̅͐ͤ͞͠͠э̜̘̩̳̬͔̾ͯ̀ͫ̒̐̿ͅͅг̭̖̀ͦ̒̑ͥ̌ͮͫ͞ё͔̟̃ͬ̾̓͟ё̦̞̙̫͔̩͑̀͂ͯ̄̔̃̑̀͠ͅͅ
User avatar
Sirius
DBB Master
DBB Master
Posts: 5437
Joined: Fri May 28, 1999 2:01 am
Location: Bellevue, WA
Contact:

Re: question about posting code

Post by Sirius » Tue Sep 13, 2011 6:40 pm

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: 6387
Joined: Sun Sep 05, 1999 2:01 am
Location: ☃☃☃

Re: question about posting code

Post by Jeff250 » Tue Sep 13, 2011 8:33 pm

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: 7127
Joined: Mon Aug 01, 2005 8:47 am
Location: Ơ̸̦͇̲̬̭̱̰͎̞͈̣͎͚̳ͬ͋̃̀̇͊͂͋͐ͦ̽ͣ̂ͥ͊̅̀̚͠ B̶͖̯͉̜̰̲̓̔͋̈́ͅ È̯ Y̪̤̼͉̠̙͝

Re: question about posting code

Post by Isaac » Tue Sep 13, 2011 8:58 pm

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!
s☼-£♦и̫͍ͥ̍ͪ͌̓͗͡о̡̹̱͊̅ͮ̓̕͢б̧̝̻̪̤̳̜͐̓̉ͤ͢͜ ͙̬͙̆̑ͮ̐ͭ̾̂́͘i̎̌̾̓̽̀̈̓̀҉͉̙̦͎̘̝͕f̻͕͔̘ͣͣ̓͊̿͢͜ ͍͔͈͕̮̫ͣ̆ͮ̊͋/♂6Æ!♪╩"▲L└уͭ̂͐̇҉̴̣̼̞̠̯͓̺̞ф̜̊͌̈́̋̏̐́ц̨͔̮̿̇ ̨̛͖̙͖̖̮̗̱ͩ̆͞ͅа̥͇̞̖͚̟̅͐ͤ͞͠͠э̜̘̩̳̬͔̾ͯ̀ͫ̒̐̿ͅͅг̭̖̀ͦ̒̑ͥ̌ͮͫ͞ё͔̟̃ͬ̾̓͟ё̦̞̙̫͔̩͑̀͂ͯ̄̔̃̑̀͠ͅͅ
User avatar
Sirius
DBB Master
DBB Master
Posts: 5437
Joined: Fri May 28, 1999 2:01 am
Location: Bellevue, WA
Contact:

Re: question about posting code

Post by Sirius » Tue Sep 13, 2011 11:11 pm

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