コード例 #1
0
        /// <summary>
        ///     Returns the formatted text.
        /// </summary>
        /// <param name="options">Whatever options were set in the regex groups.</param>
        /// <param name="text">Send the e.body so it can get formatted.</param>
        /// <returns>The formatted string of the match.</returns>
        private static string Highlight(HighlightOptions options, string text)
        {
            switch (options.Language)
            {
            case "c#":
                var csf = new CSharpFormat();
                csf.LineNumbers = options.DisplayLineNumbers;
                csf.Alternate   = options.AlternateLineNumbers;
                return(HttpUtility.HtmlDecode(csf.FormatCode(text)));

            case "vb":
                var vbf = new VisualBasicFormat();
                vbf.LineNumbers = options.DisplayLineNumbers;
                vbf.Alternate   = options.AlternateLineNumbers;
                return(vbf.FormatCode(text));

            case "js":
                var jsf = new JavaScriptFormat();
                jsf.LineNumbers = options.DisplayLineNumbers;
                jsf.Alternate   = options.AlternateLineNumbers;
                return(HttpUtility.HtmlDecode(jsf.FormatCode(text)));

            case "html":
                var htmlf = new HtmlFormat();
                htmlf.LineNumbers = options.DisplayLineNumbers;
                htmlf.Alternate   = options.AlternateLineNumbers;
                text = StripHtml(text).Trim();
                var code = htmlf.FormatCode(HttpUtility.HtmlDecode(text)).Trim();
                return(code.Replace("\r\n", "<br />").Replace("\n", "<br />"));

            case "xml":
                var xmlf = new HtmlFormat();
                xmlf.LineNumbers = options.DisplayLineNumbers;
                xmlf.Alternate   = options.AlternateLineNumbers;
                text             = text.Replace("<br />", "\r\n");
                text             = StripHtml(text).Trim();
                var xml = xmlf.FormatCode(HttpUtility.HtmlDecode(text)).Trim();
                return(xml.Replace("\r\n", "<br />").Replace("\n", "<br />"));

            case "tsql":
                var tsqlf = new TsqlFormat();
                tsqlf.LineNumbers = options.DisplayLineNumbers;
                tsqlf.Alternate   = options.AlternateLineNumbers;
                return(HttpUtility.HtmlDecode(tsqlf.FormatCode(text)));

            case "msh":
                var mshf = new MshFormat();
                mshf.LineNumbers = options.DisplayLineNumbers;
                mshf.Alternate   = options.AlternateLineNumbers;
                return(HttpUtility.HtmlDecode(mshf.FormatCode(text)));
            }

            return(string.Empty);
        }
コード例 #2
0
        /// <summary>
        /// Returns the formatted text.
        /// </summary>
        /// <param name="options">Whatever options were set in the regex groups.</param>
        /// <param name="text">Send the e.body so it can get formatted.</param>
        /// <returns>The formatted string of the match.</returns>
        private static string Highlight(HighlightOptions options, string text)
        {
            switch (options.Language)
            {
                case "c#":
                    var csf = new CSharpFormat();
                    csf.LineNumbers = options.DisplayLineNumbers;
                    csf.Alternate = options.AlternateLineNumbers;
                    return HttpUtility.HtmlDecode(csf.FormatCode(text));

                case "vb":
                    var vbf = new VisualBasicFormat();
                    vbf.LineNumbers = options.DisplayLineNumbers;
                    vbf.Alternate = options.AlternateLineNumbers;
                    return vbf.FormatCode(text);

                case "js":
                    var jsf = new JavaScriptFormat();
                    jsf.LineNumbers = options.DisplayLineNumbers;
                    jsf.Alternate = options.AlternateLineNumbers;
                    return HttpUtility.HtmlDecode(jsf.FormatCode(text));

                case "html":
                    var htmlf = new HtmlFormat();
                    htmlf.LineNumbers = options.DisplayLineNumbers;
                    htmlf.Alternate = options.AlternateLineNumbers;
                    text = StripHtml(text).Trim();
                    string code = htmlf.FormatCode(HttpUtility.HtmlDecode(text)).Trim();
                    return code.Replace("\r\n", "<br />").Replace("\n", "<br />");

                case "xml":
                    var xmlf = new HtmlFormat();
                    xmlf.LineNumbers = options.DisplayLineNumbers;
                    xmlf.Alternate = options.AlternateLineNumbers;
                    text = text.Replace("<br />", "\r\n");
                    text = StripHtml(text).Trim();
                    string xml = xmlf.FormatCode(HttpUtility.HtmlDecode(text)).Trim();
                    return xml.Replace("\r\n", "<br />").Replace("\n", "<br />");

                case "tsql":
                    var tsqlf = new TsqlFormat();
                    tsqlf.LineNumbers = options.DisplayLineNumbers;
                    tsqlf.Alternate = options.AlternateLineNumbers;
                    return HttpUtility.HtmlDecode(tsqlf.FormatCode(text));

                case "msh":
                    var mshf = new MshFormat();
                    mshf.LineNumbers = options.DisplayLineNumbers;
                    mshf.Alternate = options.AlternateLineNumbers;
                    return HttpUtility.HtmlDecode(mshf.FormatCode(text));

            }

            return string.Empty;
        }