diff --git a/src/Postal.AspNetCore/HtmlExtensions.cs b/src/Postal.AspNetCore/HtmlExtensions.cs index d311cb5..8567c0e 100644 --- a/src/Postal.AspNetCore/HtmlExtensions.cs +++ b/src/Postal.AspNetCore/HtmlExtensions.cs @@ -24,19 +24,18 @@ public static class HtmlExtensions /// An image file path or URL. A file path can be relative to the web application root directory. /// The content for the <img alt> attribute. /// An HTML <img> tag. - public static IHtmlContent EmbedImage(this IHtmlHelper html, string imagePathOrUrl, string alt = "") + public static IHtmlContent EmbedImage(this IHtmlHelper html, string imagePathOrUrl, string alt = "", string style = "") { if (string.IsNullOrWhiteSpace(imagePathOrUrl)) throw new ArgumentException("Path or URL required", "imagePathOrUrl"); if (IsFileName(imagePathOrUrl)) { var hosting = html.ViewContext.HttpContext.RequestServices.GetService(); - string webRootPath = hosting.WebRootPath; - imagePathOrUrl = System.IO.Path.Combine(webRootPath, imagePathOrUrl); + imagePathOrUrl = hosting.WebRootPath + System.IO.Path.DirectorySeparatorChar + imagePathOrUrl.Replace('/', System.IO.Path.DirectorySeparatorChar).Replace('\\', System.IO.Path.DirectorySeparatorChar); } var imageEmbedder = (ImageEmbedder)html.ViewData[ImageEmbedder.ViewDataKey]; var resource = imageEmbedder.ReferenceImage(imagePathOrUrl); - return new HtmlString(string.Format("\"{1}\"/", resource.ContentId, html.Encode(alt))); + return new HtmlString(string.Format("\"{1}\"", resource.ContentId, html.Encode(alt), html.Encode(style))); } static bool IsFileName(string pathOrUrl)