Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        private GumboOptions CreateOptions(GumboWrapperOptions? options)
        {
            var defaultOptionsCopy = _GumboLibrary.MarshalStructure<GumboOptions>("kGumboDefaultOptions");

            if (options != null)
            {
                defaultOptionsCopy.max_errors = options.Value.MaxErrors;
                defaultOptionsCopy.stop_on_first_error = options.Value.StopOnFirstError;
                defaultOptionsCopy.tab_stop = options.Value.TabStopSize;
                defaultOptionsCopy.fragment_context = options.Value.FragmentContext;
                defaultOptionsCopy.fragment_namespace = options.Value.FragmentNamespace;
            }

            return defaultOptionsCopy;
        }