internal ElementWrapper(GumboElementNode node, NodeWrapper parent, WrapperFactory factory) : base(node, parent) { _Children = factory.CreateDisposalAwareLazy(() => ImmutableArray.CreateRange(node.GetChildren().OrderBy(x => x.index_within_parent).Select(x => factory.CreateNodeWrapper(x, this)))); _Attributes = factory.CreateDisposalAwareLazy(() => ImmutableArray.CreateRange(node.GetAttributes().Select(x => factory.CreateAttributeWrapper(x, this)))); _Value = factory.CreateDisposalAwareLazy(() => string.Concat(Children.Select(x => x is ElementWrapper ? ((ElementWrapper)x).Value : ((TextWrapper)x).Value))); 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)); }
public NodeWrapper(GumboNode node, NodeWrapper parent) { Type = node.type; Index = (int)node.index_within_parent; ParseFlags = node.parse_flags; Parent = parent; }
public NodeWrapper CreateNodeWrapper(GumboNode node, NodeWrapper parent = null) { switch (node.type) { case GumboNodeType.GUMBO_NODE_DOCUMENT: return(new DocumentWrapper((GumboDocumentNode)node, this)); case GumboNodeType.GUMBO_NODE_ELEMENT: case GumboNodeType.GUMBO_NODE_TEMPLATE: return(new ElementWrapper((GumboElementNode)node, parent, this)); case GumboNodeType.GUMBO_NODE_TEXT: case GumboNodeType.GUMBO_NODE_CDATA: case GumboNodeType.GUMBO_NODE_COMMENT: case GumboNodeType.GUMBO_NODE_WHITESPACE: return(new TextWrapper((GumboTextNode)node, parent)); default: throw new NotImplementedException($"Node type '{node.type}' is not implemented"); } }
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)); }
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)); }
internal TextWrapper(GumboTextNode node, NodeWrapper parent) : base(node, parent) { Text = NativeUtf8Helper.StringFromNativeUtf8(node.text.text); StartPosition = node.text.start_pos; }
public NodeWrapper(GumboNode node, NodeWrapper parent) { Type = node.type; ParseFlags = node.parse_flags; Parent = parent; }
public GumboNavigator(GumboWrapper gumbo, NodeWrapper node) { _Gumbo = gumbo; _State = new NavigatorState(node); }