AngleSharp by AngleSharp

<PackageReference Include="AngleSharp" Version="1.0.4" />

.NET API 888,832 bytes

 HtmlDocument

Represents a document node that contains only HTML nodes.
using AngleSharp.Dom; using AngleSharp.Dom.Events; using AngleSharp.Io; using AngleSharp.Mathml.Dom; using AngleSharp.Svg.Dom; using AngleSharp.Text; using System; using System.Runtime.CompilerServices; namespace AngleSharp.Html.Dom { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] internal sealed class HtmlDocument : Document, IHtmlDocument, IDocument, INode, IEventTarget, IMarkupFormattable, IParentNode, IGlobalEventHandlers, IDocumentStyle, INonElementParentNode, IDisposable { private readonly IElementFactory<Document, HtmlElement> _htmlFactory; private readonly IElementFactory<Document, MathElement> _mathFactory; private readonly IElementFactory<Document, SvgElement> _svgFactory; public override IElement DocumentElement => this.FindChild<HtmlHtmlElement>(); public override IEntityProvider Entities => base.Context.GetProvider<IEntityProvider>() ?? HtmlEntityProvider.Resolver; internal HtmlDocument([System.Runtime.CompilerServices.Nullable(2)] IBrowsingContext context, TextSource source) : base(context ?? BrowsingContext.New(null), source) { base.ContentType = MimeTypeNames.Html; _htmlFactory = base.Context.GetFactory<IElementFactory<Document, HtmlElement>>(); _mathFactory = base.Context.GetFactory<IElementFactory<Document, MathElement>>(); _svgFactory = base.Context.GetFactory<IElementFactory<Document, SvgElement>>(); } [System.Runtime.CompilerServices.NullableContext(2)] internal HtmlDocument(IBrowsingContext context = null) : this(context, new TextSource(string.Empty)) { } public HtmlElement CreateHtmlElement(string name, [System.Runtime.CompilerServices.Nullable(2)] string prefix = null, NodeFlags flags = NodeFlags.None) { return _htmlFactory.Create(this, name, prefix, flags); } public MathElement CreateMathElement(string name, [System.Runtime.CompilerServices.Nullable(2)] string prefix = null, NodeFlags flags = NodeFlags.None) { return _mathFactory.Create(this, name, prefix, flags); } public SvgElement CreateSvgElement(string name, [System.Runtime.CompilerServices.Nullable(2)] string prefix = null, NodeFlags flags = NodeFlags.None) { return _svgFactory.Create(this, name, prefix, flags); } public override Element CreateElementFrom(string name, [System.Runtime.CompilerServices.Nullable(2)] string prefix, NodeFlags flags = NodeFlags.None) { return CreateHtmlElement(name, prefix, flags); } public override Node Clone(Document owner, bool deep) { TextSource source = new TextSource(base.Source.Text); HtmlDocument htmlDocument = new HtmlDocument(base.Context, source); CloneDocument(htmlDocument, deep); return htmlDocument; } protected override string GetTitle() { IHtmlTitleElement htmlTitleElement = DocumentElement.FindDescendant<IHtmlTitleElement>(1024); return ((htmlTitleElement != null) ? htmlTitleElement.TextContent.CollapseAndStrip() : null) ?? base.GetTitle(); } [System.Runtime.CompilerServices.NullableContext(2)] protected override void SetTitle(string value) { IHtmlTitleElement htmlTitleElement = DocumentElement.FindDescendant<IHtmlTitleElement>(1024); if (htmlTitleElement == null) { IHtmlHeadElement head = base.Head; if (head == null) return; htmlTitleElement = new HtmlTitleElement(this, null); head.AppendChild(htmlTitleElement); } htmlTitleElement.TextContent = value; } } }