Documentation ¶
Overview ¶
Package validate validates HTML and related documents.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AMPFiles ¶
AMPFiles runs amphtml-validator to validate multiple AMP HTML files at the supplied paths. The returned map is keyed by the filenames from the paths argument.
AMPFiles may be much faster than AMP when validating multiple files, since the WebAssembly-based amphtml-validator can take a substantial amount of time to start: https://github.com/ampproject/amphtml/issues/37585.
func LaunchBrowser ¶
LaunchBrowser launches a web browser with the supplied HTML page. It can be used to display results pages returned by the CSS and HTML functions.
Types ¶
type FileType ¶
type FileType string
FileType describes the type of file being validated.
const ( // Stylesheet is a standalone CSS stylesheet. Stylesheet FileType = "text/css" // HTMLDoc is an HTML document. HTMLDoc = "text/html" )
type Issue ¶
type Issue struct { // Severity describes the seriousness of the issue. Severity Severity // Line contains the 1-indexed line number where the issue occurred. // It is 0 if the line is unknown. Line int // Col contains the 1-indexed column number where the issue occurred. // It is 0 if the column is unknown. Col int // Message describes the issue. Message string // Code contains an optional code provided by the validator. Code string // Context optionally provides more detail about the context in which the issue occurred. Context string // Context optionally provides a URL with more information about the issue. URL string }
Issue describes a problem reported by a validator.
func AMP ¶
AMP reads an AMP HTML document from r and validates it by running the amphtml-validator program, which must be present in $PATH. Issues identified by the validator are parsed and returned. If the returned error is non-nil, an issue occurred in the validation process.
There unfortunately don't appear to be any online AMP validators that can be called programmatically. As a result, this function requires that the amphtml-validator Node.js program is installed locally. See https://amp.dev/documentation/guides-and-tutorials/learn/validation-workflow/validate_amp/#command-line-tool for more information about installing and running amphtml-validator.
More info about the lack of online validators:
The official AMP validator at https://validator.ampproject.org/ performs validation in the browser rather providing an HTTP server accepting posted documents.
Google provides an online AMP (and structured data) validator at https://search.google.com/test/amp, but it's very slow and it's not clear to me whether there's an easy way to use it outside of a web browser.
Cloudflare announced an online validator in 2017 at https://blog.cloudflare.com/amp-validator-api/, but it has since been shut down. That post points at https://blog.cloudflare.com/announcing-amp-real-url/ as justification, although I don't see any explanation of the validator's disappearance there.
The ampbench project seems to have provided an online validator, but it was apparently shut down in 2019 due to the codebase getting out of date: https://github.com/ampproject/ampbench/issues/126
There's more discussion at https://github.com/ampproject/amphtml/issues/1968.
func CSS ¶
CSS reads an HTML or CSS document from r and validates its CSS content using https://jigsaw.w3.org/css-validator/. FileType describes the type of file being validated: the W3C validator seems to have the unfortunate property of reporting that the data validated successfully if the wrong type is supplied.
Parsed issues and the raw HTML results page returned by the validation service are returned. If the returned error is non-nil, an issue occurred in the validation process.
func HTML ¶
HTML reads an HTML document from r and validates it using https://validator.w3.org/nu/. Parsed issues and the raw HTML results page returned by the validation service are returned. If the returned error is non-nil, an issue occurred in the validation process.