aspose file tools*
The moose likes Ranch Office and the fly likes Indenting code in posted text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Ranch Office
Bookmark "Indenting code in posted text" Watch "Indenting code in posted text" New topic
Author

Indenting code in posted text

Bill Compton
Ranch Hand

Joined: Aug 26, 2000
Posts: 186
As I begin to read many threads here, it occurs to me that many of them include code snippets that would be easier to read if the indentation were preserved. I'm sure the style-conscious Sheriff Wheaton would agree. Is there a straightforward way to do this?
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20647
    ∞

Oh yes!
I usually use the HTML <PRE> and </PRE> tags around my code fragment to do this, although there are UBB CODE tags that can do this too (click on the "UBB Code is ON" link when you are writing a message for more info).
Some forums have HTML turned off, so you would need to use the UBB tags.

[This message has been edited by Paul Wheaton (edited August 27, 2000).]


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Bill Compton
Ranch Hand

Joined: Aug 26, 2000
Posts: 186
"Ahh... I see," said the blind man!

Nice.
However, I did a brief survey of Ranch postings that include code that needs indentation and found that there are about 5 times as many such postings that don't use this than those that do (10:2). I wonder if a note on the text entry page to encourage this feature's use would help?
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20647
    ∞

Where is the text entry page you are thinking of?
(I fixed the tags in that message above - I should double check these things more often!)
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Also bear in mind that CODE and PRE are not quite as smart as most people would like. They both "eat" empty lines, so if you want blank lines to appear in your code examples, you need to put a space or two at the start of the empty lines:


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Bill Compton
Ranch Hand

Joined: Aug 26, 2000
Posts: 186
Sheriff: The "text entry page" I reffered to is the one I'm typing on right now to post this reply -- the one where UBB accepts a new topic or reply. What I was thinking of was maybe a note somewhere near this big key-in field (maybe just below the moose head?) sayin' somethin' like "If yer gonna put indented code in yer post, wrap it up with CODE tags like granny in her quilt."
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20647
    ∞

That sounds like a good idea. The only downside is rooting through the source code to find where that particular page is created and stuff in a bit of html. How about to the left where it says "Smilies Legend"?
Bill Compton
Ranch Hand

Joined: Aug 26, 2000
Posts: 186
Even better, 'cause it's closer to where you type.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Indenting code in posted text