MarkdownSharp
1.12
|
00001 using System; 00002 using System.Collections.Specialized; 00003 using System.Configuration; 00004 using System.Runtime.CompilerServices; 00005 using System.Web.Configuration; 00006 00007 namespace MarkdownSharp 00008 { 00013 public class MarkdownOptions 00014 { 00022 public MarkdownOptions() : this(true) { } 00023 00032 public MarkdownOptions(bool loadFromConfigFile) 00033 : this(loadFromConfigFile, new[] { ConfigurationManager.AppSettings, WebConfigurationManager.AppSettings }) 00034 { 00035 } 00036 00037 00043 internal MarkdownOptions(bool loadFromConfigFile, NameValueCollection[] configProviders) 00044 { 00045 Defaults(); 00046 if (!loadFromConfigFile) return; 00047 00048 00049 foreach (var appSettings in configProviders) 00050 { 00051 foreach (string key in appSettings.Keys) 00052 { 00053 switch (key) 00054 { 00055 case "Markdown.AutoHyperlink": 00056 AutoHyperlink = Convert.ToBoolean(appSettings[key]); 00057 break; 00058 case "Markdown.AutoNewlines": 00059 AutoNewlines = Convert.ToBoolean(appSettings[key]); 00060 break; 00061 case "Markdown.EmptyElementSuffix": 00062 EmptyElementSuffix = appSettings[key]; 00063 break; 00064 case "Markdown.EncodeProblemUrlCharacters": 00065 EncodeProblemUrlCharacters = Convert.ToBoolean(appSettings[key]); 00066 break; 00067 case "Markdown.LinkEmails": 00068 LinkEmails = Convert.ToBoolean(appSettings[key]); 00069 break; 00070 case "Markdown.NestDepth": 00071 NestDepth = Convert.ToInt32(appSettings[key]); 00072 break; 00073 case "Markdown.StrictBoldItalic": 00074 StrictBoldItalic = Convert.ToBoolean(appSettings[key]); 00075 break; 00076 case "Markdown.TabWidth": 00077 TabWidth = Convert.ToInt32(appSettings[key]); 00078 break; 00079 } 00080 } 00081 } 00082 } 00083 00084 00097 public MarkdownOptions(bool autoHyperlink, bool autoNewlines, string emptyElementsSuffix, 00098 bool encodeProblemUrlCharacters, bool linkEmails, int nestDepth, bool strictBoldItalic, 00099 int tabWidth) 00100 { 00101 AutoHyperlink = autoHyperlink; 00102 AutoNewlines = autoNewlines; 00103 EmptyElementSuffix = emptyElementsSuffix; 00104 EncodeProblemUrlCharacters = encodeProblemUrlCharacters; 00105 LinkEmails = linkEmails; 00106 NestDepth = nestDepth; 00107 StrictBoldItalic = strictBoldItalic; 00108 TabWidth = tabWidth; 00109 } 00110 00114 private void Defaults() 00115 { 00116 AutoHyperlink = false; 00117 AutoNewlines = false; 00118 EmptyElementSuffix = " />"; 00119 EncodeProblemUrlCharacters = false; 00120 LinkEmails = true; 00121 NestDepth = 6; 00122 StrictBoldItalic = false; 00123 TabWidth = 4; 00124 } 00125 00130 public bool AutoHyperlink { get; private set; } 00131 00136 public bool AutoNewlines { get; private set; } 00137 00141 public string EmptyElementSuffix { get; private set; } 00142 00147 public bool EncodeProblemUrlCharacters { get; private set; } 00148 00153 public bool LinkEmails { get; private set; } 00154 00158 public int NestDepth { get; private set; } 00159 00164 public bool StrictBoldItalic { get; private set; } 00165 00170 public int TabWidth { get; private set; } 00171 } 00172 }