homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Local / WebmasterWorld Community Center
Forum Library, Charter, Moderators: lawman

WebmasterWorld Community Center Forum

How to post snippets of code

 3:13 pm on Mar 10, 2008 (gmt 0)

Recently I've been asked by several people how I formatted code similar to: [webmasterworld.com ]

There are a few simple rules:[/b]
1) Wrap the code in pre/code tags: [pre ][code ] ... code here ...[/code ][/pre ]

2) If you want the box and no horizontal scroll, then also add the quote brackets: [quote ][pre ][code ][/code ][/pre ][/quote ]

3) To make sure the whole code is formatted, every blank line in your code needs at least one space:
[quote ][pre ][code ]line1
<- one space
<- another space
line4[/code ][/pre ][/quote ]

4)To have indentations in the code, about every 6 spaces is turned into 3 spaces in the forum. So, _ _ _ _ _ _ when posting equals _ _ _ when you view it. The spacing is the biggest problem because you lose it when you preview it. It is extremely important to copy your post before you preview it. Then re-paste it when you wish to submit or make any changes. I usually code with 3 space indentation; I find it easier to use Notepad to replace every 3 spaces with 6 spaces.

[quote ][pre ][code ]line1
_(one space)
_(another space)
line4[/code ][/pre ][/quote ]

Will turn into:



I hope this helps,

[edited by: Hawkgirl at 9:37 pm (utc) on Mar. 10, 2008]



 7:32 pm on Mar 10, 2008 (gmt 0)

vol7ron, you may be a Junior Member to webmasterworld, but you're a giant to me. Thanks!


 9:41 pm on Mar 10, 2008 (gmt 0)

Don't forget to read the site's rules on posting code - you can find them here [webmasterworld.com].

(Summary: only post relevant bits of code, make a test case, keep your code free of specifics, use style codes, and don't torture everyone else with "do my homework" requests.)


 2:16 pm on Mar 12, 2008 (gmt 0)

Thanks for the addition Hawkgirl.

Unfortunately, as you see above, if an admin formats your code, you lose the styling, unless they follow these practices. Above is a good example of how it would look like if you didn't copy your code before the preview and paste it before submitting. The last box originally looked like the following:




And thanks Mark.


 3:23 am on Mar 13, 2008 (gmt 0)

Actually, if an admin did it, I'm sure it'd be right. I'm just a non-code-hacking moderator. But I do know that posting code is a tricky business (thus the rules and the quote-work-arounds), and the moderators of the code-heavy forums here at WebmasterWorld do a great job of keeping everything running as smoothly as possible.


 7:43 pm on Mar 14, 2008 (gmt 0)



 5:40 pm on Mar 20, 2008 (gmt 0)

I don't know if the official rules cover this, but:

2) If you want the box and no horizontal scroll, then also add the quote brackets:

please do add the quote box because reading that page on my screen, which is 1024 x 768 makes a wide scroll causing the thread to be unreadable. Some people who are vision impaired will use 800 x 600 and as such that thread will be really intolerable and cause some people to be really lost.


 8:04 pm on Mar 25, 2008 (gmt 0)

No official rules, but of course we want everyone to be able to read the info here. I occasionally switch to 800x600 when I am VPNing and some sites do get a bit hairy with the formatting.

Clark, how often does this cause problems for you?

Not sure there's a good work-around right now, but we are very interested to know when things don't work well for everyone.


 8:27 pm on Mar 25, 2008 (gmt 0)

By that page I meant this page [webmasterworld.com].

I do get some scroll sometimes and more often an un-uniform layout, where the header won't be as wide as the middle part. Doesn't bother me unless there's a scroll.

I did send Brett a screenshot recently.


 8:48 pm on Mar 25, 2008 (gmt 0)

Thanks for letting us know!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Local / WebmasterWorld Community Center
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved