Exemplo n.º 1
0
		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;
		}
Exemplo n.º 2
0
		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();
			}
		}