internal static FormattedText ToFormattedText(XElement e) { // The text representation of e. String text = ToText(e); if (text == String.Empty) { return(null); } // e is a w:t element, it must exist inside a w:r element or a w:tabs, lets climb until we find it. while (!e.Name.Equals(XName.Get("r", DocX.w.NamespaceName)) && !e.Name.Equals(XName.Get("tabs", DocX.w.NamespaceName))) { e = e.Parent; } // e is a w:r element, lets find the rPr element. XElement rPr = e.Element(XName.Get("rPr", DocX.w.NamespaceName)); FormattedText ft = new FormattedText(); ft.text = text; ft.index = 0; ft.formatting = null; // Return text with formatting. if (rPr != null) { ft.formatting = Formatting.Parse(rPr); } return(ft); }
internal static FormattedText ToFormattedText(XElement e) { // The text representation of e. var text = ToText(e); if (text == string.Empty) { return(null); } // Save footnoteId for lookup string footnoteId = null; if (e.Name.Equals(XName.Get("footnoteReference", DocX.w.NamespaceName))) { footnoteId = e.GetAttribute(XName.Get("id", DocX.w.NamespaceName)); } // e is a w:t element, it must exist inside a w:r element or a w:tabs, lets climb until we find it. while (!e.Name.Equals(XName.Get("r", DocX.w.NamespaceName)) && !e.Name.Equals(XName.Get("tabs", DocX.w.NamespaceName))) { e = e.Parent; } // e is a w:r element, lets find the rPr element. XElement rPr = e.Element(XName.Get("rPr", DocX.w.NamespaceName)); // Find the id of the containing hyperlink, if any. var containingHyperlink = e.AncestorsAndSelf(XName.Get("hyperlink", DocX.w.NamespaceName)).FirstOrDefault(); var ft = new FormattedText { text = text, containingHyperlinkId = containingHyperlink != null?containingHyperlink.GetAttribute(XName.Get("id", DocX.r.NamespaceName), null) : null, footnoteId = footnoteId }; // Return text with formatting. if (rPr != null) { ft.formatting = Formatting.Parse(rPr); } return(ft); }
internal static FormattedText ToFormattedText(XElement e) { string text = ToText(e); if (text == string.Empty) { return(null); } while (!e.Name.Equals(XName.Get("r", DocX.w.NamespaceName)) && !e.Name.Equals(XName.Get("tabs", DocX.w.NamespaceName))) { e = e.Parent; } XElement xElement = e.Element(XName.Get("rPr", DocX.w.NamespaceName)); FormattedText formattedText = new FormattedText(); formattedText.text = text; formattedText.index = 0; formattedText.formatting = null; if (xElement != null) { formattedText.formatting = Formatting.Parse(xElement); } return(formattedText); }