示例#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));
        }
示例#2
0
        /// <summary>
        /// Handles the Click event of the btnCopy control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnCopy_Click(object sender, EventArgs e)
        {
            SourceFormat sf = null;

            if (rbCSharp.Checked)
            {
                sf = new CSharpFormat();
            }
            else if (rbVB.Checked)
            {
                sf = new VisualBasicFormat();
            }
            else if (rbtsql.Checked)
            {
                sf = new TsqlFormat();
            }
            else if (rbHtml.Checked)
            {
                sf = new HtmlFormat();
            }
            else if (rbJS.Checked)
            {
                sf = new JavaScriptFormat();
            }
            else if (rbMsh.Checked)
            {
                sf = new MshFormat();
            }
            else
            {
                return;
            }

            sf.TabSpaces       = 4;
            sf.LineNumbers     = cbLineNumbers.Checked;
            sf.EmbedStyleSheet = cbEmbedCss.Checked;
            sf.Alternate       = cbAlternate.Checked;
            string formatedCode = sf.FormatCode(CodeToFormat);

            //Clipboard.SetText(formatedCode, TextDataFormat.Html);
            Clipboard.SetText(formatedCode);
        }
示例#3
0
        public override string GetReplaceResult(Match match)
        {
            string       lang      = match.Result("$1");
            string       body      = match.Result("$2");
            SourceFormat srcFormat = new HtmlFormat();

            if (lang.Equals("c#", StringComparison.OrdinalIgnoreCase) || lang.Equals("cs", StringComparison.OrdinalIgnoreCase) ||
                lang.Equals("csharp", StringComparison.OrdinalIgnoreCase))
            {
                srcFormat = new CSharpFormat();
            }

            if (lang.Equals("vb", StringComparison.OrdinalIgnoreCase) || lang.Equals("visualbasic", StringComparison.OrdinalIgnoreCase) ||
                lang.Equals("vbscript", StringComparison.OrdinalIgnoreCase))
            {
                srcFormat = new VisualBasicFormat();
            }

            if (lang.Equals("javascript", StringComparison.OrdinalIgnoreCase) || lang.Equals("js", StringComparison.OrdinalIgnoreCase) ||
                lang.Equals("jscript", StringComparison.OrdinalIgnoreCase))
            {
                srcFormat = new JavaScriptFormat();
            }

            if (lang.Equals("sql", StringComparison.OrdinalIgnoreCase))
            {
                srcFormat = new TsqlFormat();
            }

            if (lang.Equals("msh", StringComparison.OrdinalIgnoreCase))
            {
                srcFormat = new MshFormat();
            }

            srcFormat.Alternate       = Alternate;
            srcFormat.EmbedStyleSheet = EmbedStyleSheet;
            srcFormat.LineNumbers     = LineNumbers;
            return(srcFormat.FormatCode(body));
        }
