CSS解析器+ XHTML生成器,需要建议 [英] CSS parser + XHTML generator, advice needed

查看:76
本文介绍了CSS解析器+ XHTML生成器,需要建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我需要开发一种满足以下要求的工具:

Guys, I need to develop a tool which would meet following requirements:

  1. 输入:在head部分中具有CSS规则的XHTML文档.
  2. 输出:具有在标记属性中计算的CSS规则的XHTML文档
  1. Input: XHTML document with CSS rules within head section.
  2. Output: XHTML document with CSS rules computed in tag attributes

说明我想要的行为的最佳方法如下.

The best way to illustrate the behavior I want is as follows.

示例输入:

<!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>

示例输出:

<!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>

哪些工具/库最适合此类任务? 我不确定BeautifulSoup和cssutils是否能够做到这一点.

What tools/libraries will fit best for such task? I'm not sure if BeautifulSoup and cssutils is capable of doing this.

Python不是必需的. 任何建议将不胜感激.

Python is not a requirement. Any recommendations will be highly appreciated.

推荐答案

上有一个 premailer python软件包Pypi

这篇关于CSS解析器+ XHTML生成器,需要建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