Skip to content

Instantly share code, notes, and snippets.

@archer884
Created October 22, 2014 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save archer884/dad49524188c592ecad8 to your computer and use it in GitHub Desktop.
Save archer884/dad49524188c592ecad8 to your computer and use it in GitHub Desktop.
Simple command line tool for generating HTML from Markdown
using CommonMark;
using System;
using System.IO;
using System.Linq;
namespace PipeDown
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Provide a filename to parse.");
return;
}
var filePairs = args
.Where(File.Exists)
.Select(arg =>
{
var info = new FileInfo(arg);
return new
{
Source = info.FullName,
Target = info.FullName.Replace(info.Extension, ".html"),
};
}).ToList();
if (!filePairs.Any())
{
Console.WriteLine("No file found.");
return;
}
foreach (var item in filePairs)
{
using (var reader = new StreamReader(item.Source))
using (var writer = new StreamWriter(item.Target))
{
CommonMarkConverter.Convert(reader, writer);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment