コード例 #1
0
        /// <summary>
        /// Strips the div holding the web part from the html
        /// </summary>
        /// <param name="element">Html element holding one or more web part divs</param>
        /// <returns>Cleaned html with a placeholder for the web part div</returns>
        private string StripWebPart(IHtmlElement element)
        {
            IElement copy  = element.Clone(true) as IElement;
            var      doc   = parser.Parse(copy.OuterHtml);
            var      nodes = doc.All.Where(p => p.LocalName == "div");

            if (nodes.Count() > 0)
            {
                foreach (var node in nodes.ToList())
                {
                    if (((node as IHtmlElement) != null) && (node as IHtmlElement).ClassList.Contains("ms-rte-wpbox"))
                    {
                        var newElement = doc.CreateTextNode(webPartMarkerString);
                        node.Parent.ReplaceChild(newElement, node);
                    }
                }

                if (doc.DocumentElement.Children[1].FirstElementChild != null &&
                    doc.DocumentElement.Children[1].FirstElementChild is IHtmlDivElement)
                {
                    return(doc.DocumentElement.Children[1].FirstElementChild.InnerHtml);
                }
                else
                {
                    return(doc.DocumentElement.Children[1].InnerHtml);
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Strips the div holding the web part from the html
        /// </summary>
        /// <param name="element">Html element holding one or more web part divs</param>
        /// <returns>Cleaned html</returns>
        private string StripWebPart(IHtmlElement element)
        {
            IElement copy  = element.Clone(true) as IElement;
            var      doc   = parser.Parse(copy.OuterHtml);
            var      nodes = doc.All.Where(p => p.LocalName == "div");

            if (nodes.Count() > 0)
            {
                foreach (var node in nodes.ToList())
                {
                    if (((node as IHtmlElement) != null) && (node as IHtmlElement).ClassList.Contains("ms-rte-wpbox"))
                    {
                        node.Remove();
                    }
                }

                return(doc.DocumentElement.Children[1].InnerHtml);
            }
            else
            {
                return(null);
            }
        }