public string ConvertMarkdownToHTML(string markdown) { if (!NetworkUtilities.IsNetworkAvailable()) { return("<strong>" + LocalizationProvider.GetLocalizedString("Error_NoNetworkConnection", false, "MarkdownPadStrings") + "</strong>"); } IAuthenticator authenticator = null; if (!this._settings.Markdown_GFM_AnonymousMode) { authenticator = new HttpBasicAuthenticator(this._settings.Markdown_GFM_Username, SettingsProvider.DecryptString(this._settings.Markdown_GFM_Password).ToInsecureString()); } RestClient restClient = new RestClient { BaseUrl = "https://api.github.com", Authenticator = authenticator, Proxy = WebRequest.DefaultWebProxy }; RestRequest restRequest = new RestRequest { Resource = "markdown", RequestFormat = RestSharp.DataFormat.Json, Method = Method.POST }; restRequest.AddBody(new { text = markdown, mode = "gfm" }); IRestResponse restResponse = restClient.Execute(restRequest); try { this.CheckResponse(restResponse); } catch (RestResponseException ex) { GitHubFlavoredMarkdownProcessor._logger.ErrorException("GFM RestResponseException", ex); string text = string.Empty; if (ex.Response == null) { GitHubFlavoredMarkdownProcessor._logger.ErrorException("GFM RestResponseException: Response was null", ex); text = ex.Message; } else { if (ex.Response.ErrorException != null) { GitHubFlavoredMarkdownProcessor._logger.ErrorException("GFM RestResponseException: Response was not null, and an Response ErrorException was present.", ex.Response.ErrorException); text = ex.Response.ErrorMessage; } else { GitHubFlavoredMarkdownProcessor._logger.ErrorException("GFM RestResponseException: Error message received from GFM API, deserializing JSON...\n" + ex.Response, ex); try { JsonDeserializer jsonDeserializer = new JsonDeserializer(); System.Collections.Generic.Dictionary <string, string> dictionary = jsonDeserializer.Deserialize <System.Collections.Generic.Dictionary <string, string> >(ex.Response); if (dictionary.ContainsKey("message")) { HttpStatusCode statusCode = ex.Response.StatusCode; string statusDescription = ex.Response.StatusDescription; string arg = dictionary["message"]; text = string.Format("{0} ({1}): {2}", statusCode, statusDescription, arg); string text2 = text; text = string.Concat(new string[] { text2, "<br /><br />", LocalizationProvider.GetLocalizedString("Error_GitHubFlavoredMarkdownMessage2", false, "MarkdownPadStrings"), "<br /><h4>Technical Details</h4><pre><code>", ex.Response.Content, "</code></pre>" }); } } catch (System.Runtime.Serialization.SerializationException ex2) { GitHubFlavoredMarkdownProcessor._logger.ErrorException("GFM: Error deserializing error", ex2); text = string.Concat(new object[] { LocalizationProvider.GetLocalizedString("Gfm_Error_UnexpectedErrorResponse", false, "MarkdownPadStrings"), "<br /><br /><h4>Technical Details</h4><pre><code>", ex, "</code></pre><br /><pre><code>", ex.Response.Content, "</code></pre><br /><pre><code>", ex2, "</code></pre>" }); } } } return(string.Concat(new string[] { "<p>", LocalizationProvider.GetLocalizedString("Error_GitHubFlavoredMarkdownMessage1", false, "MarkdownPadStrings"), "</p><p><strong>", text, "</strong></p><p>", LocalizationProvider.GetLocalizedString("IfBugPersists", false, "MarkdownPadStrings"), "</p>" })); } return(restResponse.Content); }