示例#4
0
        private static SourceFormat _GetSourceCodeFormat(string language, bool alternate, bool embedStyleSheet, bool lineNumbers)
        {
            SourceFormat srcFormat = new HtmlFormat();

            if (language.Equals("c#", StringComparison.OrdinalIgnoreCase) || language.Equals("cs", StringComparison.OrdinalIgnoreCase) ||
                language.Equals("csharp", StringComparison.OrdinalIgnoreCase))
            {
                srcFormat = new CSharpFormat();
            }

            if (language.Equals("vb", StringComparison.OrdinalIgnoreCase) || language.Equals("visualbasic", StringComparison.OrdinalIgnoreCase) ||
                language.Equals("vbscript", StringComparison.OrdinalIgnoreCase))
            {
                srcFormat = new VisualBasicFormat();
            }

            if (language.Equals("javascript", StringComparison.OrdinalIgnoreCase) || language.Equals("js", StringComparison.OrdinalIgnoreCase) ||
                language.Equals("jscript", StringComparison.OrdinalIgnoreCase))
            {
                srcFormat = new JavaScriptFormat();
            }

            if (language.Equals("sql", StringComparison.OrdinalIgnoreCase))
            {
                srcFormat = new TsqlFormat();
            }

            if (language.Equals("msh", StringComparison.OrdinalIgnoreCase))
            {
                srcFormat = new MshFormat();
            }

            srcFormat.Alternate       = alternate;
            srcFormat.EmbedStyleSheet = embedStyleSheet;
            srcFormat.LineNumbers     = lineNumbers;
            return(srcFormat);
        }
        public static string FormatCode(string lang, string code)
        {
            SourceFormat sf = null;

            switch (lang)
            {
            case "csharp":
            case "cs":
                sf = new Manoli.Utils.CSharpFormat.CSharpFormat();
                break;

            case "c++":
            case "cpp":
                sf = new CPlusPlusFormat();
                break;

            case "js":
            case "javascript":
                sf = new JavaScriptFormat();
                break;

            case "vb":
            case "basic":
                sf = new VisualBasicFormat();
                break;

            case "sql":
                sf = new TsqlFormat();
                break;

            case "msh":
                sf = new MshFormat();
                break;

            case "haskell":
                sf = new HaskellFormat();
                break;

            case "php":
                sf = new PhpFormat();
                break;

            case "fsharp":
            case "fs":
                sf = new FSharpFormat();
                break;

            case "html":
            case "xml":
            case "aspx":
                sf = new HtmlFormat();
                break;
            }
            if (sf == null)
            {
                return(code);
            }
            else
            {
                string c = code.Replace("&amp;", "&").Replace("&lt;", "<").Replace("&gt;", ">").Replace("&quot;", "\"");
                c = c.Replace("<em>", "verynastythingthatnoonewillusebeginem")
                    .Replace("</em>", "verynastythingthatnoonewilluseendem");
                sf.TabSpaces = 2;
                return(sf.FormatCode(c)
                       .Replace("verynastythingthatnoonewilluseendem", "</em>")
                       .Replace("verynastythingthatnoonewillusebeginem", "<em>"));
            }
        }
        public static string FormatCode(string lang, string code)
        {
            SourceFormat sf = null;

            switch (lang)
            {
            case "csharp":
            case "cs":
                sf = new Manoli.Utils.CSharpFormat.CSharpFormat();
                break;

            case "c++":
            case "cpp":
                sf = new CPlusPlusFormat();
                break;

            case "js":
            case "javascript":
                sf = new JavaScriptFormat();
                break;

            case "vb":
            case "basic":
                sf = new VisualBasicFormat();
                break;

            case "sql":
                sf = new TsqlFormat();
                break;

            case "msh":
                sf = new MshFormat();
                break;

            case "haskell":
                sf = new HaskellFormat();
                break;

            case "php":
                sf = new PhpFormat();
                break;

            case "fsharp":
            case "fs":
                sf = new FSharpFormat();
                break;

            case "html":
            case "xml":
            case "aspx":
                sf = new HtmlFormat();
                break;
            }
            if (sf == null)
            {
                return(code);
            }
            else
            {
                sf.TabSpaces = 2;
                return(sf.FormatCode(code));
            }
        }
        public static Tuple <bool, string> FormatCode(string lang, string code)
        {
            SourceFormat sf = null;

            switch (lang)
            {
            case "csharp":
            case "cs":
                sf = new Manoli.Utils.CSharpFormat.CSharpFormat();
                break;

            case "c++":
            case "cpp":
                sf = new CPlusPlusFormat();
                break;

            case "js":
            case "javascript":
                sf = new JavaScriptFormat();
                break;

            case "ts":
            case "typescript":
                sf = new TypeScriptFormat();
                break;

            case "vb":
            case "basic":
                sf = new VisualBasicFormat();
                break;

            case "sql":
                sf = new TsqlFormat();
                break;

            case "msh":
                sf = new MshFormat();
                break;

            case "haskell":
                sf = new HaskellFormat();
                break;

            case "php":
                sf = new PhpFormat();
                break;

            case "fsharp":
            case "fs":
                sf = new FSharpFormat();
                break;

            case "html":
            case "xml":
            case "aspx":
                sf = new HtmlFormat();
                break;

            case "paket":
                sf = new PaketFormat();
                break;
            }
            if (sf == null)
            {
                return(Tuple.Create(false, SourceFormat.EscapeHtml(code, tabSpaces: 2)));
            }
            else
            {
                sf.TabSpaces = 2;
                return(Tuple.Create(true, sf.FormatCode(code)));
            }
        }
示例#8
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
            {
                LineNumbers = options.DisplayLineNumbers,
                Alternate   = options.AlternateLineNumbers
            };
            return(HttpContext.Current.Server.HtmlDecode(csf.FormatCode(text)));

        case "vb":
            var vbf = new VisualBasicFormat
            {
                LineNumbers = options.DisplayLineNumbers,
                Alternate   = options.AlternateLineNumbers
            };
            return(HttpContext.Current.Server.HtmlDecode(vbf.FormatCode(text)));

        case "js":
            var jsf = new JavaScriptFormat
            {
                LineNumbers = options.DisplayLineNumbers,
                Alternate   = options.AlternateLineNumbers
            };
            return(HttpContext.Current.Server.HtmlDecode(jsf.FormatCode(text)));

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

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

        case "tsql":
            var tsqlf = new TsqlFormat
            {
                LineNumbers = options.DisplayLineNumbers,
                Alternate   = options.AlternateLineNumbers
            };
            return(HttpContext.Current.Server.HtmlDecode(tsqlf.FormatCode(text)));

        case "msh":
            var mshf = new MshFormat
            {
                LineNumbers = options.DisplayLineNumbers,
                Alternate   = options.AlternateLineNumbers
            };
            return(HttpContext.Current.Server.HtmlDecode(mshf.FormatCode(text)));
        }

        return(string.Empty);
    }