开发者

Visual Studio reformats my pre-formatted HTML

开发者 https://www.devze.com 2023-01-20 21:08 出处:网络
When I put text directly into a <pre> tag and press Ctrl+K, Ctrl+D, the whitespace is preserved.

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 knows 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)


Tool > Options > Text Editor > HTML > Miscellaneous [Format HTML on paste]

The better question is why you're putting tags inside tags.

0

精彩评论

暂无评论...
验证码 换一张
取 消