AngleSharp by Florian Rappl

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

.NET API 1,172,480 bytes

 HtmlStyleElement

Represents the HTML style element.
using AngleSharp.Dom.Css; using AngleSharp.Extensions; using AngleSharp.Html; namespace AngleSharp.Dom.Html { internal sealed class HtmlStyleElement : HtmlElement, IHtmlStyleElement, IHtmlElement, IElement, INode, IEventTarget, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle, ILinkStyle { private IStyleSheet _sheet; public bool IsScoped { get { return GetAttribute(AttributeNames.Scoped) != null; } set { SetAttribute(AttributeNames.Scoped, value ? string.Empty : null); } } public IStyleSheet Sheet => _sheet ?? (_sheet = CreateSheet()); public bool IsDisabled { get { return GetAttribute(AttributeNames.Disabled).ToBoolean(false); } set { SetAttribute(AttributeNames.Disabled, value ? string.Empty : null); if (_sheet != null) _sheet.IsDisabled = value; } } public string Media { get { return GetAttribute(AttributeNames.Media); } set { SetAttribute(AttributeNames.Media, value); } } public string Type { get { return GetAttribute(AttributeNames.Type); } set { SetAttribute(AttributeNames.Type, value); } } public HtmlStyleElement(Document owner) : base(owner, Tags.Style, NodeFlags.Special | NodeFlags.LiteralText) { RegisterAttributeObserver(AttributeNames.Media, UpdateMedia); } internal override void NodeIsInserted(Node newNode) { base.NodeIsInserted(newNode); UpdateSheet(); } internal override void NodeIsRemoved(Node removedNode, Node oldPreviousSibling) { base.NodeIsRemoved(removedNode, oldPreviousSibling); UpdateSheet(); } private void UpdateMedia(string value) { if (_sheet != null) _sheet.Media.MediaText = value; } private void UpdateSheet() { if (_sheet != null) _sheet = CreateSheet(); } private IStyleSheet CreateSheet() { if (base.Owner.Options.IsStyling) { StyleOptions options = new StyleOptions { Element = this, IsDisabled = IsDisabled, Title = base.Title, IsAlternate = false }; return base.Owner.Options.ParseStyling(TextContent, options, Type); } return null; } } }