private ClientContentItem TransCurrentNodeToClientContentItem() { if (string.IsNullOrEmpty(content) && string.IsNullOrEmpty(link) && this.type == TagType.Default) { return(null); } var currentItem = new ClientContentItem(); if (this.type == TagType.Image) { currentItem.Text = src;//TODO:解析onclick和src currentItem.TextType = ClientTextType.Photo; if (!string.IsNullOrEmpty(link)) { currentItem.Link = link; } } else if (this.type == TagType.Breaking) { if (!string.IsNullOrEmpty(content)) { currentItem.Text = content; } else { currentItem.Text = string.Empty; } currentItem.Text += "\r\n"; currentItem.TextType = ClientTextType.Text; if (!string.IsNullOrEmpty(link)) { currentItem.Link = link; currentItem.TextType = ClientTextType.Href; } } else if (this.type == TagType.Default && !string.IsNullOrEmpty(link)) { if (!string.IsNullOrEmpty(content)) { currentItem.Text = content; } currentItem.Link = link; currentItem.TextType = ClientTextType.Href; } else { if (!string.IsNullOrEmpty(content)) { currentItem.Text = content; } currentItem.TextType = ClientTextType.Text; } return(currentItem); }
public bool JoinAbleWith(ClientContentItem curItem) { if (this.TextType == curItem.TextType) { switch (this.TextType) { case ClientTextType.Href: { return(this.Link == curItem.Link); } case ClientTextType.Text: { return(true); } } } return(false); }
public List <ClientContentItem> BackOrderTravel() { List <ClientContentItem> reList = new List <ClientContentItem>(); //后续遍历 if (ChildTags != null && ChildTags.Count > 0) { foreach (var r in ChildTags) { AddClientContentItems(ref reList, r.BackOrderTravel(), this.link); } } //访问根节点 ClientContentItem item = TransCurrentNodeToClientContentItem(); //加入根节点 if (item != null) { if (reList.Count > 0) { var lastitem = reList.Last(); if (lastitem.JoinAbleWith(item)) { lastitem.JoinWith(item); } else { reList.Add(item); } } else { reList.Add(item); } } return(reList); }
public void JoinWith(ClientContentItem curItem) { if (this.TextType == curItem.TextType) { switch (this.TextType) { case ClientTextType.Href: { if (this.Link == curItem.Link) { this.Text = (this.Text ?? String.Empty) + curItem.Text; } break; } case ClientTextType.Text: { this.Text = (this.Text ?? String.Empty) + curItem.Text; break; } } } }