views:

30

answers:

0

When I put text directly into a <pre> tag and press Ctrl+K, Ctrl+D, the whitespace is preserved.

<pre>
  This
    whitespace
      gets
        preserved.</pre>

But when I put text in a tag nested within a <pre> tag, the whitespace is not preserved.

<pre><code>This whitespace doesn't get preserved.</code></pre>

Only text directly within the <pre> tag gets preserved.

<pre>
  This
    does,
      <code>but this doesn't,</code>
            and
              this
                does.</pre>

I've tried using the CSS white-space property...

<pre><code style="white-space:pre;">but it doesn't work either.</code></pre>

I've tried Tools > Options > Text Editor > HTML > Formatting > Tag Specific Options, but there's nothing there that determines whether tags preserve whitespace.

It looks like this behavior is hard-coded into Visual Studio 2008/2010, but maybe one of you know a workaround. Thanks.

A couple more things:

  • I would prefer a valid XHTML/HTML5 solution
  • I need to nest tags within <pre> tags (like <a> tags)