aboutsummaryrefslogtreecommitdiff
path: root/Mammoth/DocumentConverter.cs
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2017-05-10 20:11:39 +0100
committerMichael Williamson <mike@zwobble.org>2017-05-10 20:11:39 +0100
commitd46578f9c125e4700f0c8e1f4db3d896edb9cd92 (patch)
tree63fe2045daadce4d5d769173edc79f6efc52853c /Mammoth/DocumentConverter.cs
parentc70ed0148f584d5fa23f1c553cd618bc3368dd3c (diff)
Add support for image converters
Diffstat (limited to 'Mammoth/DocumentConverter.cs')
-rw-r--r--Mammoth/DocumentConverter.cs30
1 files changed, 30 insertions, 0 deletions
diff --git a/Mammoth/DocumentConverter.cs b/Mammoth/DocumentConverter.cs
index 59b09e1..4995e54 100644
--- a/Mammoth/DocumentConverter.cs
+++ b/Mammoth/DocumentConverter.cs
@@ -1,3 +1,5 @@
+using System;
+using System.Collections.Generic;
using System.IO;
using Mammoth.Couscous;
using Mammoth.Couscous.org.zwobble.mammoth.@internal;
@@ -33,6 +35,34 @@ namespace Mammoth {
public DocumentConverter DisableEmbeddedStyleMap() {
return new DocumentConverter(options.disableEmbeddedStyleMap());
}
+
+ public DocumentConverter ImageConverter(Func<IImage, IDictionary<string, string>> imageConverter) {
+ return new DocumentConverter(options.imageConverter(new ImageConverterShim(imageConverter)));
+ }
+
+ internal class ImageConverterShim : Mammoth.Couscous.org.zwobble.mammoth.images.ImageConverter__ImgElement {
+ private readonly Func<IImage, IDictionary<string, string>> func;
+
+ internal ImageConverterShim(Func<IImage, IDictionary<string, string>> func) {
+ this.func = func;
+ }
+
+ public Mammoth.Couscous.java.util.Map<string, string> convert(Mammoth.Couscous.org.zwobble.mammoth.images.Image image) {
+ return ToJava.DictionaryToMap(func(new Image(image)));
+ }
+ }
+
+ internal class Image : IImage {
+ private readonly Mammoth.Couscous.org.zwobble.mammoth.images.Image image;
+
+ internal Image(Mammoth.Couscous.org.zwobble.mammoth.images.Image image) {
+ this.image = image;
+ }
+
+ public string AltText { get { return image.getAltText().orElse(null); } }
+ public string ContentType { get { return image.getContentType(); } }
+ public Stream GetStream() { return image.getInputStream().Stream; }
+ }
public IResult<string> ConvertToHtml(Stream stream) {
return new InternalDocumentConverter(options)