Validate HTML on local machine
Asked Answered
T

10

40

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?

Tinsmith answered 27/8, 2010 at 16:21 Comment(1)
Firefox specific version (closed): #918919Easternmost
P
34

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

Pastorate answered 27/8, 2010 at 16:26 Comment(3)
On Ubuntu/Debian you can just sudo apt-get install w3c-markup-validatorSauls
I found this chrome extension very useful HTML Validator. It can validate a local page by submitting the source to W3C validatorMethodize
For HTML 5, you can use xmllint --noout --html page.html to validate one file. xmllint comes with the libxml2-utils package. w3c-markup-validator is meant to be used with a web server--it depends on Apache and installs that too.Nolannolana
S
14

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.

Seeley answered 22/10, 2014 at 10:20 Comment(5)
This is by far the most complete and up-to-date answer to this question as of today. A shame that it doesn't have more upvotes.Instead
On Mac, brew install vnu, then vnu path/to/your/file.html.Pivoting
@Pivoting please consider also adding a separate answer about the homebrew package to make it more noticeable (I didn’t know about it yet myself…)Seeley
They also added a "docker" version. "docker run -it --rm -p 8888:8888 ghcr.io/validator/validator:latest" and open a browser to 127.0.0.1:8888Priggery
@Priggery Thanks — I’ve updated the answer to include that tooSeeley
C
7

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.

Conciliar answered 27/8, 2010 at 16:27 Comment(0)
C
5

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.

Colewort answered 31/10, 2014 at 11:39 Comment(0)
L
2

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.

Leporide answered 26/1, 2015 at 2:16 Comment(6)
What if you have to validate a website with hundreds of pages? Is it still that easy? I run a website where most of the content is generated from TeX by a not-very-reliable Perl script. When I make any changes to the script, I want to be sure I did not break anything.Cystocarp
If your site has hundreds of pages, it is likely generated by a CMS such as Wordpress, Drupal or such. So all you need to do is validate a random sample of pages, and you are insuring that your CMS-generated pages validate. If you need to validate each and every page, perhaps an automated mechanism is required, but that is neither a) the original question, nor b) the W3C validator.Leporide
The original question asked how to validate HTML on local machine, it’s even in the title. You don’t answer that. I gave you an example of site where online validation is not feasible. Hard to guess why exactly the OP wanted the validator to run offline.Cystocarp
The OP's question was "the W3C validator assumes a publicly available page", how can I use it to validate something on "localhost"? It does NOT ask "how can I validate pages on my local machine without access to the internet at all". I pointed out a simple, software-free, solution to the question that uses the W3C validator.Leporide
@Leporide What did you mean by "tab over to the validator"? Did you mean the W3C validator site?Tymothy
Yes. Open the W3C validator in one browser tab. Open your web page's source view, copy it all and paste into the validator's "direct input" option. No, you can't do thousands of pages this way. No, it's not automatic. But if you, like me, are generating pages with a CMS, it's a great way to clean up things easily.Leporide
B
2

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)

Bozo answered 6/12, 2016 at 5:0 Comment(0)
C
1

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)
    })
})
Commentary answered 21/2, 2019 at 10:7 Comment(0)
D
0

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.

Dorotheadorothee answered 27/8, 2010 at 16:23 Comment(0)
J
0

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

Joviality answered 22/10, 2018 at 6:22 Comment(1)
Sounded interesting, but that link is deadPremise
R
0

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.

Ramification answered 16/12, 2021 at 14:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.