示例#1
0
        internal DocumentWrapper(GumboDocumentNode node, WrapperFactory factory)
            : base(node, null)
        {
            _Children = factory.CreateDisposalAwareLazy(() =>
                                                        ImmutableArray.CreateRange(node.GetChildren().OrderBy(x => x.index_within_parent).Select(x => factory.CreateNodeWrapper(x, this))));

            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;
        }
示例#2
0
        internal DocumentWrapper(GumboDocumentNode node, WrapperFactory factory)
            : base(node, null)
        {
            _Children = factory.CreateDisposalAwareLazy(() =>
                ImmutableArray.CreateRange(node.GetChildren().OrderBy(x => x.index_within_parent).Select(x => factory.CreateNodeWrapper(x, this))));

            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;
        }
示例#3
0
        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);
        }
示例#4
0
        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;
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
 public static XDocument ToXDocument(this GumboDocumentNode docNode)
 {
     return((XDocument)CreateXNode(docNode));
 }
示例#8
0
 public static IEnumerable <GumboNode> GetChildren(this GumboDocumentNode node)
 {
     return(MarshalToPtrArray(node.document.children).Select(MarshalToSpecificNode));
 }