Guys, I need to develop a tool that will meet the following requirements:
- Input: XHTML document with CSS rules in the section
head. - Exit: XHTML document with CSS rules computed in tag attributes
The best way to illustrate the behavior I want is as follows.
Input Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<style type="text/css" media="screen">
.a { color: red; }
p { font-size: 12px; }
</style>
</head>
<body>
<p class="a">Lorem Ipsum</p>
<div class="a">
<p>Oh hai</p>
</div>
</body>
</html>
Output Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<body>
<p style="color: red; font-size: 12px;">Lorem Ipsum</p>
<div style="color: red;">
<p style="font-size: 12px;">Oh hai</p>
</div>
</body>
</html>
What tools / libraries are best suited for such a task? I'm not sure if BeautifulSoup and cssutils are able to do this.
Python is not a requirement. Any recommendations would be highly appreciated.
source
share