How do you preserve whitespace in Java code?

How do you preserve whitespace in Java code?

by John Isner -
Number of replies: 3
I'm writing some questions about programming, and I need to include some Java code in the question text. But no matter what I do, the editor removes my whitespace (spaces, newlines), flattening the code into one long line.

For example, here is my latest attempt (I have no idea why it doesn't work):
  • toggle the editor into HTML mode
  • manually enter <pre><code>
  • paste Java code from another editor (vim, indenting with spaces)
  • manually enter </code></pre>
When I toggle back into normal mode, the code looks fine. But if I return to HTML mode, all extra whitespace is removed. I now have one long line.

The long line is also what I see if I save the question and preview it, so I think the HTML editor is causing the problem.
Average of ratings: -
In reply to John Isner

Re: How do you preserve whitespace in Java code?

by Steve Hyndman -

You should be able to verify this by disabling the html editor in your profile. I have to do this anytime I work on database templates.

Steve

In reply to Steve Hyndman

Re: How do you preserve whitespace in Java code?

by John Isner -
Perfect answer! Too bad this forum doesn't allow ratings smile