Quantcast
Channel: HTML Renderer
Viewing all articles
Browse latest Browse all 693

New Post: External CSS background-image from external CSS stylesheet

$
0
0
Stupid bug, sorry, will be fixed in next version.

If you need a quick fix replace "CorrectRelativeUrls" method in "StylesheetLoadHandler" with:
int idx = 0;
while( idx != -1 && idx < stylesheet.Length )
{
    idx = stylesheet.IndexOf("url", idx, StringComparison.OrdinalIgnoreCase);
    if( idx > 0 )
    {
        int endIdx = stylesheet.IndexOf(")", idx, StringComparison.OrdinalIgnoreCase);
        if( endIdx > 0 )
        {
            var offset1 = 4 + (stylesheet[idx + 4] == '\'' ? 1 : 0);
            var offset2 = (stylesheet[endIdx -1] == '\'' ? 1 : 0);
            var urlStr = stylesheet.Substring(idx + offset1, endIdx - idx - offset1 - offset2);
            Uri url;
            if( Uri.TryCreate(urlStr, UriKind.Relative, out url) )
            {
                url = new Uri(baseUri, url);
                stylesheet = stylesheet.Remove(idx + 4, endIdx - idx - 4);
                stylesheet = stylesheet.Insert(idx + 4, url.AbsoluteUri);
                idx += url.AbsoluteUri.Length + 4;
            }
            else
            {
                idx = endIdx + 1;
            }
        }
    }
}

return stylesheet;

Viewing all articles
Browse latest Browse all 693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>