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));
     }
 }
Beispiel #2
0
 private 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>");
     }
 }