在本地机器上验证 HTML

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3586207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:16:53  来源:igfitidea点击:

Validate HTML on local machine

htmlvalidationlocalhostw3c-validation

提问by dvanaria

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).

我目前正在尝试学习 HTML 和 Java EE Servlet 编程。我有一个应用程序服务器在我的本地机器上运行(Orion 应用程序服务器),并且我使用在同一台机器上运行的浏览器连接到我在这台服务器上部署的网页,定向到http://localhost/mypage.htm(例如)。

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?

我知道 W3C 有一个您可以访问的站点,该站点将验证 HTML 页面(并计算给定文档类型发现的错误数),但这必须是公开可用的 URL。您如何像我上面描述的那样在本地运行的设置中验证 HTML?

回答by sideshowbarker

You can download a vnu.jar release for checking HTML5 documents offline. See https://github.com/validator/validator/releases/latestfor the actual download file, and see https://validator.github.io/validator/for more information

您可以下载 vnu.jar 版本以离线检查 HTML5 文档。见https://github.com/validator/validator/releases/latest的实际下载文件,看https://validator.github.io/validator/了解更多信息

回答by Stephen

If you're using firefox, this plugin is perfect:

如果你使用 Firefox,这个插件是完美的:

http://users.skynet.be/mgueury/mozilla/

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.

我整天都在使用它。当您查看源代码时,它会向您显示错误列表并为您突出显示它们。

回答by svenkreiss

A command line tool for validating a folder of html files: https://github.com/svenkreiss/html5validator

用于验证 html 文件文件夹的命令行工具:https: //github.com/svenkreiss/html5validator

It integrates with CircleCI and TravisCI and can be used for validating Pelican and Jekyll sites.

它与 CircleCI 和 TravisCI 集成,可用于验证 Pelican 和 Jekyll 站点。

回答by CLWill

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.

也许最直接的方法就是我一直这样做的方式。网页的“查看源代码”,全选(ctrl+a),选择“复制”(crtl+c),切换到验证器及其“直接输入”选项,然后粘贴(ctrl+v )。十分简单。

回答by IqbalBary

On Mac, install w3validator by homebrew brew install vnu. Then check your local site by vnu http://localhost/siteor any local file by vnu path/to/your/file.html(From Bluuanswer)

在 Mac 上,通过 homebrew 安装 w3validator brew install vnu。然后vnu http://localhost/site通过vnu path/to/your/file.html(来自Bluu答案)检查您的本地站点或任何本地文件

回答by Aónio

If you're using nodeyou may use package html-validator

如果您正在使用,node您可以使用包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)
    })
})

回答by yussan

if you have internet connection and want to use https://validator.w3.org/for localhost without installing, you can use ngrok

如果您有互联网连接并想在不安装的情况下使用https://validator.w3.org/作为本地主机,您可以使用 ngrok

reference : https://academy.byidmore.com/post/W3C-Markup-Validation-for-Localhost-5bc942eb3704302c0986bd60

参考:https: //academy.byidmore.com/post/W3C-Markup-Validation-for-Localhost-5bc942eb3704302c0986bd60

回答by LesterDove

http://validator.w3.org/#validate_by_uploadif you don't mind uploading the HTML source file.

http://validator.w3.org/#validate_by_upload如果您不介意上传 HTML 源文件。

http://getfirebug.com/if you're running Firefox can help with HTML validation issues as well.

http://getfirebug.com/如果您运行 Firefox 也可以帮助解决 HTML 验证问题。