diff --git a/weasy/css/__init__.py b/weasy/css/__init__.py index 97d13866..0e54ff61 100644 --- a/weasy/css/__init__.py +++ b/weasy/css/__init__.py @@ -83,6 +83,7 @@ def find_stylesheets(document): Find and parse stylesheets in a Document object. Return an iterable of stylesheets, in tree order. """ + parser = document.css_parser for element in document.dom.iter(): if element.tag not in ('style', 'link'): continue @@ -102,15 +103,17 @@ def find_stylesheets(document): content = ''.join(content) # lxml should give us either unicode or ASCII-only bytestrings, so # we don't need `encoding` here. - yield parseString(content, href=element.base_url, - media=media_attr, title=element.get('title')) + yield parser.parseString(content, + href=element.base_url, + media=media_attr, title=element.get('title')) elif element.tag == 'link' and element.get('href') \ and ' stylesheet ' in ' %s ' % element.get('rel', ''): # URLs should NOT have been made absolute earlier # TODO: support the HTML element, but do not use # lxml.html.HtmlElement.make_links_absolute() that changes the tree href = get_url_attribute(element, 'href') - yield parseUrl(href, media=media_attr, title=element.get('title')) + yield parser.parseUrl(href, + media=media_attr, title=element.get('title')) def find_style_attributes(document): diff --git a/weasy/document.py b/weasy/document.py index ab20055a..e218d50f 100644 --- a/weasy/document.py +++ b/weasy/document.py @@ -21,7 +21,7 @@ import os.path import math import logging -from cssutils import parseFile +from cssutils import parseFile, CSSParser import lxml.html import cairo @@ -54,6 +54,9 @@ class Document(object): # Go through the property setter which calls ensure_url() self.base_url = self.base_url + self.css_parser = CSSParser() + self.css_parser.setFetcher(utils.urllib_fetcher) + self.user_stylesheets = user_stylesheets or [] self.user_agent_stylesheets = user_agent_stylesheets or [] diff --git a/weasy/tests/resources/doc1.html b/weasy/tests/resources/doc1.html index 510a9add..a373a439 100644 --- a/weasy/tests/resources/doc1.html +++ b/weasy/tests/resources/doc1.html @@ -2,10 +2,11 @@ + +