I'm currently trying to learn HTML and Java EE Servlet programming. I have an application server running on my local machine (Orion Application Server) and I'm connecting to web pages I've deployed on this server using a browser running on the same machine, directed to http://localhost/mypage.htm (for example).
I know W3C has a site you can go to that will validate an HTML page (and count how many errors are found for a given doctype), but that has to be a publicly available URL. How do you validate HTML on a locally running setup like I've described above?
many options:
see installation of w3c validation service:
http://validator.w3.org/docs/install.html
Firefox addons:
Firefox addon or other tool to locally validate HTML pages
https://addons.mozilla.org/en-US/firefox/addon/249/
Offline validator:
You can download a vnu.jar release for checking HTML5 documents offline. See https://github.com/validator/validator/releases/latest for the actual download file, and see https://validator.github.io/validator/ for more information
If you're using firefox, this plugin is perfect:
http://users.skynet.be/mgueury/mozilla/
I use it all day. When you view source it shows you a list of errors and highlights them for you.
A command line tool for validating a folder of html files: https://github.com/svenkreiss/html5validator
It integrates with CircleCI and TravisCI and can be used for validating Pelican and Jekyll sites.
Perhaps the most straightforward way to do this, is the way I do it all the time. "View source" of the web page, select it all (ctrl+a), choose "copy" (crtl+c), tab over to the validator, and its "direct input" option, and paste it in (ctrl+v). Easy, peasy.
On Mac, install w3validator by homebrew brew install vnu
. Then check your local site by vnu http://localhost/site
or any local file by vnu path/to/your/file.html
(From Bluu
answer)
If you're using node
you may use package html-validator
const validator = require('html-validator')
const fs = require('fs')
var options = {
format: 'text'
}
fs.readFile( 'file-to-validate.html', 'utf8', (err, html) => {
if (err) {
throw err;
}
options.data = html
validator(options)
.then((data) => {
console.log(data)
})
.catch((error) => {
console.error(error)
})
})
http://validator.w3.org/#validate_by_upload if you don't mind uploading the HTML source file.
http://getfirebug.com/ if you're running Firefox can help with HTML validation issues as well.
if you have internet connection and want to use https://validator.w3.org/ for localhost without installing, you can use ngrok
reference : https://academy.byidmore.com/post/W3C-Markup-Validation-for-Localhost-5bc942eb3704302c0986bd60
来源:https://stackoverflow.com/questions/3586207/validate-html-on-local-machine