/// <summary/> public HtmlFormat() { const string regJavaScript = @"(?<=<script(?:\s.*?)?>).+?(?=</script>)"; const string regComment = @"<!--.*?-->"; const string regAspTag = @"<%@.*?%>|<%=?|%>|<\?php|<\?|\?>"; const string regPhpCode = @"(?<=<\?).*?(?=\?>)|(?<=<\?php).*?(?=\?>)"; const string regAspCode = @"(?<=<%=?).*?(?=%>)"; const string regTagDelimiter = @"(?:</?!?\??(?!%)|(?<!%)/?>)+"; const string regTagName = @"(?<=</?!?\??(?!%))[\w\.:-]+(?=.*>)"; const string regAttributes = @"(?<=<(?!%)/?!?\??[\w:-]+).*?(?=(?<!%)/?>)"; const string regEntity = @"&\w+;"; const string regAttributeMatch = @"(=?"".*?""|=?'.*?')|([\w:-]+)"; //the regex object will handle all the replacements in one pass string regAll = "(" + regJavaScript + ")|(" + regComment + ")|(" + regAspTag + ")|(" + regAspCode + ")|(" + regPhpCode + ")|(" + regTagDelimiter + ")|(" + regTagName + ")|(" + regAttributes + ")|(" + regEntity + ")"; CodeRegex = new Regex(regAll, RegexOptions.IgnoreCase | RegexOptions.Singleline); attribRegex = new Regex(regAttributeMatch, RegexOptions.Singleline); csf = new CSharpFormat(); jsf = new JavaScriptFormat(); phf = new PhpFormat(); }
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)); } }
public HtmlFormat() { CodeRegex = new Regex("((?<=<script(?:\\s.*?)?>).+?(?=</script>))|(<!--.*?-->)|(<%@.*?%>|<%|%>)|((?<=<%).*?(?=%>))|((?:</?!?\\??(?!%)|(?<!%)/?>)+)|((?<=</?!?\\??(?!%))[\\w\\.:-]+(?=.*>))|((?<=<(?!%)/?!?\\??[\\w:-]+).*?(?=(?<!%)/?>))|(&\\w+;)", RegexOptions.IgnoreCase | RegexOptions.Singleline); attribRegex = new Regex("(=?\".*?\"|=?'.*?')|([\\w:-]+)", RegexOptions.Singleline); csf = new CSharpFormat(); jsf = new JavaScriptFormat(); }
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("&", "&").Replace("<", "<").Replace(">", ">").Replace(""", "\""); 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 { string c = code.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace(""", "\""); 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 void Main(string[] args) { SourceFormat sourceFormat = null; bool lineNumbers = false; bool alternate = false; bool embedStyleSheet = false; string title = null; foreach (string arg in args) { String s = arg.ToLower(); if (s.Equals("-csharp")) { sourceFormat = new CSharpFormat(); } else if (s.Equals("-java")) { sourceFormat = new JavaFormat(); } else if (s.StartsWith("-line")) { lineNumbers = true; } else if (s.StartsWith("-alt")) { alternate = true; } else if (s.StartsWith("-embed")) { embedStyleSheet = true; } else if (s.StartsWith("-title:")) { title = arg.Substring(7); } else { Console.WriteLine("ERROR: Invalid argument: " + arg); Environment.Exit(1); } } if (sourceFormat == null) { Console.WriteLine("ERROR: Missing language argument"); Environment.Exit(1); } if (lineNumbers) { sourceFormat.LineNumbers = true; } if (alternate) { sourceFormat.Alternate = true; } if (embedStyleSheet) { sourceFormat.EmbedStyleSheet = true; } if (title != null) { sourceFormat.Title = title; } Console.Write(sourceFormat.FormatCode(Console.In.ReadToEnd())); }
/// <summary> /// Generate code using the current template. /// </summary> /// <param name="baseUri">Base URI for container and authority.</param> /// <param name="tableName">Table name.</param> /// <param name="query">Query</param> /// <returns>Sample code.</returns> internal string GenerateCSharp(string baseUri, string tableName, string query) { // Create uri string uri = baseUri + "/" + tableName; Template = Template.Replace("{0}", uri); Template = Template.Replace("{1}", query); // Get the code in csharpformat var csharpFormat = new CSharpFormat(); csharpFormat.Alternate = true; csharpFormat.EmbedStyleSheet = false; csharpFormat.LineNumbers = false; return csharpFormat.FormatCode(Template); }
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))); } }