private void Link(HtmlDocNodeBeginTagA beginTagA)
 {
     _currentTagA = beginTagA;
 }
 private void EndLink()
 {
     _currentTagA = null;
 }
        public IEnumerable <OXmlElement> ToOXmlXElements(IEnumerable <HtmlDocNode> nodes, WebImage[] webImages = null, string sourceUrl = null, Dictionary <string, NamedValues <ZValue> > imagePatches = null)
        {
            _webImages    = webImages;
            _sourceUrl    = sourceUrl;
            _imagePatches = imagePatches;

            _paragraph   = null;
            _line        = null;
            _currentTagA = null;
            _htmlImages  = new List <HtmlImage>();

            //yield return new OXmlDocDefaultsParagraphPropertiesElement();
            //yield return new OXmlElement { Type = OXmlElementType.DocDefaultsParagraphProperties };
            IEnumerable <OXmlElement> elements;

            foreach (HtmlDocNode node in nodes)
            {
                elements = null;
                switch (node.Type)
                {
                case HtmlDocNodeType.BeginTag:
                    // <p> <a>
                    //element = BeginTag((HtmlDocNodeBeginTag)node);
                    HtmlDocNodeBeginTag beginTag = (HtmlDocNodeBeginTag)node;
                    if (beginTag.Tag == HtmlTagType.P)
                    {
                        elements = Paragraph();
                    }
                    else if (beginTag.Tag == HtmlTagType.A)
                    {
                        Link((HtmlDocNodeBeginTagA)beginTag);
                    }
                    break;

                case HtmlDocNodeType.EndTag:
                    HtmlDocNodeEndTag endTag = (HtmlDocNodeEndTag)node;
                    if (endTag.Tag == HtmlTagType.A)
                    {
                        EndLink();
                    }
                    break;

                case HtmlDocNodeType.Tag:
                    //HtmlDocNodeTagImg
                    // <br> <img>
                    //element = Tag((HtmlDocNodeTag)node);
                    HtmlDocNodeTag tag = (HtmlDocNodeTag)node;
                    if (tag.Tag == HtmlTagType.BR)
                    {
                        elements = NewLine();
                    }
                    else if (tag.Tag == HtmlTagType.Img)
                    {
                        //elements = Image((HtmlDocNodeTagImg)tag);
                        Image((HtmlDocNodeTagImg)tag);
                    }
                    break;

                case HtmlDocNodeType.Text:
                    //element = new OXmlTextElement { Text = ((HtmlDocNodeText)node).Text };
                    elements = Text((HtmlDocNodeText)node);
                    break;
                }
                if (elements != null)
                {
                    foreach (OXmlElement element in elements)
                    {
                        yield return(element);
                    }
                }
            }
            elements = GetImages(endOfDocument: true);
            if (elements != null)
            {
                foreach (OXmlElement element in elements)
                {
                    yield return(element);
                }
            }
        }