Validate HTML pages in Go
- Go 100%
validate
The codeberg.org/derat/validate Go package validates:
- HTML documents using the W3C's online "Nu Html Checker"
- CSS using the W3C's online CSS Validation Service
- AMP HTML documents using a local installation of the amphtml-validator Node.js program
Supplied documents are uploaded (in the case of online validators) and any issues identified by the validator are parsed and returned.
Usage
import("codeberg.org/derat/validate")// ...f,err:=os.Open("page.html")iferr!=nil{// ...}deferf.Close()// See also validate.AMP() and validate.CSS().issues,out,err:=validate.HTML(context.Background(),f)iferr!=nil{// ...}// Iterate over the parsed issues.for_,is:=rangeissues{fmt.Println(is)}// Display the full results page in a browser.iferr:=validate.LaunchBrowser(out);err!=nil{// ...}A command-line program named validate_page that validates a file or a document provided over stdin is also provided:
% go install codeberg.org/derat/validate/cmd/validate_page
% validate_page -browser page.html
% validate_page -type=amp index.amp.html
% validate_page <style.css
% validate_page -type=htmlcss -browser page.html # check CSS in HTML doc