public IExtensionData[] CalculateReferencedExtensionData(string content)
 {
     Hashtable datas = new Hashtable();
     ContentSourceManager.SmartContentPredicate predicate = new ContentSourceManager.SmartContentPredicate();
     SimpleHtmlParser p = new SimpleHtmlParser(content);
     for (Element el; null != (el = p.Next());)
     {
         if (predicate.IsMatch(el))
         {
             BeginTag bt = el as BeginTag;
             Attr idAttr = bt.GetAttribute("id");
             if (idAttr != null) //Synchronized WP posts will strip ID attrs (bug 488143)
             {
                 string smartContentSourceId;
                 string smartContentId;
                 string smartContentElementId = idAttr.Value;
                 ContentSourceManager.ParseContainingElementId(smartContentElementId, out smartContentSourceId, out smartContentId);
                 IExtensionData data = GetExtensionData(smartContentId);
                 if (data != null)
                     datas[smartContentId] = data;
             }
         }
     }
     return (IExtensionData[])ArrayHelper.CollectionToArray(datas.Values, typeof(IExtensionData));
 }
        /// <summary>
        /// Clones active smart content contained in the provided HTML, and disables unknown smart content.
        /// </summary>
        public static string PrepareSmartContentHtmlForEditorInsertion(string html, IContentSourceSidebarContext sourceContext)
        {
            StringBuilder output = new StringBuilder();
            ContentSourceManager.SmartContentPredicate predicate = new ContentSourceManager.SmartContentPredicate();
            SimpleHtmlParser p = new SimpleHtmlParser(html);
            for (Element el; null != (el = p.Next());)
            {
                if (predicate.IsMatch(el))
                {
                    BeginTag bt = el as BeginTag;
                    Attr idAttr = bt.GetAttribute("id");

                    String contentSourceId, contentItemId;
                    ContentSourceManager.ParseContainingElementId(idAttr.Value, out contentSourceId, out contentItemId);
                    ISmartContent smartContent = sourceContext.FindSmartContent(contentItemId);
                    if (smartContent != null)
                    {
                        String newId = Guid.NewGuid().ToString();
                        sourceContext.CloneSmartContent(contentItemId, newId);

                        if (RefreshableContentManager.ContentSourcesWithRefreshableContent.Contains(contentSourceId))
                        {
                            IExtensionData extensionData = sourceContext.FindExtentsionData(newId);
                            Debug.Assert(extensionData != null);

                            // Since we just made a new id for the smart content just about to be inserted
                            // we want to give it a chance to get a callback because its callback might have happened while
                            // it was on the clipboard(in the event of cut).  This means the refreshable content manager doesnt know
                            // to watch out for this smart content on paste, it only knows to look out for who created it.   Thus
                            // we just force the callback, and if it didnt need it, nothing will happen.
                            if (extensionData.RefreshCallBack == null)
                            {
                                extensionData.RefreshCallBack = DateTime.UtcNow;
                            }
                        }

                        idAttr.Value = ContentSourceManager.MakeContainingElementId(contentSourceId, newId);
                    }
                    else
                    {
                        ContentSourceManager.RemoveSmartContentAttributes(bt);
                    }
                }
                output.Append(el.ToString());
            }
            return output.ToString();
        }