diff --git a/PreMailer.Net/PreMailer.Net.Tests/PreMailerTests.cs b/PreMailer.Net/PreMailer.Net.Tests/PreMailerTests.cs index 179f947..c523d24 100644 --- a/PreMailer.Net/PreMailer.Net.Tests/PreMailerTests.cs +++ b/PreMailer.Net/PreMailer.Net.Tests/PreMailerTests.cs @@ -710,5 +710,74 @@ public void MoveCssInline_EmptyTagsArePreserved() Assert.DoesNotContain("", premailedOutput.Html); Assert.DoesNotContain("", premailedOutput.Html); } + + [Fact] + public void MoveCssInline_BackwardCompatibility_StaticMethod_WithoutUseEmailFormatter() + { + // Test that the old method signature (without useEmailFormatter) still works + string input = "
test
"; + + // This should call the backward-compatible overload + var premailedOutput = PreMailer.MoveCssInline(input, false, null, null, false, false, null, false); + + Assert.Contains("
.test { height: 100px; }
test
"; + + var premailer = new PreMailer(input); + // This should call the backward-compatible instance method overload + var premailedOutput = premailer.MoveCssInline(false, null, null, false, false, null, false); + + Assert.Contains("
.test { height: 100px; }
test
"; + + using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(input))) + { + // This should call the backward-compatible Stream overload + var premailedOutput = PreMailer.MoveCssInline(stream, false, null, null, false, false, null, false); + + Assert.Contains("
.test { height: 100px; }
test
"; + var baseUri = new Uri("http://example.com/"); + + // This should call the backward-compatible Uri overload + var premailedOutput = PreMailer.MoveCssInline(baseUri, input, false, null, null, false, false, null, false); + + Assert.Contains("
.test { height: 100px; }
test
"; + var baseUri = new Uri("http://example.com/"); + + using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(input))) + { + // This should call the backward-compatible Uri + Stream overload + var premailedOutput = PreMailer.MoveCssInline(baseUri, stream, false, null, null, false, false, null, false); + + Assert.Contains("
+ /// In-lines the CSS within the HTML given. + /// + /// The HTML input. + /// If set to true the style elements are removed. + /// CSS selector for STYLE elements to ignore (e.g. mobile-specific styles etc.) + /// A string containing a style-sheet for inlining. + /// True to strip ID and class attributes + /// True to remove comments, false to leave them intact + /// Custom formatter to use + /// If set to true and removeStyleElements is true, it will instead preserve unsupported media queries in the style node and remove the other css, instead of removing the whole style node + /// Returns the html input, with styles moved to inline attributes. + public static InlineResult MoveCssInline(string html, bool removeStyleElements, string ignoreElements, string css, bool stripIdAndClassAttributes, bool removeComments, IMarkupFormatter customFormatter, bool preserveMediaQueries) + { + return new PreMailer(html).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, false); + } + /// /// In-lines the CSS within the HTML given. /// @@ -86,6 +103,23 @@ public static InlineResult MoveCssInline(string html, bool removeStyleElements = return new PreMailer(html).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, useEmailFormatter); } + /// + /// In-lines the CSS within the HTML given. + /// + /// The Stream input. + /// If set to true the style elements are removed. + /// CSS selector for STYLE elements to ignore (e.g. mobile-specific styles etc.) + /// A string containing a style-sheet for inlining. + /// True to strip ID and class attributes + /// True to remove comments, false to leave them intact + /// Custom formatter to use + /// If set to true and removeStyleElements is true, it will instead preserve unsupported media queries in the style node and remove the other css, instead of removing the whole style node + /// Returns the html input, with styles moved to inline attributes. + public static InlineResult MoveCssInline(Stream stream, bool removeStyleElements, string ignoreElements, string css, bool stripIdAndClassAttributes, bool removeComments, IMarkupFormatter customFormatter, bool preserveMediaQueries) + { + return new PreMailer(stream).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, false); + } + /// /// In-lines the CSS within the HTML given. /// @@ -104,6 +138,25 @@ public static InlineResult MoveCssInline(Stream stream, bool removeStyleElements return new PreMailer(stream).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, useEmailFormatter); } + /// + /// In-lines the CSS within the HTML given. + /// + /// /// The base url that will be used to resolve any relative urls + /// The Url that all relative urls will be off of. + /// The HTML input. + /// If set to true the style elements are removed. + /// CSS selector for STYLE elements to ignore (e.g. mobile-specific styles etc.) + /// A string containing a style-sheet for inlining. + /// True to strip ID and class attributes + /// True to remove comments, false to leave them intact + /// Custom formatter to use + /// If set to true and removeStyleElements is true, it will instead preserve unsupported media queries in the style node and remove the other css, instead of removing the whole style node + /// Returns the html input, with styles moved to inline attributes. + public static InlineResult MoveCssInline(Uri baseUri, string html, bool removeStyleElements, string ignoreElements, string css, bool stripIdAndClassAttributes, bool removeComments, IMarkupFormatter customFormatter, bool preserveMediaQueries) + { + return new PreMailer(html, baseUri).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, false); + } + /// /// In-lines the CSS within the HTML given. /// @@ -124,6 +177,25 @@ public static InlineResult MoveCssInline(Uri baseUri, string html, bool removeSt return new PreMailer(html, baseUri).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, useEmailFormatter); } + /// + /// In-lines the CSS within the HTML given. + /// + /// /// The base url that will be used to resolve any relative urls + /// The Url that all relative urls will be off of. + /// The HTML input. + /// If set to true the style elements are removed. + /// CSS selector for STYLE elements to ignore (e.g. mobile-specific styles etc.) + /// A string containing a style-sheet for inlining. + /// True to strip ID and class attributes + /// True to remove comments, false to leave them intact + /// Custom formatter to use + /// If set to true and removeStyleElements is true, it will instead preserve unsupported media queries in the style node and remove the other css, instead of removing the whole style node + /// Returns the html input, with styles moved to inline attributes. + public static InlineResult MoveCssInline(Uri baseUri, Stream stream, bool removeStyleElements, string ignoreElements, string css, bool stripIdAndClassAttributes, bool removeComments, IMarkupFormatter customFormatter, bool preserveMediaQueries) + { + return new PreMailer(stream, baseUri).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, false); + } + /// /// In-lines the CSS within the HTML given. /// @@ -144,6 +216,22 @@ public static InlineResult MoveCssInline(Uri baseUri, Stream stream, bool remove return new PreMailer(stream, baseUri).MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, useEmailFormatter); } + /// + /// In-lines the CSS for the current HTML + /// + /// If set to true the style elements are removed. + /// CSS selector for STYLE elements to ignore (e.g. mobile-specific styles etc.) + /// A string containing a style-sheet for inlining. + /// True to strip ID and class attributes + /// True to remove comments, false to leave them intact + /// Custom formatter to use + /// If set to true and removeStyleElements is true, it will instead preserve unsupported media queries in the style node and remove the other css, instead of removing the whole style node + /// Returns the html input, with styles moved to inline attributes. + public InlineResult MoveCssInline(bool removeStyleElements, string ignoreElements, string css, bool stripIdAndClassAttributes, bool removeComments, IMarkupFormatter customFormatter, bool preserveMediaQueries) + { + return MoveCssInline(removeStyleElements, ignoreElements, css, stripIdAndClassAttributes, removeComments, customFormatter, preserveMediaQueries, false); + } + /// /// In-lines the CSS for the current HTML ///