Пример #1
0
        private void parseMainContent()
        {
            //[\\w\\s-_|^[]+]]
            Regex t = new Regex("(\\[\\[[^\\[]+\\]\\])|('''[\\w\\s,\\.]+''')", RegexOptions.IgnoreCase);

            List <string> used = new List <string>();

            MainContent = MainContent.Replace("'", "");
            MainContent = HttpUtility.HtmlEncode(MainContent);
            MainContent = MainContent.Replace("&amp;quot;", "\'");
            MainContent = MainContent.Replace("&amp;nbsp;", "");
            MainContent = MainContent.Replace("&amp;ndash;", "-");
            MainContent = MainContent.Replace("&quot;", "\'");
            MainContent = MainContent.Replace("&nbsp;", "");
            MainContent = MainContent.Replace("&ndash;", "-");
            //MainContent = HttpUtility.HtmlDecode(MainContent);

            try
            {
                Regex regex = new Regex(@"(<[^<]+>)|({{[^{]+}})|(<!--[^<]+-->)");
                while (regex.IsMatch(MainContent))
                {
                    MainContent = regex.Replace(MainContent, "");
                }
            }
            catch (ArgumentException ex)
            {
                // Syntax error in the regular expression
            }


            foreach (var s in t.Matches(MainContent))
            {
                bool doReplace = true;

                foreach (var b in used)
                {
                    if (b.Equals(s.ToString()))
                    {
                        doReplace = false;
                    }
                }

                if (doReplace)
                {
                    used.Add(s.ToString());

                    string ss = s.ToString();

                    string[] split = ss.Substring(2, ss.Length - 4).Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

                    if (split.Length == 1)
                    {
                        MainContent = MainContent.Replace(s.ToString(), "<Run FontWeight=\"Bold\" Text=\"" + split[0] + "\"/>");
                    }
                    else
                    {
                        MainContent = MainContent.Replace(s.ToString(), "<Run FontWeight=\"Bold\" Text=\"" + split[1] + "\"/>");
                    }
                }
            }

            // Build text with highlights

            string textBlockStr = "<TextBlock xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" FontSize=\"25\" TextWrapping=\"Wrap\" VerticalAlignment=\"Top\">";

            textBlockStr += MainContent;

            textBlockStr += "</TextBlock>";
            // textBlockStr = textBlockStr.Replace("&nbsp;", "");

            MainContent = textBlockStr;
        }