private Paragraph AddImageAndHyperLinks(string input, Paragraph para) { var emoteList = Main.EmoteList.CheckTextForEmotes(input); emoteList.Add(MainWindow.RegexHyperLink); var paraItems = new List<ParaInfo>(); foreach (var item in emoteList) { var newItem = item; Regex r; if (item != MainWindow.RegexHyperLink) { newItem = newItem.Replace("\\", "\\\\").Replace(")", "\\)").Replace("(", "\\("); r = new Regex(newItem); } else { r = new Regex(newItem, RegexOptions.IgnoreCase); } var matches = r.Matches(input); for (int i = 0; i < matches.Count; i++) { var tempInfo = new ParaInfo(); tempInfo.start = matches[i].Index; tempInfo.end = matches[i].Length + tempInfo.start; if (CheckSpaces(input, tempInfo.start, tempInfo.end)) { tempInfo.item = item; if (item == MainWindow.RegexHyperLink) { tempInfo.item = matches[i].Value; tempInfo.isHyper = true; } paraItems.Add(tempInfo); } } } int tracker = 0; foreach (var item in paraItems.OrderBy(x => x.start)) { para.Inlines.Add(input.Substring(tracker, item.start - tracker)); if (item.isHyper) { para.Inlines.Add(addHyperLink(item.item)); } else { para.Inlines.Add(AddImageToPara(item.item)); } tracker = item.end; } para.Inlines.Add(input.Substring(tracker, input.Length - tracker)); return para; }
private Paragraph addImageAndHyperLinks(string input, Paragraph para) { var emoteList = emotes.CheckTextForEmotes(input); emoteList.Add(RegexHyperLink); var paraItems = new List <ParaInfo>(); foreach (var item in emoteList) { var newItem = item; Regex r; if (item != RegexHyperLink) { newItem = newItem.Replace("\\", "\\\\").Replace(")", "\\)").Replace("(", "\\("); r = new Regex(newItem); } else { r = new Regex(newItem, RegexOptions.IgnoreCase); } var matches = r.Matches(input); for (int i = 0; i < matches.Count; i++) { var tempInfo = new ParaInfo(); tempInfo.start = matches[i].Index; tempInfo.end = matches[i].Length + tempInfo.start; if (checkSpaces(input, tempInfo.start, tempInfo.end)) { tempInfo.item = item; if (item == RegexHyperLink) { tempInfo.item = matches[i].Value; tempInfo.isHyper = true; } paraItems.Add(tempInfo); } } } //var itemsCount = 0; //foreach (var item in input.Split(' ')) //{ // //var temp = item; // //if (!item.StartsWith("http")) // // temp = "http://" + item; // //if (temp.IsValidUrl()) // //if(Uri.IsWellFormedUriString(item, UriKind.Relative)) // Uri uri; // if(Uri.TryCreate(item, UriKind.Absolute, out uri) // && (uri.Scheme == Uri.UriSchemeHttp // || uri.Scheme == Uri.UriSchemeHttps)) // { // var tempInfo = new ParaInfo(); // tempInfo.start = itemsCount; // tempInfo.end = item.Length + tempInfo.start; // tempInfo.item = item; // tempInfo.isHyper = true; // paraItems.Add(tempInfo); // } // itemsCount += item.Length + 1; //} int tracker = 0; foreach (var item in paraItems.OrderBy(x => x.start)) { para.Inlines.Add(input.Substring(tracker, item.start - tracker)); if (item.isHyper) { para.Inlines.Add(addHyperLink(item.item)); } else { para.Inlines.Add(AddImageToPara(item.item)); } tracker = item.end; } //if (paraItems.Count == 0) //{ // para.Inlines.Add(input); //} para.Inlines.Add(input.Substring(tracker, input.Length - tracker)); return(para); }