如何验证脚本中的CSS? [英] How can I validate CSS within a script?

查看:211
本文介绍了如何验证脚本中的CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可以验证CSS的库?



我可以找到的唯一工具是网站。如果这些网站之一有一个API,也符合帐单。



我有一个脚本,作为一个CSS编译器。它根据主题的设置设置各种变量,并生成和写入CSS文件。在提交编写CSS文件之前,我想验证它,以确保没有任何无效的条目。



PHP将是方便,但Python,Perl ,Ruby,Java或任何可执行文件都是可以的。



理想情况下,有一些东西可以作为序列的一部分使用:

  $ css_file = theme_compile('theme-name'); 
if(!validate_css($ css_file)){
echocss文件包含无效的条目width:px'; //只是一个例子,当然是
}
else {
file_put_contents('/ path / css_file',$ css_file); W3C有一个API: / p>

http:// jigsaw。 w3.org/css-validator/api.html



您也可以下载验证器并在本地运行:
http://jigsaw.w3.org/css-validator/DOWNLOAD.html



您需要能够从脚本中运行java。


Is there a library out there which will validate CSS?

The only tools I can find to do so are web sites. If one of these sites has an API, that would fit the bill, too.

I have a script that serves as a CSS compiler. It sets various variables according to settings for a theme, and generates and writes a CSS file. Before committing to writing the CSS file, I'd like to validate it to make sure there aren't any invalid entries.

PHP would be convenient, but Python, Perl, Ruby, Java, or anything executable from a shell would be fine.

Ideally, there's something out there that I can use as part of a sequence like:

 $css_file=theme_compile('theme-name');
 if(!validate_css($css_file)){
   echo "css file contained invalid entry 'width:px'";//just an example, of course
   }   
 else{
   file_put_contents('/path/css_file',$css_file);
   }

解决方案

W3C has an API:

http://jigsaw.w3.org/css-validator/api.html

You can also download the validator and run it locally: http://jigsaw.w3.org/css-validator/DOWNLOAD.html

You need to be able to run java from your script.

这篇关于如何验证脚本中的CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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