internal Document(GumboDocumentNode node, GumboFactory factory) : base(node, null) { _children = factory.CreateLazy(() => ImmutableArray.CreateRange(node.GetChildren().OrderBy(x => x.index_within_parent).Select(x => factory.CreateNode(x, this)))); HasDocType = node.document.has_doctype; Name = NativeUtf8.StringFromNativeUtf8(node.document.name); PublicIdentifier = NativeUtf8.StringFromNativeUtf8(node.document.public_identifier); SystemIdentifier = NativeUtf8.StringFromNativeUtf8(node.document.system_identifier); DocTypeQuirksMode = node.document.doc_type_quirks_mode; }
public Gumbo(string html, GumboLibraryOptions?options = null) { _options = CreateOptions(options); _html = NativeUtf8.NativeUtf8FromString(html); _outputPtr = NativeMethods.gumbo_parse(_html); var output = Marshal.PtrToStructure <GumboOutput>(_outputPtr); _gumboDocumentNode = output.GetDocument(); Errors = output.GetErrors(); var lazyFactory = new LazyFactory(() => _disposed, typeof(Gumbo).Name); _gumboFactory = new GumboFactory(lazyFactory); Document = (Document)_gumboFactory.CreateNode(_gumboDocumentNode); }
internal Element(GumboElementNode node, Node parent, GumboFactory factory) : base(node, parent) { _children = factory.CreateLazy(() => ImmutableArray.CreateRange(node.GetChildren().OrderBy(x => x.index_within_parent).Select(x => factory.CreateNode(x, this)))); _attributes = factory.CreateLazy(() => ImmutableArray.CreateRange(node.GetAttributes().Select(x => factory.CreateAttribute(x, this)))); _value = factory.CreateLazy(() => string.Concat(Children.Select(x => x is Element ? ((Element)x).Value : ((Text)x).Value))); StartPosition = node.element.start_pos; EndPosition = node.element.end_pos; Tag = node.element.tag; TagNamespace = node.element.tag_namespace; OriginalTag = NativeUtf8.StringFromNativeUtf8(node.element.original_tag.data, (int)node.element.original_tag.length); OriginalTagName = GetTagNameFromOriginalTag(node.element); OriginalEndTag = NativeUtf8.StringFromNativeUtf8(node.element.original_end_tag.data, (int)node.element.original_end_tag.length); NormalizedTagName = NativeUtf8.StringFromNativeUtf8(NativeMethods.gumbo_normalized_tagname(node.element.tag)); }