From c3f394bb9b6a91ccde7b2255e46db463afc63652 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 7 May 2015 21:27:34 +0000 Subject: Use edge.js to run mammoth.js from .NET --- Mammoth/DocumentConverter.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Mammoth/DocumentConverter.cs (limited to 'Mammoth/DocumentConverter.cs') diff --git a/Mammoth/DocumentConverter.cs b/Mammoth/DocumentConverter.cs new file mode 100644 index 0000000..84c1f85 --- /dev/null +++ b/Mammoth/DocumentConverter.cs @@ -0,0 +1,34 @@ +using EdgeJs; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Threading.Tasks; + +namespace Mammoth +{ + public class DocumentConverter + { + public Result ConvertToHtml(string path) + { + var mammothJs = ReadResource("Mammoth.mammoth.browser.js") + ReadResource("Mammoth.mammoth.edge.js"); + + var f = Edge.Func(mammothJs); + var result = f(File.ReadAllBytes(path)); + Task.WaitAll(result); + + return new Result((string)result.Result, new List()); + } + + private static string ReadResource(string resourceName) + { + var currentAssembly = Assembly.GetExecutingAssembly(); + using (var stream = currentAssembly.GetManifestResourceStream(resourceName)) + { + using (var reader = new StreamReader(stream)) + { + return reader.ReadToEnd(); + } + } + } + } +} -- cgit v1.2.3