Created
October 22, 2014 21:59
-
-
Save archer884/dad49524188c592ecad8 to your computer and use it in GitHub Desktop.
Simple command line tool for generating HTML from Markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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