How can I validate CSS on internal web pages?

后端 未结 3 631
小蘑菇
小蘑菇 2020-12-05 08:00

I want to check internal web pages, so I cannot use the W3C validation service directly. I managed to run the XHTML validator locally, however, I have some problems with the

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 08:57

    That jar is runnable, but it needs some extra libraries.

    Examine the MANIFEST.MF file:

    $ unzip -p css-validator.jar META-INF/MANIFEST.MF
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.8.0
    Created-By: 1.6.0_26-b03 (Sun Microsystems Inc.)
    Main-Class: org.w3c.css.css.CssValidator
    Class-Path: . lib/commons-collections-3.2.1.jar lib/commons-lang-2.6.j
     ar lib/jigsaw.jar lib/tagsoup-1.2.jar lib/velocity-1.7.jar lib/xerces
     Impl.jar lib/xml-apis.jar lib/htmlparser-1.3.1.jar
    

    You need all the jars mentioned in Class-Path. You can download them from the maven repository using this script:

    #!/bin/bash
    
    set -e
    
    mkdir -p lib
    curl -LO http://www.w3.org/QA/Tools/css-validator/css-validator.jar
    echo "\
    http://repo1.maven.org/maven2/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
    http://repo1.maven.org/maven2/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
    http://repo1.maven.org/maven2/org/w3c/jigsaw/jigsaw/2.2.6/jigsaw-2.2.6.jar jigsaw.jar
    http://repo1.maven.org/maven2/org/ccil/cowan/tagsoup/tagsoup/1.2/tagsoup-1.2.jar
    http://repo1.maven.org/maven2/org/apache/velocity/velocity/1.7/velocity-1.7.jar
    http://repo1.maven.org/maven2/xerces/xercesImpl/2.11.0/xercesImpl-2.11.0.jar xercesImpl.jar
    http://repo1.maven.org/maven2/nu/validator/htmlparser/htmlparser/1.2.1/htmlparser-1.2.1.jar\
    " | while read url shortname; do
            if [ -z "$shortname" ]; then
                shortname="${url##*/}"
            fi
            curl -L -o "lib/${shortname}" "${url}"
        done
    

    After doing that, it works:

    $ java -jar css-validator.jar --output=soap12 file:badcss.html
    {vextwarning=false, output=soap12, lang=en, warning=2, medium=all, profile=css3}
    
    
        
            
                file:badcss.html
                http://jigsaw.w3.org/css-validator/
                css3
                2013-03-12T06:40:09Z
                false
                
                    
                        1
    
                    
                        file:badcss.html
    
                            
                                8
                                parse-error
                                 h1         
                                
                                    exp
                                
                                
                                    100%
                                
    
                                
    
                                    Property fnt-size doesn't exist : 
                                
                            
    
                        
    
                    
                    
                        1
    
                        
                            file:badcss.html
    
                            
                                5
                                0
                                You should add a 'type' attribute with a value of 'text/css' to the 'style' element
                            
    
                        
                        
                
            
        
    
    

提交回复
热议问题