如何让 HtmlParser 在验证 html 时忽略未编码的 &
?
比如下面的代码
using AngleSharp.Html.Dom.Events;
using AngleSharp.Html.Parser;
HtmlParser parser = new(new HtmlParserOptions { IsEmbedded = true });
var errorEvents = new List<HtmlErrorEvent>();
parser.Error += (_, e) => errorEvents.Add((HtmlErrorEvent)e);
parser.ParseDocument("test&1");
foreach (var e in errorEvents)
{
Console.WriteLine(e.Message);
}
会输出验证错误
Character reference is not terminated by a semicolon.
通过 IsNotConsumingCharacterReferences
选项可以解决
HtmlParser parser = new(new HtmlParserOptions { IsEmbedded = true, IsNotConsumingCharacterReferences = true });