Beispiel #1
0
def process_css(html, stylesheets):
	p = Processor()
	parser = etree.HTMLParser()
	tree = etree.fromstring(html, parser).getroottree()
	page = tree.getroot()

	if page is None:
		print repr(html)
		raise ParserError("Could not parse the HTML")

	body, = CSSSelector('body')(page)

	processed_css = ''

	for sheet in stylesheets:
		sheet_path = normpath(join(PROJECT_ROOT, sheet))

		with open(sheet_path, 'r') as sheet_file:
			content = unicode(sheet_file.read(), 'utf-8')
			processed_css += p._process_content(content, [body, ])

	return cssmin(processed_css)