internal static void GetFormattedTextRecursive(XElement Xml, ref List<FormattedText> alist) { FormattedText ft = ToFormattedText(Xml); FormattedText last = null; if (ft != null) { if (alist.Any()) last = alist.Last(); // Join adjacent runs that have the same formatting and do not cross a hyperlink boundary (they must both be inside a hyperlink or both be outside) if (last != null && last.CompareTo(ft) == 0 && (last.containingHyperlinkId == null) == (ft.containingHyperlinkId == null)) { // Update text of last entry. last.text += ft.text; } else { if (last != null) ft.index = last.index + last.text.Length; alist.Add(ft); } } if (Xml.HasElements) foreach (XElement e in Xml.Elements()) GetFormattedTextRecursive(e, ref alist); }