【问题标题】:Correct html with missing <p> tag更正缺少 <p> 标签的 html
【发布时间】:2015-06-24 01:04:12
【问题描述】:

目前我正在研究纠正 HTML 的解决方案。在我们的解决方案中,我们有一个富文本编辑器,我们希望在用户忘记&lt;p&gt; 元素时更正HTML,这种情况经常发生。

var input = new StringBuilder();
input.AppendLine("<h2>title1</h2>");
input.AppendLine("text");
input.AppendLine("<h2>title2</h2>");
input.AppendLine("<p>paragraph</p>");

var expected = new StringBuilder();
expected.AppendLine("<h2>title1</h2>");
expected.AppendLine("<p>text</p>");
expected.AppendLine("<h2>title2</h2>");
expected.AppendLine("<p>paragraph</p>");

Assert.AreEqual(expected.ToString(), input.DoSomething());

HTML 敏捷包中有什么东西吗?有没有别的解决办法?

【问题讨论】:

  • 即使你不使用 HTML AP,使用 stringbuilder 也是自找麻烦,.net 中有一个内置的 HTMLDocument 类会有所改进。

标签: c# html xml


【解决方案1】:

不确定是否有帮助,但有一个类似的主题:

How to fix ill-formed HTML with HTML Agility Pack?

另外,不是您的问题,但我们使用 Markdown 编辑器而不是 HTML 编辑器取得了不错的效果。

【讨论】:

    猜你喜欢
    • 2023-01-22
    • 2015-07-04
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 2015-10-12
    • 2020-10-27
    • 1970-01-01
    • 2016-05-17
    相关资源
    最近更新 更多