public OpenMarkdown(Configuration Config) {
			this.Config = Config;
			Reset();
		}
		public static int Main(string[] arguments) {
			bool outputXhtml	= true;
			bool indented		= false;
			bool wholeDocument	= false;
			bool useSmartyPants = false;

			string outputFile = null;

			List<string> args = new List<string>();
			foreach (string arg in arguments)
				args.Add(arg);

			while (args.Count > 0 && args[0][0] == '-') {
				switch (args[0]) {
				case "-x":
					outputXhtml = false;
					indented = true;
					break;
				case "-i":
					outputXhtml = true;
					indented = true;
					break;
				case "-h":
					outputXhtml = true;
					indented = true;
					wholeDocument = true;
					break;
				case "-o":
					outputFile = args[1];
					args.RemoveAt(0);
					break;
				case "-s":
					useSmartyPants = true;
					break;
				}
				args.RemoveAt(0);
			}

			Configuration config = new Configuration();
			config.UseSmartyPants = useSmartyPants;

			FileInfo info = new FileInfo(args[0]);
			if (! info.Exists) {
				Console.WriteLine("File '" + args[0] + "' does not exist!");
				return 1;
			}

			OpenMarkdown doc = OpenMarkdown.ReadFromFile(args[0], config);

			TextWriter outStream = Console.Out;

			if (outputFile != null) {
				info = new FileInfo(outputFile);
				if (info.Exists)
					info.Delete();

				info.Directory.Create();

				FileStream fs = info.OpenWrite();
				StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
				outStream = sw;
			}

			XmlTextWriter xw = new XmlTextWriter(outStream);
			if (indented)
				xw.Formatting = Formatting.Indented;

			if (outputXhtml) {
				XhtmlWriter xhw = new XhtmlWriter(doc);
				if (wholeDocument) {
					xhw.WriteDocumentTo(xw);
				} else {
					xhw.UseClasses = false;
					xhw.WriteTo(xw);
				}
			} else {
				xw.WriteStartDocument();
				doc.Document.WriteTo(xw);
			}

			outStream.Close();

			return 0;
		}
		public static OpenMarkdown Parse(TextReader reader, Configuration Config)
		{
			OpenMarkdown MMD = new OpenMarkdown(Config);
			MMD.Reader = reader;

			XmlDocument doc = new XmlDocument();
			MMD.Document = doc;
			MMD.TopElement = doc.CreateElement("markdown");
			doc.AppendChild(MMD.TopElement);
			XmlElement body = doc.CreateElement("body");
			MMD.TopElement.AppendChild(body);
			MMD.Parse(body);

			MMD.InsertMetadata();
			MMD.InsertLinks();
			MMD.InsertFootnotes();

			return MMD;
		}
		public static string ToIndentedXhtml(string text, Configuration config)
		{
			using (StringReader reader = new StringReader(text)) {
				OpenMarkdown doc = Parse(reader, config);
				XhtmlWriter xhw = new XhtmlWriter(doc);
				StringWriter sw = new StringWriter();
				XmlTextWriter xw = new XmlTextWriter(sw);
				xw.Formatting = Formatting.Indented;
				xhw.WriteTo(xw);
				return sw.ToString();
			}
		}
		public static string ToIndentedXhtml(string text, bool useSmartyPants) {
			Configuration config = new Configuration();
			config.UseSmartyPants = useSmartyPants;
			return ToIndentedXhtml(text, config);
		}
		public static string ToXml(string text, Configuration config)
		{
			using (StringReader reader = new StringReader(text)) {
				OpenMarkdown doc = Parse(reader, config);
				StringWriter sw = new StringWriter();
				XmlTextWriter xw = new XmlTextWriter(sw);
				doc.Document.WriteTo(xw);
				return sw.ToString();
			}
		}
		public static OpenMarkdown ReadFromFile(string path, Configuration config) {
			return ReadFromFile(path, Encoding.UTF8, config);
		}
		public static OpenMarkdown ReadFromFile(string path, Encoding code,
												 Configuration config) {
			using (StreamReader reader = new StreamReader(path, code))
				return Parse(reader, config);
		}