开发者

Validate HTML on local machine

开发者 https://www.devze.com 2023-01-13 04:01 出处:网络
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

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.ht开发者_如何转开发m (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:

http://htmlhelp.com/tools/validator/offline/index.html.en


You can download a vnu.jar release for checking HTML5 documents offline:

https://github.com/validator/validator/releases/download/latest/vnu.jar

Alternatively, you can install it using any of the following:

  • docker run -it --rm -p 8888:8888 ghcr.io/validator/validator:latest
  • npm install vnu-jar
  • brew install vnu
  • pip install html5validator

See https://validator.github.io/validator/ for more details.


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


You can run the tool on your local with docker just by using the command below.

  • docker run -it --rm -p 8888:8888 ghcr.io/validator/validator:latest

After running it with docker, when you go to 127.0.0.1:8888 you will see the validator tool. When you try to validate a url and if you get such an error like IO Error (Connection refused) then you can try installing vnu with brew by using the second command below.

  • brew install vnu

I tried it with docker and I got IO Error. Then I tried it with brew and it was successful. After you install it with brew, now to check a url you should run the command below.

  • vnu http://localhost/page-to-test/

Just replace the url with the one you want to validate with the tool.

0

精彩评论

暂无评论...
验证码 换一张
取 消