Example #1
0
        public static string MinifyString(string extension, string content)
        {
            if (extension == ".css")
            {
                Minifier    minifier = new Minifier();
                CssSettings settings = new CssSettings();
                settings.CommentMode = CssComment.None;

                if (WESettings.GetBoolean(WESettings.Keys.KeepImportantComments))
                {
                    settings.CommentMode = CssComment.Important;
                }

                return(minifier.MinifyStyleSheet(content, settings));
            }
            else if (extension == ".js")
            {
                Minifier     minifier = new Minifier();
                CodeSettings settings = new CodeSettings()
                {
                    EvalTreatment             = EvalTreatment.MakeImmediateSafe,
                    PreserveImportantComments = WESettings.GetBoolean(WESettings.Keys.KeepImportantComments)
                };

                return(minifier.MinifyJavaScript(content, settings));
            }

            return(null);
        }
Example #2
0
        public static string MinifyString(string extension, string content)
        {
            if (extension == ".css")
            {
                Minifier    minifier = new Minifier();
                CssSettings settings = new CssSettings();
                settings.CommentMode = CssComment.None;

                if (WESettings.GetBoolean(WESettings.Keys.KeepImportantComments))
                {
                    settings.CommentMode = CssComment.Important;
                }

                return(minifier.MinifyStyleSheet(content, settings));
            }
            else if (extension == ".js")
            {
                Minifier     minifier = new Minifier();
                CodeSettings settings = new CodeSettings()
                {
                    EvalTreatment             = EvalTreatment.MakeImmediateSafe,
                    PreserveImportantComments = WESettings.GetBoolean(WESettings.Keys.KeepImportantComments)
                };

                return(minifier.MinifyJavaScript(content, settings));
            }
            else if (_htmlExt.Contains(extension.ToLowerInvariant()))
            {
                var minifyer = new XhtmlMinifier();
                MarkupMinificationResult result = minifyer.Minify(content, generateStatistics: true);

                if (result.Errors.Count == 0)
                {
                    EditorExtensionsPackage.DTE.StatusBar.Text = "Web Essentials: HTML minified by " + result.Statistics.SavedInPercent + "%";
                    return(result.MinifiedContent);
                }
                else
                {
                    EditorExtensionsPackage.DTE.StatusBar.Text = "Web Essentials: Cannot minify the current selection";
                    return(content);
                }
            }

            return(null);
        }