diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-05-07 21:27:34 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-05-07 21:27:34 +0000 |
| commit | c3f394bb9b6a91ccde7b2255e46db463afc63652 (patch) | |
| tree | e3e5d670be450ed774f0fb0ca587a3bde53fa4b8 /Mammoth/DocumentConverter.cs | |
Use edge.js to run mammoth.js from .NET
Diffstat (limited to 'Mammoth/DocumentConverter.cs')
| -rw-r--r-- | Mammoth/DocumentConverter.cs | 34 |
1 files changed, 34 insertions, 0 deletions
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<string> 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>((string)result.Result, new List<Message>()); + } + + 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(); + } + } + } + } +} |
