Skip to content

Instantly share code, notes, and snippets.

@Aimeast
Created February 16, 2014 15:35
Show Gist options
  • Save Aimeast/9036104 to your computer and use it in GitHub Desktop.
Save Aimeast/9036104 to your computer and use it in GitHub Desktop.
Combine Highlight.js
// A highlight.js packer which work for Git Candy©
// The output please reference to https://github.com/Aimeast/GitCandy/blob/dev/GitCandy/Scripts/highlight.pack.js
class Program
{
static void Main(string[] args)
{
using (var writer = new StreamWriter("highlight.pack.js"))
{
writer.WriteLine("//https://github.com/isagalaev/highlight.js");
writer.WriteLine("//Version 8.0 (f08dbfd8c33d7d5c30d736b5a4ef4d1f361e93ae)");
writer.WriteLine();
writer.WriteLine("; (function (window) {");
writer.WriteLine("var hljs = new ");
writer.Write(ReadToEnd("highlight.js"));
writer.WriteLine("();");
foreach (var item in Directory.GetFiles("languages", "*.js"))
{
writer.WriteLine("hljs.registerLanguage(\"" + Path.GetFileNameWithoutExtension(item) + "\",");
writer.Write(ReadToEnd(item));
writer.WriteLine(");");
writer.WriteLine();
}
writer.WriteLine("window.hljs = hljs;");
writer.WriteLine("hljs.initHighlightingOnLoad();");
writer.WriteLine("})(window);");
}
}
static string ReadToEnd(string filename)
{
using (var reader = new StreamReader(filename))
{
var sb = new StringBuilder();
while (!reader.EndOfStream)
sb.AppendLine(reader.ReadLine());
return sb.ToString().TrimEnd(new[] { '\r', '\n' });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment