public ActionResult New(string message = null) { ViewData["UserState"] = AppUserState; var snippet = new CodeSnippet(); snippet.Author = this.AppUserState.Name; string codeUrl = Request.QueryString["url"]; if (!string.IsNullOrEmpty(codeUrl)) { HttpClient client = new HttpClient(); client.Timeout = 4000; snippet.Code = client.DownloadString(codeUrl); snippet.Title = Path.GetFileName(codeUrl); string extension = Path.GetExtension(codeUrl); snippet.Language = CodeFormatFactory.GetStringLanguageFromExtension(extension); Response.Write(snippet.Language); } if (!string.IsNullOrEmpty(message)) { this.ErrorDisplay.ShowMessage(message); } return(this.View("New", snippet)); }
/// <summary> /// Returns formatted code for the specified language. /// /// see CSharpFormat for supported types /// </summary> /// <param name="code"></param> /// <param name="language"></param> /// <returns></returns> public string GetFormattedCode(string code, string language, bool showLineNumbers = false, bool allowWordWrap = false) { SourceFormat formatter = CodeFormatFactory.Create(language); formatter.AllowWordWrapping = allowWordWrap; if (showLineNumbers) { formatter.LineNumbers = true; } return(formatter.FormatCode(code)); }