diff options
| author | Michael Williamson <mike@zwobble.org> | 2017-05-10 20:11:39 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2017-05-10 20:11:39 +0100 |
| commit | d46578f9c125e4700f0c8e1f4db3d896edb9cd92 (patch) | |
| tree | 63fe2045daadce4d5d769173edc79f6efc52853c /Mammoth.Tests | |
| parent | c70ed0148f584d5fa23f1c553cd618bc3368dd3c (diff) | |
Add support for image converters
Diffstat (limited to 'Mammoth.Tests')
| -rw-r--r-- | Mammoth.Tests/DocumentConverterTests.cs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Mammoth.Tests/DocumentConverterTests.cs b/Mammoth.Tests/DocumentConverterTests.cs index 416893f..5469e08 100644 --- a/Mammoth.Tests/DocumentConverterTests.cs +++ b/Mammoth.Tests/DocumentConverterTests.cs @@ -2,6 +2,7 @@ using System.IO; using Xunit.Sdk; using System; +using System.Collections.Generic; using System.Linq; namespace Mammoth.Tests { @@ -97,6 +98,28 @@ namespace Mammoth.Tests { Directory.Delete(tempDirectory, recursive: true); } } + + [Fact] + public void ImageConversionCanBeCustomised() { + AssertSuccessfulConversion( + ConvertToHtml("tiny-picture.docx", mammoth => mammoth.ImageConverter(ConvertImage)), + "<p><img src=\"iV,image/png\" /></p>" + ); + } + + private IDictionary<string, string> ConvertImage(IImage image) { + using (var stream = image.GetStream()) { + var base64 = StreamToBase64(stream); + var src = base64.Substring(0, 2) + "," + image.ContentType; + return new Dictionary<string, string> { { "src", src } }; + } + } + + private static string StreamToBase64(System.IO.Stream stream) { + var memoryStream = new System.IO.MemoryStream(); + stream.CopyTo(memoryStream); + return System.Convert.ToBase64String(memoryStream.ToArray()); + } [Fact] public void ContentTypesAreRead() { |
