Example #1
0
        public static string HighlightToHTML(string source, LangType type, bool customProtectionTags)
        {
            SourceFormat sf = null;

            switch (type)
            {
                case LangType.C:
                case LangType.CPP:
                    sf = new CppFormat();
                    break;
                case LangType.CS:
                    sf = new CSharpFormat();
                    break;
                case LangType.Html:
                case LangType.Xml:
                case LangType.Asp:
                    sf = new HtmlFormat();
                    break;
                case LangType.JS:
                    sf = new JavaScriptFormat();
                    break;
                case LangType.Msh:
                    sf = new MshFormat();
                    break;
                case LangType.TSql:
                    sf = new TsqlFormat();
                    break;
                case LangType.VB:
                    sf = new VisualBasicFormat();
                    break;
            }

            if (sf == null) return source;

            sf.CustomProtectedTags = customProtectionTags;
            return sf.FormatCode(source);
        }
Example #2
0
        /// <summary/>
        public HtmlFormat()
        {
            const string regJavaScript     = @"(?<=&lt;script(?:\s.*?)?&gt;).+?(?=&lt;/script&gt;)";
            const string regComment        = @"&lt;!--.*?--&gt;";
            const string regAspTag         = @"&lt;%@.*?%&gt;|&lt;%|%&gt;";
            const string regAspCode        = @"(?<=&lt;%).*?(?=%&gt;)";
            const string regTagDelimiter   = @"(?:&lt;/?!?\??(?!%)|(?<!%)/?&gt;)+";
            const string regTagName        = @"(?<=&lt;/?!?\??(?!%))[\w\.:-]+(?=.*&gt;)";
            const string regAttributes     = @"(?<=&lt;(?!%)/?!?\??[\w:-]+).*?(?=(?<!%)/?&gt;)";
            const string regEntity         = @"&amp;\w+;";
            const string regAttributeMatch = @"(=?"".*?""|=?'.*?')|([\w:-]+)";

            //the regex object will handle all the replacements in one pass
            const string regAll = "(" + regJavaScript + ")|(" + regComment + ")|("
                                  + regAspTag + ")|(" + regAspCode + ")|("
                                  + regTagDelimiter + ")|(" + regTagName + ")|("
                                  + regAttributes + ")|(" + regEntity + ")";

            CodeRegex    = new Regex(regAll, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            _attribRegex = new Regex(regAttributeMatch, RegexOptions.Singleline);

            _csf = new CSharpFormat();
            _jsf = new JavaScriptFormat();
        }
Example #3
0
        /// <summary/>
        public HtmlFormat()
        {
            const string regJavaScript = @"(?<=&lt;script(?:\s.*?)?&gt;).+?(?=&lt;/script&gt;)";
            const string regComment = @"&lt;!--.*?--&gt;";
            const string regAspTag = @"&lt;%@.*?%&gt;|&lt;%|%&gt;";
            const string regAspCode = @"(?<=&lt;%).*?(?=%&gt;)";
            const string regTagDelimiter = @"(?:&lt;/?!?\??(?!%)|(?<!%)/?&gt;)+";
            const string regTagName = @"(?<=&lt;/?!?\??(?!%))[\w\.:-]+(?=.*&gt;)";
            const string regAttributes = @"(?<=&lt;(?!%)/?!?\??[\w:-]+).*?(?=(?<!%)/?&gt;)";
            const string regEntity = @"&amp;\w+;";
            const string regAttributeMatch = @"(=?"".*?""|=?'.*?')|([\w:-]+)";

            //the regex object will handle all the replacements in one pass
            const string regAll = "(" + regJavaScript + ")|(" + regComment + ")|("
                                  + regAspTag + ")|(" + regAspCode + ")|("
                                  + regTagDelimiter + ")|(" + regTagName + ")|("
                                  + regAttributes + ")|(" + regEntity + ")";

            CodeRegex = new Regex(regAll, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            _attribRegex = new Regex(regAttributeMatch, RegexOptions.Singleline);

            _csf = new CSharpFormat();
            _jsf = new JavaScriptFormat();
        }