Beispiel #1
0
        /// <summary>
        /// Highlights macros of defined <paramref name="type"/> in <paramref name="code"/>
        /// using HTML syntax.
        /// </summary>
        /// <param name="code">Code with macros.</param>
        /// <param name="type">Type of macros to highlight.</param>
        /// <returns>Code with HTML highlighted macros.</returns>
        public string HighlightMacros(string code, MacroType type)
        {
            List <string> macros = new List <string>();

            if (type.HasFlag(MacroType.Context))
            {
                macros.AddRange(GetMacros(code, "%"));
            }

            if (type.HasFlag(MacroType.Query))
            {
                macros.AddRange(GetMacros(code, "?"));
            }

            if (type.HasFlag(MacroType.Custom))
            {
                macros.AddRange(GetMacros(code, "#"));
            }

            foreach (string macro in macros)
            {
                code = code.Replace(macro, "<span style=\"color: red;\">" + macro + "</span>");
            }

            return(code);
        }
Beispiel #2
0
 /// <summary>
 /// Checks whether <paramref name="text"/> contains macros of defined <paramref name="type"/>.
 /// </summary>
 /// <param name="text">Text with or without macros.</param>
 /// <param name="type">Type of macros to check.</param>
 /// <returns>True if text contains macros, false otherwise.</returns>
 public bool ContainsMacros(string text, MacroType type)
 {
     if (type.HasFlag(MacroType.Context) && text.Contains("{%"))
     {
         return(true);
     }
     if (type.HasFlag(MacroType.Query) && text.Contains("{?"))
     {
         return(true);
     }
     if (type.HasFlag(MacroType.Custom) && text.Contains("{#"))
     {
         return(true);
     }
     return(false);
 }