CsCss icon indicating copy to clipboard operation
CsCss copied to clipboard

Unable to parse URL from google font face

Open minhnguyenlinknode opened this issue 7 years ago • 0 comments

I need to parse URLs from this CSS content but it returns nothing:

@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 400;
  src: local('Montserrat Regular'), local('Montserrat-Regular'), url(https://fonts.gstatic.com/s/montserrat/v12/rBHvpRWBkgyW99dXT88n7yEAvth_LlrfE80CYdSH47w.woff2) format('woff2');
  unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}

I have used this code to get URLs:

 var uris = _cssLoader.AllStyleRules
                .SelectMany(styleRule => styleRule.Declaration.AllData)
                .SelectMany(prop => prop.Value.Unit == CssUnit.List ? prop.Value.List : new[] { prop.Value })
                .Where(val => val.Unit == CssUnit.Url)
                // Get unresolved URLs (you can use Uri property to get resolved URLs)
                .Select(val => val.OriginalUri)              
                .ToList();

minhnguyenlinknode avatar Jan 17 '18 13:01 minhnguyenlinknode