示例#1
0
		public SundownNetTest()
		{
			md = new Markdown(new HtmlRenderer());
			Name = "SundownNet";
		}
示例#2
0
		static void Work(Options options, string inputfile)
		{
			Renderer renderer = null;
			switch (options.Renderer) {
			case RendererType.Html:
				renderer = new HtmlRenderer(options.HtmlRenderMode);
				break;
			case RendererType.BBCode:
				renderer = new BBCodeRenderer(options.BBCodeOptions);
				break;
			case RendererType.TableOfContent:
				renderer = new TableOfContentRenderer();
				break;
			}

			var md = new Markdown(renderer, options.Extensions, options.MaxNesting);

			if (options.Iterations > 0) {
				try {
					using (var sr = new StreamReader(File.OpenRead(inputfile))) {
						var text = sr.ReadToEnd();
						var bytetext = Encoding.ASCII.GetBytes(text);
						long text2text;
						long byte2byte;

						Stopwatch s = new Stopwatch();
						s.Start();
						for (long i = 0; i < options.Iterations; i++) {
							md.Transform(text);
						}
						text2text = s.ElapsedMilliseconds;
						s.Stop();
						s.Reset();
						s.Start();
						for (long i = 0; i < options.Iterations; i++) {
							md.Transform(bytetext);
						}
						byte2byte = s.ElapsedMilliseconds;
						s.Stop();
						Console.WriteLine("{0} iterations", options.Iterations);
						Console.WriteLine("text2text: {0}", text2text);
						Console.WriteLine("byte2byte: {0}", byte2byte);
					}
				} catch (Exception exception) {
					Console.WriteLine("Unable to open input file {0}: {1}", inputfile, exception.Message);
					return;
				}
				return;
			}

			using (Buffer buffer = Buffer.Create())
			try {
				using (var sr = new StreamReader(File.OpenRead(inputfile)))
				md.Render(buffer, sr.ReadToEnd());
			} catch (Exception exception) {
				Console.WriteLine("Unable to open input file {0}: {1}", inputfile, exception.Message);
				return;
			} finally {
				Console.Write(buffer);
			}
		}