private CQ Wrap(IEnumerable <IDomObject> wrapper, bool keepSiblingsTogether) { // get innermost structure CQ wrapperTemplate = EnsureCsQuery(wrapper); IDomElement wrappingEl = null; IDomElement wrappingElRoot = null; int depth = GetInnermostContainer(wrapperTemplate.Elements, out wrappingEl, out wrappingElRoot); if (wrappingEl != null) { IDomObject nextEl = null; IDomElement innerEl = null; IDomElement innerElRoot = null; foreach (IDomObject el in SelectionSet) { if (nextEl == null || (!ReferenceEquals(nextEl, el)) && !keepSiblingsTogether) { var template = wrappingElRoot.Cq().Clone(); if (el.ParentNode != null) { template.InsertBefore(el); } // This will always succceed because we tested before this loop. But we need // to run it again b/c it's a clone now GetInnermostContainer(template.Elements, out innerEl, out innerElRoot); } nextEl = el.NextSibling; innerEl.AppendChild(el); } } return(this); }
private static PlayerInfo ParseSearchResult(IDomElement result) { var cqResult = result.Cq(); var aTag = cqResult.Find("a"); var profileUrl = aTag.Attr("href"); var characterName = aTag.Text().CleanUp(); var worldName = Regex.Replace(aTag.Next("span").Text().CleanUp(), @"\(|\)", ""); var match = Regex.Match(profileUrl, "/lodestone/character/(?<profileId>[0-9]+)/"); if (match.Success) { return(new PlayerInfo(null, null) { Name = characterName, World = worldName, Id = match.Groups["profileId"].Captures[0].Value }); } return(null); }