public GumboWrapper(string html, GumboWrapperOptions? options = null) { _Options = CreateOptions(options); _Html = NativeUtf8Helper.NativeUtf8FromString(html); _OutputPtr = NativeMethods.gumbo_parse(_Html); var output = Marshal.PtrToStructure<GumboOutput>(_OutputPtr); _GumboDocumentNode = output.GetDocument(); Errors = output.GetErrors(); var lazyFactory = new DisposalAwareLazyFactory(() => _IsDisposed, typeof(GumboWrapper).Name); _WrapperFactory = new WrapperFactory(lazyFactory); Document = (DocumentWrapper)_WrapperFactory.CreateNodeWrapper(_GumboDocumentNode); }
internal DocumentWrapper(GumboDocumentNode node, DisposalAwareLazyFactory lazyFactory, Action<string, ElementWrapper> addElementWithId) : base(node, null) { _Children = lazyFactory.Create<IEnumerable<ElementWrapper>>(() => { return node.GetChildren().Select(x => new ElementWrapper((GumboElementNode)x, this, lazyFactory, addElementWithId)).ToList().AsReadOnly(); }); HasDocType = node.document.has_doctype; Name = NativeUtf8Helper.StringFromNativeUtf8(node.document.name); PublicIdentifier = NativeUtf8Helper.StringFromNativeUtf8(node.document.public_identifier); SystemIdentifier = NativeUtf8Helper.StringFromNativeUtf8(node.document.system_identifier); DocTypeQuirksMode = node.document.doc_type_quirks_mode; }
public GumboWrapper(string html, bool stopOnFirstError = false, int maxErrors = -1, int tabStopSize = 8) { _Options = new GumboOptions(); NativeMethods.gumbo_set_options_defaults(ref _Options); _Options.max_errors = maxErrors; _Options.stop_on_first_error = stopOnFirstError; _Html = NativeUtf8Helper.NativeUtf8FromString(html); _OutputPtr = NativeMethods.gumbo_parse(_Html); var output = (GumboOutput)Marshal.PtrToStructure(_OutputPtr, typeof(GumboOutput)); _GumboDocumentNode = output.GetDocument(); Errors = output.GetErrors(); var lazyFactory = new DisposalAwareLazyFactory(() => this._Disposed, typeof(GumboWrapper).Name); Document = new DocumentWrapper(_GumboDocumentNode, lazyFactory, AddElementWithId); }
internal ElementWrapper(GumboElementNode node, NodeWrapper parent, DisposalAwareLazyFactory lazyFactory, Action<string, ElementWrapper> addElementWithId) : base(node, parent) { _Children = lazyFactory.Create<IEnumerable<NodeWrapper>>(() => { return node.GetChildren().Select(x => x is GumboElementNode ? (NodeWrapper)new ElementWrapper((GumboElementNode)x, this, lazyFactory, addElementWithId) : (NodeWrapper)new TextWrapper((GumboTextNode)x, this)).ToList().AsReadOnly(); }); _Attributes = lazyFactory.Create<IEnumerable<AttributeWrapper>>(() => { return node.GetAttributes().Select((x, i) => new AttributeWrapper(x, this, i, addElementWithId)).ToList(); }); _Value = lazyFactory.Create<string>(() => { return String.Concat(this.Children.Select(x => x is ElementWrapper ? ((ElementWrapper)x).Value : ((TextWrapper)x).Text)); }); StartPosition = node.element.start_pos; EndPosition = node.element.end_pos; Tag = node.element.tag; TagNamespace = node.element.tag_namespace; OriginalTag = NativeUtf8Helper.StringFromNativeUtf8( node.element.original_tag.data, (int)node.element.original_tag.length); OriginalTagName = GetTagNameFromOriginalTag(node.element); OriginalEndTag = NativeUtf8Helper.StringFromNativeUtf8( node.element.original_end_tag.data, (int)node.element.original_end_tag.length); NormalizedTagName = NativeUtf8Helper.StringFromNativeUtf8( NativeMethods.gumbo_normalized_tagname(node.element.tag)); }