开发者

Curing HtmlTextWriter's Ugly Formatting?

开发者 https://www.devze.com 2023-02-12 08:52 出处:网络
I\'m creating an ASP.NET server control using the HtmlTextWriter class. My understanding is that it\'s a nice class to use for making sure my output HTML is valid. I assumed it would format things nic

I'm creating an ASP.NET server control using the HtmlTextWriter class. My understanding is that it's a nice class to use for making sure my output HTML is valid. I assumed it would format things nicely as well, but it does a bunch of strange stuff that makes the output hard to read.

Are there some settings or something I can play with to get this looking like someone took the time to properly format it, or is it just a downside of using this class? Here are some examples of the ugly formatting I'm talking about:

  • Inconsistent use of self-closing tags. With some tags I get them, and others I don't.
  • Random newlines between tags.
  • Lack of newlines in appropriate places.
  • Mismatched indentation.

This is actually what I'm trying to reproduce:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="MySWF" width="100" height="100" codebase="https://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
    <param name="movie" value="/MySWF.swf"></param>
    <param name="quality" value="high" />
    <param name="allowScriptAccess" value="sameDomain" /> 
    <embed align="middle" pluginspage="https://www.adobe.com/go/getflashplayer" width="100" quality="high" height="100" loop="false" name="MySWF" type="application/x-shockwave-flash" play="true" allowscriptaccess="sameDomain" src="/MySWF.swf" />
</object>

...and this is what I'm getting:

    <object classid="clsid:D27CDB开发者_运维技巧6E-AE6D-11cf-96B8-444553540000" id="MySWF" width="100" height="100" codebase="https://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
        <param name="movie" value="/MySWF.swf">

        </param><param name="quality" value="high">

        </param><param name="allowScriptAccess" value="sameDomain">

        </param><embed align="middle" pluginspage="https://www.adobe.com/go/getflashplayer" width="100" quality="high" height="100" loop="false" name="MySWF" type="application/x-shockwave-flash" play="true" allowscriptaccess="sameDomain" src="/MySWF.swf" />
</object>


AFAIK, there aren't any settings for the actual formatting. If you want to format it yourself, that would probably be the best solution. Thou, this would create some overhead, so idk if it's worth it. Here are some open source examples of DIY formatting

http://snipplr.com/view/28048/net-html-formatter/

http://weblogs.asp.net/scottcate/archive/2007/01/10/my-c-code-formatting.aspx

0

精彩评论

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