using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace umbraco.presentation.ClientDependency { public class CssFileUrlFormatter { /// /// Returns the CSS file with all of the url's formatted to be absolute locations /// /// content of the css file /// the uri location of the css file /// public static string TransformCssFile(string fileContent, Uri cssLocation) { string str = Regex.Replace( fileContent, @"url\((.+)\)", new MatchEvaluator( delegate(Match m) { if (m.Groups.Count == 2) { string match = m.Groups[1].Value.Trim('\'', '"'); return string.Format(@"url(""{0}"")", match.StartsWith("http") ? match : new Uri(cssLocation, match).ToString()); } return m.Value; }) ); return str; } } }