private static string HtmlToXml(TrainingModule trainingModule)
        {
            var html = string.Copy(trainingModule.DocumentHtml);
            var mlp = new MlParser();
            string searchString;
            string value;
            string tag;

            #region Парсинг закладки

            searchString = "class=bookmark";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("id");

                tag = string.Concat("<anchor id=\"", value, "\" name_anchor=\"",
                                    Warehouse.Warehouse.GetBookmarkNameById(new Guid(value)), "\"></anchor>");

                mlp.ShiftLastIndex(ref html);
                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);
            }

            #endregion

            #region Парсинг компетенции

            searchString = "class=concept";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                mlp.ShiftLastIndex(ref html);

                tag = string.Concat("<glossary_definition concept_id=\"#elem{", mlp.GetValue("id").ToUpper(),
                                    "}\" index=\"1\">", mlp.GetInnerHtml(),
                                    "</glossary_definition>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);
            }

            #endregion

            #region Парсинг ссылки на закладку

            searchString = "class=linktobookmark";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                mlp.ShiftLastIndex(ref html);

                tag = string.Concat("<ref type=\"reference\" linkitem_id=\"", ExtractRelativeHref(mlp.GetValue("href")),
                                    "\">", mlp.GetInnerHtml(), "</ref>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);
            }

            #endregion

            #region Парсинг ссылки на внутреннюю компетенцию

            searchString = "class=linktointernalconcept";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                mlp.ShiftLastIndex(ref html);

                tag = string.Concat("<ref type=\"concept\" linkitem_id=\"#elem{", ExtractRelativeHref(mlp.GetValue("href")).ToUpper(),
                                    "}\">", mlp.GetInnerHtml(), "</ref>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);
            }

            #endregion

            #region Парсинг ссылки на внешнюю компетенцию

            // Парсинга не происходит.
            // При нажатии на ссылку выдает сообщение "Ссылка на внешнюю компетенцию не настроена".

            #endregion

            #region Парсинг ссылки на модуль

            searchString = "class=linktotrainingmodule";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                mlp.ShiftLastIndex(ref html);

                tag = string.Concat("<ref type=\"module\" linkitem_id=\"#module{", ExtractRelativeHref(mlp.GetValue("href")).ToUpper(),
                                    "}\">", mlp.GetInnerHtml(), "</ref>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);
            }

            #endregion

            #region Парсинг рисунка, анимации, аудио, видео, ссылки на них, формулы

            searchString = "<IMG";
            while (html.Contains(searchString))
            {
                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("src_");
                if (!value.Equals(string.Empty))
                {
                    value = value.Substring(0, value.IndexOf("\\"));
                }
                // value может быть равно Flashes, Images или string.Empty.
                // value равно string.Empty, если обрабатывается рисунок или формула.

                if (value.Equals(Warehouse.Warehouse.RelativeFlashesDirectory))
                {
                    value = mlp.GetValue("sdocument");

                    if (value.Equals("0"))
                    {
                        #region Анимация

                        tag = string.Concat("<flash src=\"" + mlp.GetValue("src_"),
                                            "\" width=\"", "835",
                                            "\" height=\"", "615",
                                            "\" view=\"0\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                    else if (value.Equals("1"))
                    {
                        #region Ссылка на анимацию

                        tag = string.Concat("<flash src=\"" + mlp.GetValue("src_"),
                                            "\" width=\"", "835",
                                            "\" height=\"", "615",
                                            "\" title=\"", mlp.GetValue("alt"),
                                            "\" view=\"1\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                }
                else if (value.Equals(Warehouse.Warehouse.RelativeImagesDirectory) ||
                    value == string.Empty)
                {
                    value = mlp.GetValue("sdocument");

                    if (value.Equals("0"))
                    {
                        #region Рисунок

                        var src = mlp.GetValue("src");
                        src = ExtractRelativeSrc(src);
                        var width = mlp.GetValue("width");
                        var height = mlp.GetValue("height");

                        if (width == string.Empty || height == string.Empty)
                        {
                            var src_ = Path.Combine(Warehouse.Warehouse.ProjectEditorLocation, src);
                            var imageDimension = System.Drawing.Image.FromFile(src_).PhysicalDimension;
                            width = imageDimension.Width.ToString();
                            height = imageDimension.Height.ToString();
                        }

                        tag = string.Concat("<image src=\"", src,
                                            "\" width=\"", width,
                                            "\" height=\"", height);

                        var attribute = mlp.GetValue("style");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" style=\"", attribute);
                        }

                        attribute = mlp.GetValue("title");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" title=\"", attribute);
                        }

                        attribute = mlp.GetValue("align");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" align=\"", attribute);
                        }

                        attribute = mlp.GetValue("border");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" border=\"", attribute);
                        }

                        attribute = mlp.GetValue("hspace");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" hspace=\"", attribute);
                        }

                        attribute = mlp.GetValue("vspace");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" vspace=\"", attribute);
                        }

                        tag += "\" view=\"0\" />";

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                    else if (value.Equals("1"))
                    {
                        #region Ссылка на рисунок

                        var src = mlp.GetValue("src_");
                        var width = mlp.GetValue("width_");
                        var height = mlp.GetValue("height_");

                        if (width == string.Empty || height == string.Empty)
                        {
                            var src_ = Path.Combine(Warehouse.Warehouse.ProjectEditorLocation, src);
                            var imageDimension = System.Drawing.Image.FromFile(src_).PhysicalDimension;
                            width = imageDimension.Width.ToString();
                            height = imageDimension.Height.ToString();
                        }

                        tag = string.Concat("<image title=\"", mlp.GetValue("alt"), "\" src=\"", src, "\" width=\"",
                                            width, "\" height=\"", height);

                        var attribute = mlp.GetValue("align_");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" align=\"", attribute);
                        }

                        attribute = mlp.GetValue("border_");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" border=\"", attribute);
                        }

                        attribute = mlp.GetValue("hspace_");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" hspace=\"", attribute);
                        }

                        attribute = mlp.GetValue("vspace_");
                        if (!attribute.Equals(string.Empty))
                        {
                            tag += string.Concat("\" vspace=\"", attribute);
                        }

                        tag += "\" view=\"1\" />";

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                    else if (value.Equals(string.Empty))
                    {
                        #region Формула

                        var src = mlp.GetValue("src");
                        src = ExtractRelativeSrc(src);

                        tag = string.Concat("<image src=\"", src,"\" align=\"",
                                            mlp.GetValue("align"), "\" longDesc=\"",
                                            mlp.GetValue("longDesc"), "\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                }
                else if (value.Equals(Warehouse.Warehouse.RelativeAudiosDirectory))
                {
                    value = mlp.GetValue("sdocument");

                    if (value.Equals("0"))
                    {
                        #region Аудио

                        tag = string.Concat("<audio src=\"" + mlp.GetValue("src_"),
                                            "\" view=\"0\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                    else if (value.Equals("1"))
                    {
                        #region Ссылка на аудио

                        tag = string.Concat("<audio src=\"" + mlp.GetValue("src_"),
                                            "\" title=\"", mlp.GetValue("alt"),
                                            "\" view=\"1\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                }
                else if (value.Equals(Warehouse.Warehouse.RelativeVideosDirectory))
                {
                    value = mlp.GetValue("sdocument");

                    if (value.Equals("0"))
                    {
                        #region Видео

                        tag = string.Concat("<video src=\"" + mlp.GetValue("src_"),
                                            "\" view=\"0\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                    else if (value.Equals("1"))
                    {
                        #region Ссылка на видео

                        tag = string.Concat("<video src=\"" + mlp.GetValue("src_"),
                                            "\" title=\"", mlp.GetValue("alt"),
                                            "\" view=\"1\" />");

                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, tag);

                        #endregion
                    }
                }
            }

            #endregion

            #region Парсинг греческих символов

            var greekSymbols = Regex.Matches(html, "[Α-Ωα-ω¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿™•∑∏∫∂√∞ƒ≤≥≠≡…′″∃∈∋∧∨∩∪∼≈⊂⊃⊆⊇⊕⊥°→×÷∀]", RegexOptions.IgnoreCase);
            int index;

            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    var symbol = greekSymbols[i - 1].Value;
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, string.Concat("&#", char.ConvertToUtf32(symbol, 0), ";"));
                }
            }

            greekSymbols = Regex.Matches(html, "[Ë]", RegexOptions.IgnoreCase);
            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, "&Euml;");
                }
            }

            greekSymbols = Regex.Matches(html, "[Ï]", RegexOptions.IgnoreCase);
            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, "&Iuml;");
                }
            }

            greekSymbols = Regex.Matches(html, "[Æ]", RegexOptions.IgnoreCase);
            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, "&AElig;");
                }
            }

            greekSymbols = Regex.Matches(html, "[Ä]", RegexOptions.IgnoreCase);
            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, "&Auml;");
                }
            }

            greekSymbols = Regex.Matches(html, "[Þ]", RegexOptions.IgnoreCase);
            if (greekSymbols.Count != 0)
            {
                for (var i = greekSymbols.Count; i > 0; i--)
                {
                    index = greekSymbols[i - 1].Index;
                    html = html.Remove(index, 1);
                    html = html.Insert(index, "&THORN;");
                }
            }

            #endregion

            // POSTPONE: Протестировать.
            //html = Regex.Replace(html, "<[ \n\t]*/[ \n\t]*sup[ \n\t]*>", "</SUP>", RegexOptions.IgnoreCase);

            return html;
        }
        public string XmlToHtml(string documentHtml)
        {
            var html = string.Copy(documentHtml);
            var mlp = new MlParser();
            string searchString;
            string value;
            string tag;

            #region Парсинг закладки

            searchString = "<anchor";
            while (html.Contains(searchString))
            {
                Application.DoEvents();

                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("id");
                value = value.ToLower();
                mlp.ShiftLastIndex(ref html);

                // Заменяет id закладки типа #a1 на Guid.
                if (!value.Length.Equals(36))
                {
                    value = ((Guid)BookmarksIds[value]).ToString();
                }

                tag = string.Concat("<A id=", value, " class=bookmark></A>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);

                var b = new Bookmark
                {
                    Id = new Guid(value),
                    ModuleId = trainingModule.Id,
                    Text = mlp.GetValue("name_anchor")
                };
                Warehouse.Warehouse.Instance.Bookmarks.Add(b);
            }

            #endregion

            #region Парсинг компетенции

            searchString = "<glossary_definition";
            while (html.Contains(searchString))
            {
                Application.DoEvents();

                mlp.GetTagBounds(html, searchString);
                if (html[mlp.StartIndex] == '<' && html[mlp.StartIndex + 1] != '/')
                {
                    value = mlp.GetValue("concept_id");
                    value = value.Substring(6, 36);
                    value = value.ToLower();
                    mlp.ShiftLastIndex(ref html);

                    tag = string.Concat("<A id=", value, " class=concept>", mlp.GetInnerHtml(), "</A>");

                    html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                    html = html.Insert(mlp.StartIndex, tag);
                }
            }

            #endregion

            #region Парсинг ссылки на закладку

            searchString = "type=\"reference\"";
            while (html.Contains(searchString))
            {
                Application.DoEvents();

                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("linkitem_id");
                value = value.ToLower();
                // Заменяет id закладки типа #a1 на Guid.
                if (!value.Length.Equals(36))
                {
                    value = ((Guid)BookmarksIds[value]).ToString();
                }

                mlp.ShiftLastIndex(ref html);

                tag = string.Concat("<A href=", value, " class=linktobookmark>", mlp.GetInnerHtml(), "</A>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);

                var lto = new LinkToObject();
                lto.TrainingModule = trainingModule;
                lto.ObjectId = new Guid(value);
                Warehouse.Warehouse.Instance.LinksToObjects.Add(lto);
            }

            #endregion

            #region Парсинг ссылки на внутреннюю компетенцию

            searchString = "type=\"concept\"";
            while (html.Contains(searchString))
            {
                Application.DoEvents();

                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("linkitem_id");
                value = value.Substring(6, 36);
                value = value.ToLower();
                mlp.ShiftLastIndex(ref html);

                tag = string.Concat("<A href=", value, " class=linktointernalconcept>", mlp.GetInnerHtml(), "</A>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);

                LinkToObject lto = new LinkToObject();
                lto.TrainingModule = trainingModule;
                lto.ObjectId = new Guid(value);
                Warehouse.Warehouse.Instance.LinksToObjects.Add(lto);
            }

            #endregion

            #region Парсинг ссылки на модуль

            searchString = "type=\"module\"";
            while (html.Contains(searchString))
            {
                Application.DoEvents();

                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("linkitem_id");
                value = value.Substring(8, 36);
                value = value.ToLower();
                mlp.ShiftLastIndex(ref html);

                tag = string.Concat("<A href=", value, " class=linktotrainingmodule>", mlp.GetInnerHtml(), "</A>");

                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                html = html.Insert(mlp.StartIndex, tag);

                LinkToObject lto = new LinkToObject();
                lto.TrainingModule = trainingModule;
                lto.ObjectId = new Guid(value);
                Warehouse.Warehouse.Instance.LinksToObjects.Add(lto);
            }

            #endregion

            #region Парсинг рисунка, ссылки на рисунок, формулы

            searchString = "<image";
            while (html.Contains(searchString))
            {
                Application.DoEvents();

                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("view");

                if (value.Equals("0"))
                {
                    #region Рисунок

                    var src = mlp.GetValue("src");
                    var width = mlp.GetValue("width");
                    var height = mlp.GetValue("height");

                    if (width == string.Empty || height == string.Empty)
                    {
                        var src_ = Path.Combine(Warehouse.Warehouse.ProjectEditorLocation, src);
                        var imageDimension = System.Drawing.Image.FromFile(src_).PhysicalDimension;
                        width = imageDimension.Width.ToString();
                        height = imageDimension.Height.ToString();
                    }

                    tag = string.Concat("<IMG src=\"", src,
                                        "\" width=\"", width,
                                        "\" height=\"", height);

                    var attribute = mlp.GetValue("style");
                    if (!attribute.Equals(string.Empty))
                    {
                        tag += string.Concat("\" style=\"", attribute);
                    }

                    attribute = mlp.GetValue("title");
                    if (!attribute.Equals(string.Empty))
                    {
                        tag += string.Concat("\" title=\"", attribute);
                    }

                    attribute = mlp.GetValue("align");
                    if (!attribute.Equals(string.Empty))
                    {
                        tag += string.Concat("\" align=\"", attribute);
                    }

                    attribute = mlp.GetValue("border");
                    if (!attribute.Equals(string.Empty))
                    {
                        tag += string.Concat("\" border=\"", attribute);
                    }

                    attribute = mlp.GetValue("hspace");
                    if (!attribute.Equals(string.Empty))
                    {
                        tag += string.Concat("\" hspace=\"", attribute);
                    }

                    attribute = mlp.GetValue("vspace");
                    if (!attribute.Equals(string.Empty))
                    {
                        tag += string.Concat("\" vspace=\"", attribute);
                    }

                    tag += string.Concat("\" sdocument=0>");

                    html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                    html = html.Insert(mlp.StartIndex, tag);

                    #endregion
                }
                else if (value.Equals("1"))
                {
                    #region Ссылка на рисунок

                    var src = mlp.GetValue("src");
                    var width = mlp.GetValue("width");
                    var height = mlp.GetValue("height");

                    if (width == string.Empty || height == string.Empty)
                    {
                        var src_ = Path.Combine(Warehouse.Warehouse.ProjectEditorLocation, src);
                        var imageDimension = System.Drawing.Image.FromFile(src_).PhysicalDimension;
                        width = imageDimension.Width.ToString();
                        height = imageDimension.Height.ToString();
                    }

                    tag = string.Concat("<IMG src=\"Images\\Pic.png\"",
                                        " src_=\"", mlp.GetValue("src"),
                                        "\" alt=\"", mlp.GetValue("title"),
                                        "\" width_=\"", mlp.GetValue("width"),
                                        "\" height_=\"", mlp.GetValue("height"));

                    var attribute = mlp.GetValue("align");
                    if (!attribute.Equals(string.Empty))
                    {
                        tag += string.Concat("\" align_=\"", attribute);
                    }

                    attribute = mlp.GetValue("border");
                    if (!attribute.Equals(string.Empty))
                    {
                        tag += string.Concat("\" border_=\"", attribute);
                    }

                    attribute = mlp.GetValue("hspace");
                    if (!attribute.Equals(string.Empty))
                    {
                        tag += string.Concat("\" hspace_=\"", attribute);
                    }

                    attribute = mlp.GetValue("vspace");
                    if (!attribute.Equals(string.Empty))
                    {
                        tag += string.Concat("\" vspace_=\"", attribute);
                    }

                    tag += string.Concat("\" sdocument=1>");

                    html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                    html = html.Insert(mlp.StartIndex, tag);

                    #endregion
                }
                else if (value.Equals(string.Empty))
                {
                    #region Формула

                    tag = string.Concat("<IMG src=\"", mlp.GetValue("src"),"\" align=\"",
                                            mlp.GetValue("align"), "\" longDesc=\"",
                                mlp.GetValue("longDesc"), "\" />");

                    html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                    html = html.Insert(mlp.StartIndex, tag);

                    #endregion
                }
            }

            #endregion

            #region Парсинг анимации, ссылки на анимацию

            searchString = "<flash";
            while (html.Contains(searchString))
            {
                Application.DoEvents();

                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("view");

                if (value.Equals("0"))
                {
                    #region Анимация

                    tag = string.Concat("<IMG src=\"Images\\Anim.png",
                                        "\" src_=\"", mlp.GetValue("src"),
                                        "\" sdocument=0>");

                    html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                    html = html.Insert(mlp.StartIndex, tag);

                    #endregion
                }
                else if (value.Equals("1"))
                {
                    #region Ссылка на анимацию

                    tag = string.Concat("<IMG src=\"Images\\Anim.png",
                                        "\" src_=\"", mlp.GetValue("src"),
                                        "\" alt=\"", mlp.GetValue("title"),
                                        "\" sdocument=1>");

                    html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                    html = html.Insert(mlp.StartIndex, tag);

                    #endregion
                }
            }

            #endregion

            #region Парсинг аудио, ссылки на аудио

            searchString = "<audio";
            while (html.Contains(searchString))
            {
                Application.DoEvents();

                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("view");

                if (value.Equals("0"))
                {
                    #region Аудио

                    tag = string.Concat("<IMG src=\"Images\\Aud.png",
                                        "\" src_=\"", mlp.GetValue("src"),
                                        "\" sdocument=0>");

                    html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                    html = html.Insert(mlp.StartIndex, tag);

                    #endregion
                }
                else if (value.Equals("1"))
                {
                    #region Ссылка на аудио

                    tag = string.Concat("<IMG src=\"Images\\Aud.png",
                                        "\" src_=\"", mlp.GetValue("src"),
                                        "\" alt=\"", mlp.GetValue("title"),
                                        "\" sdocument=1>");

                    html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                    html = html.Insert(mlp.StartIndex, tag);

                    #endregion
                }
            }

            #endregion

            #region Парсинг видело, ссылки на видео

            searchString = "<video";
            while (html.Contains(searchString))
            {
                Application.DoEvents();

                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("view");

                if (value.Equals("0"))
                {
                    #region Видео

                    tag = string.Concat("<IMG src=\"Images\\Vid.png",
                                        "\" src_=\"", mlp.GetValue("src"),
                                        "\" sdocument=0>");

                    html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                    html = html.Insert(mlp.StartIndex, tag);

                    #endregion
                }
                else if (value.Equals("1"))
                {
                    #region Ссылка на видео

                    tag = string.Concat("<IMG src=\"Images\\Vid.png",
                                        "\" src_=\"", mlp.GetValue("src"),
                                        "\" alt=\"", mlp.GetValue("title"),
                                        "\" sdocument=1>");

                    html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                    html = html.Insert(mlp.StartIndex, tag);

                    #endregion
                }
            }

            #endregion

            return html;
        }
        public static void ReadBookmarksIds(string documentHtml)
        {
            var html = string.Copy(documentHtml);
            var mlp = new MlParser();
            string searchString;
            string value;

            searchString = "<anchor";
            while (html.Contains(searchString))
            {
                Application.DoEvents();

                mlp.GetTagBounds(html, searchString);
                value = mlp.GetValue("id");
                value = value.ToLower();

                // Заменяет id закладки типа #a1 на Guid.
                if (!value.Length.Equals(36))
                {
                    if (!BookmarksIds.ContainsKey(value))
                    {
                        BookmarksIds.Add(value, Guid.NewGuid());
                    }
                }

                mlp.ShiftLastIndex(ref html);
                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
            }
        }
        public override void Execute(object @object)
        {
            if (!Enabled)
            {
                return;
            }

            var ct = Warehouse.Warehouse.Instance.ConceptTree;
            var c = ct.CurrentNode;

            if (c == null)
            {
                return;
            }

            if (MessageBox.Show(deleteConceptMessage, System.Windows.Forms.Application.ProductName, 
                MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
            {
                return;
            }

            // Удаляет компетенцию из дерева компетенций.
            ct.Nodes.Remove(c);

            if (c.Type.Equals(Enums.ConceptType.Internal))
            {
                // Удаляет компетенцию из выходов.
                c.OutDummyConcept.Parent.Nodes.Remove(c.OutDummyConcept);

                // Удаляет компетенцию из входов.
                foreach (var idc in c.InDummyConcepts)
                {
                    idc.Parent.Nodes.Remove(idc);
                }
                c.InDummyConcepts.Clear();

                // Удаляет компетенцию из Html-кода.
                var tm = Warehouse.Warehouse.GetTrainingModuleById(c.ModuleId);
                if (tm.TrainingModuleDocument == null)
                {
                    #region Документ не создан

                    var html = string.Copy(tm.DocumentHtml);
                    var mlp = new MlParser();
                    string searchString;
                    string innerHtml;

                    searchString = c.Id.ToString();
                    while (html.Contains(searchString))
                    {
                        mlp.GetTagBounds(html, searchString);
                        mlp.ShiftLastIndex(ref html);

                        innerHtml = mlp.GetInnerHtml();
                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, innerHtml);
                    }

                    tm.DocumentHtml = html;

                    #endregion
                }
                else
                {
                    #region Документ создан

                    var html = string.Copy(tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                    var mlp = new MlParser();
                    string searchString;
                    string innerHtml;

                    searchString = c.Id.ToString();
                    while (html.Contains(searchString))
                    {
                        mlp.GetTagBounds(html, searchString);
                        mlp.ShiftLastIndex(ref html);

                        innerHtml = mlp.GetInnerHtml();
                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, innerHtml);
                    }

                    tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html;

                    #endregion
                }

                // Удаляет ссылки на компетенцию.
                foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
                {
                    if (lto.ObjectId.Equals(c.Id))
                    {
                        if (lto.TrainingModule.TrainingModuleDocument == null)
                        {
                            #region Документ не создан

                            var html_ = string.Copy(lto.TrainingModule.DocumentHtml);
                            var mlp_ = new MlParser();
                            string searchString_;
                            string innerHtml;

                            searchString_ = lto.ObjectId.ToString();
                            while (html_.Contains(searchString_))
                            {
                                mlp_.GetTagBounds(html_, searchString_);
                                mlp_.ShiftLastIndex(ref html_);

                                innerHtml = mlp_.GetInnerHtml();
                                html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                            }

                            lto.TrainingModule.DocumentHtml = html_;

                            #endregion
                        }
                        else
                        {
                            #region Документ создан

                            var html_ = string.Copy(lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                            var mlp_ = new MlParser();
                            string searchString_;
                            string innerHtml;

                            searchString_ = lto.ObjectId.ToString();
                            while (html_.Contains(searchString_))
                            {
                                mlp_.GetTagBounds(html_, searchString_);
                                mlp_.ShiftLastIndex(ref html_);

                                innerHtml = mlp_.GetInnerHtml();
                                html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                            }

                            lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html_;

                            #endregion
                        }
                    }
                }
            }

            if (ct.Nodes.Count.Equals(0))
            {
                ct.CurrentNode = null;
            }

            Warehouse.Warehouse.IsProjectModified = true;
        }
        private void Delete()
        {
            if (MessageBox.Show(deleteBookmarkMessage, Application.ProductName, 
                MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                var b = bookmarkTree.CurrentNode;

                // Удаляет закладку из дерева закладок.
                bookmarkTree.Nodes.Remove(b);

                if (bookmarkTree.Nodes.Count.Equals(0))
                {
                    bookmarkTree.CurrentNode = null;
                }

                // Удаляет закладку из списка закладок.
                Warehouse.Warehouse.Instance.Bookmarks.Remove(b);

                // Удаляет закладку из Html-кода.
                var tm = Warehouse.Warehouse.GetTrainingModuleById(b.ModuleId);
                if (tm.TrainingModuleDocument == null)
                {
                    #region Документ не создан

                    var html = tm.DocumentHtml;
                    var mlp = new MlParser();
                    string searchString;
                    string value;
                    int index;

                    searchString = "class=bookmark";
                    index = 0;
                    while (html.Contains(searchString))
                    {
                        mlp.GetTagBounds(html, searchString, index);
                        value = mlp.GetValue("id");
                        mlp.ShiftLastIndex(ref html);

                        if (value.Equals(b.Id.ToString()))
                        {
                            html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                            index = mlp.StartIndex;
                        }
                        else
                        {
                            index = mlp.LastIndex;
                        }

                        if (index == mlp.StartIndex)
                        {
                            break;
                        }
                    }

                    tm.DocumentHtml = html;

                    #endregion
                }
                else
                {
                    #region Документ создан

                    var html = tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml;
                    var mlp = new MlParser();
                    string searchString;
                    string value;
                    int index;

                    searchString = "class=bookmark";
                    index = 0;
                    while (html.Contains(searchString))
                    {
                        mlp.GetTagBounds(html, searchString, index);
                        value = mlp.GetValue("id");
                        mlp.ShiftLastIndex(ref html);

                        if (value.Equals(b.Id.ToString()))
                        {
                            html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                            index = mlp.StartIndex;
                        }
                        else
                        {
                            index = mlp.LastIndex;
                        }

                        if (index == mlp.StartIndex)
                        {
                            break;
                        }
                    }

                    tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html;   

                    #endregion
                }

                // Удаляет ссылки на закладку.
                foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
                {
                    if (lto.ObjectId.Equals(b.Id))
                    {
                        //MessageBox.Show(lto.TrainingModule.Text);
                        if (lto.TrainingModule.TrainingModuleDocument == null)
                        {
                            #region Документ не создан

                            var html_ = string.Copy(lto.TrainingModule.DocumentHtml);
                            var mlp_ = new MlParser();
                            string searchString_;
                            string innerHtml;

                            searchString_ = lto.ObjectId.ToString();
                            while (html_.Contains(searchString_))
                            {
                                mlp_.GetTagBounds(html_, searchString_);
                                mlp_.ShiftLastIndex(ref html_);

                                innerHtml = mlp_.GetInnerHtml();
                                html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                            }

                            lto.TrainingModule.DocumentHtml = html_;

                            #endregion
                        }
                        else
                        {
                            #region Документ создан

                            var html_ = string.Copy(lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                            var mlp_ = new MlParser();
                            string searchString_;
                            string innerHtml;

                            searchString_ = lto.ObjectId.ToString();
                            while (html_.Contains(searchString_))
                            {
                                mlp_.GetTagBounds(html_, searchString_);
                                mlp_.ShiftLastIndex(ref html_);

                                innerHtml = mlp_.GetInnerHtml();
                                html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                            }

                            lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html_;

                            #endregion
                        }
                    }
                }

                CheckState();
            }
        }
        private void VisualHtmlEditor_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.Equals(Keys.Delete))
            {
                if (!HtmlEditingTool.IsSelection)
                {
                    if (HtmlEditingTool.ActiveElement.TagName == TagNames.AnchorTagName)
                    {
                        if (HtmlEditingTool.ActiveElement.OuterHtml.Contains("class=bookmark"))
                        {
                            #region Удаление закладки

                            Bookmark bm = null;

                            foreach (var b in Warehouse.Warehouse.Instance.Bookmarks)
                            {
                                if (HtmlEditingTool.ActiveElement.Id.Equals(b.Id.ToString()))
                                {
                                    bm = b;
                                    break;
                                }
                            }

                            if (bm != null)
                            {
                                Warehouse.Warehouse.Instance.Bookmarks.Remove(bm);
                            }

                            // Удаляет ссылки на закладку.
                            foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
                            {
                                if (lto.ObjectId.Equals(bm.Id))
                                {
                                    if (lto.TrainingModule.TrainingModuleDocument == null)
                                    {
                                        #region Документ не создан

                                        var html_ = string.Copy(lto.TrainingModule.DocumentHtml);
                                        var mlp_ = new MlParser();
                                        string searchString_;
                                        string value;
                                        int index;
                                        string innerHtml;

                                        searchString_ = lto.ObjectId.ToString();
                                        index = 0;
                                        while (html_.Contains(searchString_))
                                        {
                                            mlp_.GetTagBounds(html_, searchString_, index);
                                            mlp_.ShiftLastIndex(ref html_);

                                            value = mlp_.GetValue("class");
                                            if (value.Equals("linktobookmark"))
                                            {
                                                innerHtml = mlp_.GetInnerHtml();
                                                html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                                html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                                                index = mlp_.StartIndex;
                                            }
                                            else
                                            {
                                                index = mlp_.LastIndex;
                                            }

                                            if (index == mlp_.StartIndex)
                                            {
                                                break;
                                            }
                                        }

                                        lto.TrainingModule.DocumentHtml = html_;

                                        #endregion
                                    }
                                    else
                                    {
                                        #region Документ создан

                                        var html_ = string.Copy(lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                                        var mlp_ = new MlParser();
                                        string searchString_;
                                        string value;
                                        int index;
                                        string innerHtml;

                                        searchString_ = lto.ObjectId.ToString();
                                        index = 0;
                                        while (html_.Contains(searchString_))
                                        {
                                            mlp_.GetTagBounds(html_, searchString_, index);
                                            mlp_.ShiftLastIndex(ref html_);

                                            value = mlp_.GetValue("class");
                                            if (value.Equals("linktobookmark"))
                                            {
                                                innerHtml = mlp_.GetInnerHtml();
                                                html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                                html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                                                index = mlp_.StartIndex;
                                            }
                                            else
                                            {
                                                index = mlp_.LastIndex;
                                            }

                                            if (index == mlp_.StartIndex)
                                            {
                                                break;
                                            }
                                        }

                                        lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html_;

                                        #endregion
                                    }
                                }
                            }

                            #endregion
                        }
                    }

                    var mlp = new MlParser();
                    string searchString;

                    #region Удаление закладок

                    if (bookmarks != null)
                    {
                        var html = HtmlEditingTool.BodyInnerHtml;

                        foreach (var b in bookmarks)
                        {
                            // Удаляет закладку из списка.
                            Warehouse.Warehouse.Instance.Bookmarks.Remove(b);

                            searchString = b.Id.ToString();
                            while (html.Contains(searchString))
                            {
                                mlp.GetTagBounds(html, searchString);
                                mlp.ShiftLastIndex(ref html);

                                var innerHtml = mlp.GetInnerHtml();
                                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                                html = html.Insert(mlp.StartIndex, innerHtml);
                            }

                            // Удаляет ссылки на закладку.
                            foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
                            {
                                if (lto.ObjectId.Equals(b.Id))
                                {
                                    if (lto.TrainingModule.TrainingModuleDocument == null)
                                    {
                                        #region Документ не создан

                                        var html_ = string.Copy(lto.TrainingModule.DocumentHtml);
                                        var mlp_ = new MlParser();
                                        string searchString_;
                                        string innerHtml;

                                        searchString_ = lto.ObjectId.ToString();
                                        while (html_.Contains(searchString_))
                                        {
                                            mlp_.GetTagBounds(html_, searchString_);
                                            mlp_.ShiftLastIndex(ref html_);

                                            innerHtml = mlp_.GetInnerHtml();
                                            html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                            html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                                        }

                                        lto.TrainingModule.DocumentHtml = html_;

                                        #endregion
                                    }
                                    else
                                    {
                                        #region Документ создан

                                        var html_ = string.Copy(lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                                        var mlp_ = new MlParser();
                                        string searchString_;
                                        string innerHtml;

                                        searchString_ = lto.ObjectId.ToString();
                                        while (html_.Contains(searchString_))
                                        {
                                            mlp_.GetTagBounds(html_, searchString_);
                                            mlp_.ShiftLastIndex(ref html_);

                                            innerHtml = mlp_.GetInnerHtml();
                                            html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                            html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                                        }

                                        lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html_;

                                        #endregion
                                    }
                                }
                            }
                        }

                        HtmlEditingTool.BodyInnerHtml = html;
                    }

                    #endregion

                    #region Удаление компетенций

                    if (concepts != null)
                    {
                        var html = HtmlEditingTool.BodyInnerHtml;

                        foreach (var c in concepts)
                        {
                            // Удаляет компетенцию из дерева компетенций. 
                            Warehouse.Warehouse.Instance.ConceptTree.Nodes.Remove(c);

                            // Удаляет компетенцию из выходов.
                            // Если уже была удалена такая компетенция.
                            if (c.OutDummyConcept.Parent != null)
                            {
                                c.OutDummyConcept.Parent.Nodes.Remove(c.OutDummyConcept);
                            }

                            // Удаляет компетенцию из входов.
                            foreach (var idc in c.InDummyConcepts)
                            {
                                idc.Parent.Nodes.Remove(idc);
                            }
                            c.InDummyConcepts.Clear();

                            searchString = c.Id.ToString();
                            while (html.Contains(searchString))
                            {
                                mlp.GetTagBounds(html, searchString);
                                mlp.ShiftLastIndex(ref html);

                                var innerHtml = mlp.GetInnerHtml();
                                html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                                html = html.Insert(mlp.StartIndex, innerHtml);
                            }

                            // Удаляет ссылки на компетенцию.
                            foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
                            {
                                if (lto.ObjectId.Equals(c.Id))
                                {
                                    if (lto.TrainingModule.TrainingModuleDocument == null)
                                    {
                                        #region Документ не создан

                                        var html_ = string.Copy(lto.TrainingModule.DocumentHtml);
                                        var mlp_ = new MlParser();
                                        string searchString_;
                                        string innerHtml;

                                        searchString_ = lto.ObjectId.ToString();
                                        while (html_.Contains(searchString_))
                                        {
                                            mlp_.GetTagBounds(html_, searchString_);
                                            mlp_.ShiftLastIndex(ref html_);

                                            innerHtml = mlp_.GetInnerHtml();
                                            html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                            html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                                        }

                                        lto.TrainingModule.DocumentHtml = html_;

                                        #endregion
                                    }
                                    else
                                    {
                                        #region Документ создан

                                        var html_ = string.Copy(lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                                        var mlp_ = new MlParser();
                                        string searchString_;
                                        string innerHtml;

                                        searchString_ = lto.ObjectId.ToString();
                                        while (html_.Contains(searchString_))
                                        {
                                            mlp_.GetTagBounds(html_, searchString_);
                                            mlp_.ShiftLastIndex(ref html_);

                                            innerHtml = mlp_.GetInnerHtml();
                                            html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                            html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                                        }

                                        lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html_;

                                        #endregion
                                    }
                                }
                            }
                        }

                        HtmlEditingTool.BodyInnerHtml = html;
                    }

                    #endregion
                }
            }
        }
        private void VisualHtmlEditor_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.Equals(Keys.Insert))
            {
                if (EditorObserver.HostEditorMode == Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Design)
                {
                    if (EditorObserver.ActiveEditor.CanOverwrite)
                    {
                        RibbonStatusStripEx.Instance.MakeInsert();
                    }
                    else
                    {
                        RibbonStatusStripEx.Instance.MakeOverwrite();
                    }
                }
            }

            if (e.KeyCode.Equals(Keys.F1))
            {
                CommandManager.Instance.GetCommand(CommandNames.Help).Execute(null);
            }

            if (e.KeyCode.Equals(Keys.F3))
            {
                CommandManager.Instance.GetCommand(CommandNames.Find).Execute(null);
            }

            if (e.KeyCode.Equals(Keys.F5))
            {
                CommandManager.Instance.GetCommand(CommandNames.Preview).Execute(null);
            }

            if (e.KeyCode.Equals(Keys.F6))
            {
                CommandManager.Instance.GetCommand(CommandNames.Design).Execute(null);
            }

            if (e.KeyCode.Equals(Keys.F7))
            {
                CommandManager.Instance.GetCommand(CommandNames.Course).Execute(null);
            }

            if (e.KeyCode.Equals(Keys.F8))
            {
                CommandManager.Instance.GetCommand(CommandNames.Concepts).Execute(null);
            }

            if (e.KeyCode.Equals(Keys.F9))
            {
                CommandManager.Instance.GetCommand(CommandNames.Warnings).Execute(null);
            }

            if (e.KeyCode.Equals(Keys.Apps))
            {
                if (EditorObserver.HostEditorMode == Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Design)
                {
                    AttachContextMenu(HtmlEditingTool.Document.Body);

                    bodyContextMenu.Show(HtmlEditingTool, 0, 0);
                }
            }

            if (e.KeyCode.Equals(Keys.Delete))
            {
                if (HtmlEditingTool.IsSelection)
                {
                    var html = HtmlEditingTool.GetSelection();

                    // Не предусмотрено удаление контента, являющегося рисунком из css.
                    if (html.Equals(string.Empty))
                    {
                        return;
                        //html = BodyInnerHtml;
                    }

                    var mlp = new MlParser();
                    string searchString;
                    string id;

                    #region Удаление закладок

                    bookmarks = new List<Bookmark>();

                    searchString = "class=bookmark";
                    while (html.Contains(searchString))
                    {
                        mlp.GetTagBounds(html, searchString);
                        id = mlp.GetValue("id");

                        var bi = new Guid(id);

                        foreach (Bookmark b in Warehouse.Warehouse.Instance.Bookmarks)
                        {
                            if (b.Id.Equals(bi))
                            {
                                bookmarks.Add(b);

                                break;
                            }
                        }

                        mlp.ShiftLastIndex(ref html);
                        var innerHtml = mlp.GetInnerHtml();
                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, innerHtml);
                    }

                    if (bookmarks.Count.Equals(0))
                    {
                        bookmarks = null;
                    }

                    #endregion

                    #region Удаление компетенций

                    concepts = new List<Concept>();

                    searchString = "class=concept";
                    while (html.Contains(searchString))
                    {
                        mlp.GetTagBounds(html, searchString);
                        id = mlp.GetValue("id");

                        var ci = new Guid(id);

                        foreach (Concept c in Warehouse.Warehouse.Instance.ConceptTree.Nodes)
                        {
                            if (c.Id.Equals(ci))
                            {
                                concepts.Add(c);

                                break;
                            }
                        }

                        mlp.ShiftLastIndex(ref html);
                        var innerHtml = mlp.GetInnerHtml();
                        html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                        html = html.Insert(mlp.StartIndex, innerHtml);
                    }

                    if (concepts.Count.Equals(0))
                    {
                        concepts = null;
                    }

                    #endregion

                    // Удаление ссылок из списков не предусмотрено.
                }
            }

            Warehouse.Warehouse.IsProjectModified = true;
        }
        private static void DeleteTrainingModule(TrainingModule tm)
        {
            #region Ссылки на модули

            // Удаляет ссылки на модуль.
            foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
            {
                if (lto.ObjectId.Equals(tm.Id))
                {
                    if (lto.TrainingModule.TrainingModuleDocument == null)
                    {
                        #region Документ не создан

                        var html_ = string.Copy(lto.TrainingModule.DocumentHtml);
                        var mlp_ = new MlParser();
                        string searchString_;
                        string innerHtml;

                        searchString_ = lto.ObjectId.ToString();
                        while (html_.Contains(searchString_))
                        {
                            mlp_.GetTagBounds(html_, searchString_);
                            mlp_.ShiftLastIndex(ref html_);

                            innerHtml = mlp_.GetInnerHtml();
                            html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                            html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                        }

                        lto.TrainingModule.DocumentHtml = html_;

                        #endregion
                    }
                    else
                    {
                        #region Документ создан

                        var html_ = string.Copy(lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                        var mlp_ = new MlParser();
                        string searchString_;
                        string innerHtml;

                        searchString_ = lto.ObjectId.ToString();
                        while (html_.Contains(searchString_))
                        {
                            mlp_.GetTagBounds(html_, searchString_);
                            mlp_.ShiftLastIndex(ref html_);

                            innerHtml = mlp_.GetInnerHtml();
                            html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                            html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                        }

                        lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html_;

                        #endregion
                    }
                }
            }

            #endregion

            #region Закладки и ссылки на закладки

            // Список закладок текущего учебного модуля.
            var bookmarks = new List<Bookmark>();

            foreach (var b in Warehouse.Warehouse.Instance.Bookmarks)
            {
                if (b.ModuleId.Equals(tm.Id))
                {
                    bookmarks.Add(b);
                }
            }

            foreach (var b in bookmarks)
            {
                // Удаляет закладку из списка закладок.
                Warehouse.Warehouse.Instance.Bookmarks.Remove(b);

                // Удаляет закладку из Html-кода.
                if (tm.TrainingModuleDocument == null)
                {
                    #region Документ не создан

                    var html = tm.DocumentHtml;
                    var mlp = new MlParser();
                    string searchString;
                    string value;
                    int index;

                    searchString = "class=bookmark";
                    index = 0;
                    while (html.Contains(searchString))
                    {
                        mlp.GetTagBounds(html, searchString, index);
                        value = mlp.GetValue("id");
                        mlp.ShiftLastIndex(ref html);

                        if (value.Equals(b.Id.ToString()))
                        {
                            html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                            index = mlp.StartIndex;
                        }
                        else
                        {
                            index = mlp.LastIndex;
                        }

                        if (index == mlp.StartIndex)
                        {
                            break;
                        }
                    }

                    tm.DocumentHtml = html;

                    #endregion
                }
                else
                {
                    #region Документ создан

                    var html = tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml;
                    var mlp = new MlParser();
                    string searchString;
                    string value;
                    int index;

                    searchString = "class=bookmark";
                    index = 0;
                    while (html.Contains(searchString))
                    {
                        mlp.GetTagBounds(html, searchString, index);
                        value = mlp.GetValue("id");
                        mlp.ShiftLastIndex(ref html);

                        if (value.Equals(b.Id.ToString()))
                        {
                            html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                            index = mlp.StartIndex;
                        }
                        else
                        {
                            index = mlp.LastIndex;
                        }

                        if (index == mlp.StartIndex)
                        {
                            break;
                        }
                    }

                    tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html;

                    #endregion
                }

                // Удаляет ссылки на закладку.
                foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
                {
                    if (lto.ObjectId.Equals(b.Id))
                    {
                        if (lto.TrainingModule.TrainingModuleDocument == null)
                        {
                            #region Документ не создан

                            var html_ = string.Copy(lto.TrainingModule.DocumentHtml);
                            var mlp_ = new MlParser();
                            string searchString_;
                            string innerHtml;

                            searchString_ = lto.ObjectId.ToString();
                            while (html_.Contains(searchString_))
                            {
                                mlp_.GetTagBounds(html_, searchString_);
                                mlp_.ShiftLastIndex(ref html_);

                                innerHtml = mlp_.GetInnerHtml();
                                html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                            }

                            lto.TrainingModule.DocumentHtml = html_;

                            #endregion
                        }
                        else
                        {
                            #region Документ создан

                            var html_ = string.Copy(lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                            var mlp_ = new MlParser();
                            string searchString_;
                            string innerHtml;

                            searchString_ = lto.ObjectId.ToString();
                            while (html_.Contains(searchString_))
                            {
                                mlp_.GetTagBounds(html_, searchString_);
                                mlp_.ShiftLastIndex(ref html_);

                                innerHtml = mlp_.GetInnerHtml();
                                html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                            }

                            lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html_;

                            #endregion
                        }
                    }
                }
            }

            #endregion

            #region Компетенции и ссылки на компетенции

            // Список компетенций текущего учебного модуля.
            var concepts = new List<Logic.Course.Items.Concept>();

            foreach (var odc in tm.OutConceptParent.OutDummyConcepts)
            {
                concepts.Add(odc.Concept);
            }

            foreach (var c in concepts)
            {
                // Удаляет компетенцию из дерева компетенций.
                Warehouse.Warehouse.Instance.ConceptTree.Nodes.Remove(c);

                if (Warehouse.Warehouse.Instance.ConceptTree.Nodes.Count.Equals(0))
                {
                    Warehouse.Warehouse.Instance.ConceptTree.CurrentNode = null;
                }

                if (c.Type.Equals(Enums.ConceptType.Internal))
                {
                    // Удаляет компетенцию из выходов.
                    c.OutDummyConcept.Parent.Nodes.Remove(c.OutDummyConcept);

                    // Удаляет компетенцию из входов.
                    foreach (var idc in c.InDummyConcepts)
                    {
                        idc.Parent.Nodes.Remove(idc);
                    }
                    c.InDummyConcepts.Clear();

                    // Удаляет компетенцию из Html-кода.
                    if (tm.TrainingModuleDocument == null)
                    {
                        #region Документ не создан

                        var html = string.Copy(tm.DocumentHtml);
                        var mlp = new MlParser();
                        string searchString;
                        string innerHtml;

                        searchString = c.Id.ToString();
                        while (html.Contains(searchString))
                        {
                            mlp.GetTagBounds(html, searchString);
                            mlp.ShiftLastIndex(ref html);

                            innerHtml = mlp.GetInnerHtml();
                            html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                            html = html.Insert(mlp.StartIndex, innerHtml);
                        }

                        tm.DocumentHtml = html;

                        #endregion
                    }
                    else
                    {
                        #region Документ создан

                        var html = string.Copy(tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                        var mlp = new MlParser();
                        string searchString;
                        string innerHtml;

                        searchString = c.Id.ToString();
                        while (html.Contains(searchString))
                        {
                            mlp.GetTagBounds(html, searchString);
                            mlp.ShiftLastIndex(ref html);

                            innerHtml = mlp.GetInnerHtml();
                            html = html.Remove(mlp.StartIndex, mlp.LastIndex - mlp.StartIndex + 1);
                            html = html.Insert(mlp.StartIndex, innerHtml);
                        }

                        tm.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html;

                        #endregion
                    }

                    // Удаляет ссылки на компетенцию.
                    foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
                    {
                        if (lto.ObjectId.Equals(c.Id))
                        {
                            if (lto.TrainingModule.TrainingModuleDocument == null)
                            {
                                #region Документ не создан

                                var html_ = string.Copy(lto.TrainingModule.DocumentHtml);
                                var mlp_ = new MlParser();
                                string searchString_;
                                string innerHtml;

                                searchString_ = lto.ObjectId.ToString();
                                while (html_.Contains(searchString_))
                                {
                                    mlp_.GetTagBounds(html_, searchString_);
                                    mlp_.ShiftLastIndex(ref html_);

                                    innerHtml = mlp_.GetInnerHtml();
                                    html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                    html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                                }

                                lto.TrainingModule.DocumentHtml = html_;

                                #endregion
                            }
                            else
                            {
                                #region Документ создан

                                var html_ = string.Copy(lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml);
                                var mlp_ = new MlParser();
                                string searchString_;
                                string innerHtml;

                                searchString_ = lto.ObjectId.ToString();
                                while (html_.Contains(searchString_))
                                {
                                    mlp_.GetTagBounds(html_, searchString_);
                                    mlp_.ShiftLastIndex(ref html_);

                                    innerHtml = mlp_.GetInnerHtml();
                                    html_ = html_.Remove(mlp_.StartIndex, mlp_.LastIndex - mlp_.StartIndex + 1);
                                    html_ = html_.Insert(mlp_.StartIndex, innerHtml);
                                }

                                lto.TrainingModule.TrainingModuleDocument.HtmlEditingTool.BodyInnerHtml = html_;

                                #endregion
                            }
                        }
                    }
                }
            }

            #endregion

            #region Ссылки

            // Список ссылок из текущего учебного модуля.
            var linksToObjects = new List<LinkToObject>();

            foreach (var lto in Warehouse.Warehouse.Instance.LinksToObjects)
            {
                if (lto.TrainingModule.Equals(tm))
                {
                    linksToObjects.Add(lto);
                }
            }

            foreach (var lto in linksToObjects)
            {
                Warehouse.Warehouse.Instance.LinksToObjects.Remove(lto);
            }

            #endregion

            Warehouse.Warehouse.Instance.TrainingModules.Remove(tm);

            if (tm.TrainingModuleDocument != null)
            {
                tm.TrainingModuleDocument.Hide();
            }
        }