private void CreateItemCloze()
        {
            try
            {
                var parentEl = Svc.SM.UI.ElementWdw.CurrentElement;
                if (parentEl == null || parentEl.Type == ElementType.Item)
                {
                    return;
                }

                var    selObj  = ContentUtils.GetSelectionObject();
                string selText = selObj?.htmlText;
                if (selObj == null || string.IsNullOrEmpty(selText))
                {
                    return;
                }

                var htmlCtrl = ContentUtils.GetFocusedHtmlCtrl();
                var htmlDoc  = htmlCtrl?.GetDocument();
                if (htmlDoc == null)
                {
                    return;
                }

                selObj.pasteHTML("[...]");
                string questionChild = htmlDoc.body.innerHTML.Replace("[...]", "<SPAN class=cloze>[...]</SPAN>");

                int MaxTextLength = 2000000000;
                selObj.moveEnd("character", MaxTextLength);
                selObj.moveStart("character", -MaxTextLength);

                selObj.findText("[...]");
                selObj.select();

                selObj.pasteHTML("<SPAN class=clozed>" + selText + "</SPAN>");
                string parentContent = htmlDoc.body.innerHTML;

                htmlCtrl.Text = parentContent;

                var references = ReferenceParser.GetReferences(parentContent);
                CreateSMElement(RemoveReferences(questionChild), selText, references);
            }
            catch (RemotingException) { }
        }
        private void ResurrectParent()
        {
            var currentElement  = Svc.SM.UI.ElementWdw.CurrentElement;
            var parentOfCurrent = currentElement.Parent;

            var htmls = ContentUtils.GetHtmlCtrls();

            if (htmls == null || htmls.Count < 2)
            {
                LogTo.Debug("Failed to resurrect. There are less than 2 html ctrls");
                return;
            }

            var fst = htmls.FirstOrDefault();
            var lst = htmls.LastOrDefault();

            if (!fst.Text.Contains("[...]"))
            {
                LogTo.Debug("Failed to resurrect. There was no cloze marker found in the first html ctrl");
                return;
            }

            var answer = lst.Text;

            // Replace cloze marker with answer text.

            var doc = new HtmlDocument();

            doc.LoadHtml(fst.Text);
            var cloze = doc.DocumentNode.SelectSingleNode("//span[@class='cloze']");

            if (cloze == null)
            {
                LogTo.Debug("Failed to resurrect. Failed to find the cloze span.");
                return;
            }

            cloze.Attributes["class"].Remove();
            cloze.InnerHtml = answer;

            var question = doc.DocumentNode.OuterHtml;
            var refs     = ReferenceParser.GetReferences(question);

            question = RemoveReferences(question);

            if (parentOfCurrent == null)
            {
                LogTo.Debug("Failed to resurrect parent. Parent element of current was null.");
                return;
            }

            bool ret = Svc.SM.Registry.Element.Add(
                out var value,
                ElemCreationFlags.ForceCreate,
                new ElementBuilder(ElementType.Topic, new ContentBase[] { new TextContent(true, question) })
                .WithParent(parentOfCurrent)
                .WithPriority(Config.ResurrectedParentPriority)
                .WithReference(_ => refs)
                .DoNotDisplay());

            if (ret)
            {
                LogTo.Debug("Successfully resurrected parent of cloze");
            }
            else
            {
                LogTo.Error("Failed to resurrect parent of cloze");
            }
        }