diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-05-07 21:44:57 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-05-07 21:44:57 +0000 |
| commit | 1ccd812fd633ca0f5da89b0fb6acfbf3136868d2 (patch) | |
| tree | 008bb43baaae96f87a277f7168ceb34c91d8084a | |
| parent | c3f394bb9b6a91ccde7b2255e46db463afc63652 (diff) | |
Read messages from result
| -rw-r--r-- | Mammoth.Tests/DocumentConverterTests.cs | 8 | ||||
| -rw-r--r-- | Mammoth.Tests/Mammoth.Tests.csproj | 3 | ||||
| -rw-r--r-- | Mammoth.Tests/TestDocuments/unrecognised-paragraph-styles.docx | bin | 0 -> 3400 bytes | |||
| -rw-r--r-- | Mammoth/DocumentConverter.cs | 10 | ||||
| -rw-r--r-- | Mammoth/mammoth.edge.js | 2 |
5 files changed, 21 insertions, 2 deletions
diff --git a/Mammoth.Tests/DocumentConverterTests.cs b/Mammoth.Tests/DocumentConverterTests.cs index 9a977c5..37cec23 100644 --- a/Mammoth.Tests/DocumentConverterTests.cs +++ b/Mammoth.Tests/DocumentConverterTests.cs @@ -12,5 +12,13 @@ namespace Mammoth.Tests Assert.AreEqual("<p>Walking on imported air</p>", result.Value); Assert.IsEmpty(result.Messages); } + + [Test] + public void UnrecognisedStylesAreStatedInMessages() + { + var documentConverter = new DocumentConverter(); + var result = documentConverter.ConvertToHtml("TestDocuments/unrecognised-paragraph-styles.docx"); + Assert.AreEqual("Unrecognised paragraph style: 'Funky' (Style ID: style20)", result.Messages[0].Value); + } } } diff --git a/Mammoth.Tests/Mammoth.Tests.csproj b/Mammoth.Tests/Mammoth.Tests.csproj index 963e64c..212db46 100644 --- a/Mammoth.Tests/Mammoth.Tests.csproj +++ b/Mammoth.Tests/Mammoth.Tests.csproj @@ -68,6 +68,9 @@ <None Include="TestDocuments\single-paragraph.docx"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> + <None Include="TestDocuments\unrecognised-paragraph-styles.docx"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> </ItemGroup> <ItemGroup> <ProjectReference Include="..\Mammoth\Mammoth.csproj"> diff --git a/Mammoth.Tests/TestDocuments/unrecognised-paragraph-styles.docx b/Mammoth.Tests/TestDocuments/unrecognised-paragraph-styles.docx Binary files differnew file mode 100644 index 0000000..ad4064f --- /dev/null +++ b/Mammoth.Tests/TestDocuments/unrecognised-paragraph-styles.docx diff --git a/Mammoth/DocumentConverter.cs b/Mammoth/DocumentConverter.cs index 84c1f85..6057cbd 100644 --- a/Mammoth/DocumentConverter.cs +++ b/Mammoth/DocumentConverter.cs @@ -1,6 +1,7 @@ using EdgeJs; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Reflection; using System.Threading.Tasks; @@ -16,7 +17,14 @@ namespace Mammoth var result = f(File.ReadAllBytes(path)); Task.WaitAll(result); - return new Result<string>((string)result.Result, new List<Message>()); + return ReadResult(result.Result); + } + + private Result<string> ReadResult(dynamic result) + { + var rawMessages = (dynamic[])result.messages; + var messages = rawMessages.Select(message => Message.Warning((string)message.message)).ToList(); + return new Result<string>(result.value, messages); } private static string ReadResource(string resourceName) diff --git a/Mammoth/mammoth.edge.js b/Mammoth/mammoth.edge.js index a5a96a9..fe0202b 100644 --- a/Mammoth/mammoth.edge.js +++ b/Mammoth/mammoth.edge.js @@ -4,7 +4,7 @@ return function(data, callback) { mammoth.convertToHtml({arrayBuffer: toArrayBuffer(data)}) .then(function(result) { - callback(null, result.value); + callback(null, result); }, callback); function toArrayBuffer(buffer) { |
