ASP.NET MVC“整洁”动态 HTML

发布于 2024-09-11 15:08:41 字数 1015 浏览 6 评论 0原文

我想知道是否有任何类型的工具可以在 Tidy Html飞。

目前在我的应用程序中,我使用母版页,然后我的视图加载到母版页中。问题是 总是在输出 HTML 中添加额外的空格/换行符。

我真正想做的就是清理它,这样

<title>
    This is my title

</title>

看起来就像

<title>This is my title</title>

现在我意识到我可以遍历并设置

<asp:content ID="Content1" runat="server" ContentPlaceHolderID="TitleContent">This is my title</asp:content>

但这变得很痛苦,因为我经常使用 Ctrl + k< /kbd> + d 这会导致不希望的重新格式化。

此外,当我使用内联代码

 <asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">User <%: Model.UserName%> - Urban Now</asp:Content>

并使用“重新格式化”击键时,在 <%: Model.UserName%> 之前和之后也有换行符,并且无法在“工具/选项/格式 --> 标记特定选项”中设置格式(至少我找不到)。

I'm wondering if there's any kind of tool out there to Tidy Html on the fly.

Currently in my app, I use a MasterPage and then my Views are loaded into the Masterpage. The problem is that the <asp:content runat="server" ... /> always adds additional whitespace/linebreaks in the output HTML.

What I'd really like to do is clean it up so that

<title>
    This is my title

</title>

will look like

<title>This is my title</title>

Now I realize that I can go through and set

<asp:content ID="Content1" runat="server" ContentPlaceHolderID="TitleContent">This is my title</asp:content>

But that becomes a pain because I often use Ctrl + k + d which results in the reformatting that is undesirable.

Moreover, when I use inline code like

 <asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">User <%: Model.UserName%> - Urban Now</asp:Content>

and use the "reformatting" key strokes, then there are also line breaks before and after the <%: Model.UserName%> and there is no way to set that formatting in the "Tools/Options/Formatting --> Tag Specific Options" (at least not that I can find).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小瓶盖 2024-09-18 15:08:41

TidyManaged 是开源、跨平台 Tidy 库的托管 .NET/Mono 包装器、HTML/XHTML/XML 标记解析器和 HTML/XHTML/XML 标记解析器。清洁剂最初由 Dave Raggett 创建。

示例使用

using System;
using TidyManaged;

public class Test
{
  public static void Main(string[] args)
  {
    using (Document doc = Document.FromString("<hTml><title>test</tootle><body>asd</body>"))
    {
      doc.ShowWarnings = false;
      doc.Quiet = true;
      doc.OutputXhtml = true;
      doc.CleanAndRepair();
      string parsed = doc.Save();
      Console.WriteLine(parsed);
    }
  }
}

结果:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 13), see www.w3.org" />
<title>test</title>
</head>
<body>
asd
</body>
</html>

请注意,test</tootle></code> 已更改为正确的 <code><title>test

https://github.com/markbeaton/TidyManaged

TidyManaged is a managed .NET/Mono wrapper for the open source, cross-platform Tidy library, a HTML/XHTML/XML markup parser & cleaner originally created by Dave Raggett.

Sample Usage

using System;
using TidyManaged;

public class Test
{
  public static void Main(string[] args)
  {
    using (Document doc = Document.FromString("<hTml><title>test</tootle><body>asd</body>"))
    {
      doc.ShowWarnings = false;
      doc.Quiet = true;
      doc.OutputXhtml = true;
      doc.CleanAndRepair();
      string parsed = doc.Save();
      Console.WriteLine(parsed);
    }
  }
}

results in:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 13), see www.w3.org" />
<title>test</title>
</head>
<body>
asd
</body>
</html>

Please note that <title>test</tootle> is changed to the correct <title>test</title>.

https://github.com/markbeaton/TidyManaged

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文