在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:squizlabs/HTML_CodeSniffer开源软件地址:https://github.com/squizlabs/HTML_CodeSniffer开源编程语言:JavaScript 94.3%开源软件介绍:HTML_CodeSnifferWhat is HTML_CodeSniffer?HTML_CodeSniffer is a JavaScript application that checks a HTML document or source code, and detects violations of a defined presentation or accessibility standard, such as Section508 or WCAG2.1. Standards includedBy default, HTML_CodeSniffer comes with standards that cover the three conformance levels of the W3C Web Content Accessibility Guidelines (WCAG) 2.1, and the U.S. Section 508 legislation. It also provides tools to write your own standards, which can be useful in situations where you wish to enforce consistency across a web site. Using HTML_CodeSnifferHTML_CodeSniffer can be called in multiple ways:
Using the source codeBuilding the auditorThe HTML_CodeSniffer auditor can be built using Node.js and Grunt task runner. It has been tested with the recent version of Node.js (starting from version 6.0) and Grunt.
You should see two new directories: Then grab or copy the JavaScript from the auditor bookmarklet from the HTML_CodeSniffer site, replace the directory at the start (//squizlabs.github.io/HTML_CodeSniffer/build) with your local URL, and save as a new bookmarklet. Debug buildIf you are developing using HTML_CodeSniffer and require the code not minified for
debugging purposes, follow the above steps, but run Command-Line processingNote: These examples assume a built version of HTMLCS exported to PhantomJSYou will need PhantomJS installed if you wish to use the contributed command-line script. PhantomJS provides a headless Webkit-based browser to run the scripts in, so it should provide results that are similar to recent (or slightly less than recent) versions of Safari. See the Headless Google Chrome via PuppeteerPuppeteer offers an easy way to interact with the page via Google Chrome. This example assumes that there is the latest version of Google Chrome installed,
hence only the npm i puppeteer-core The test script assumes a recent version of Node.js to be available. const puppeteer = require('puppeteer-core');
// Replace with the path to the chrome executable in your file system. This one assumes MacOSX.
const executablePath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
// Replace with the url you wish to test.
const url = 'https://www.squiz.net';
(async () => {
const browser = await puppeteer.launch({
executablePath
});
const page = await browser.newPage();
page.on('console', msg => {
console.log(msg.text())
});
await page.goto(url);
await page.addScriptTag({
path: 'build/HTMLCS.js'
});
await page.evaluate(function () {
HTMLCS_RUNNER.run('WCAG2AA');
});
await browser.close();
})(); Node.js & JSDomHTML_CodeSniffer requires a DOM to run, however, it is possible to run it entirely server side without a headless browser using Node.js on arbitrary fragments of HTML using an environment wrapper like JSDom. An example Node.js script: var jsdom = require('jsdom');
var { JSDOM } = jsdom;
var fs = require('fs');
var HTMLCS = fs.readFileSync('./build/HTMLCS.js', 'utf-8');
var vConsole = new jsdom.VirtualConsole();
// Forward messages to the console.
vConsole.on('log', function(message) {
console.log(message)
});
var dom = new JSDOM('<img src="test.png" />', {
runScripts: "dangerously",
virtualConsole: vConsole
});
dom.window.eval(HTMLCS);
dom.window.HTMLCS_RUNNER.run('WCAG2AA'); TranslationsHTML_CodeSniffer supports very basic string translations. The auditor will use the current language of the document it is being run in (e.g. Example usage: HTMLCSAuditor.run('WCAG2AA', null, {
lang: 'pl'
}); Note: HTML_CodeSniffer only has English (default), French, and Polish languages. If other language support is required a custom version can be built by adding more translations in Contributing and reporting issuesTo report any issues with using HTML_CodeSniffer, please use the HTML_CodeSniffer Issue Tracker. Contributions to the HTML_CodeSniffer code base are also welcome: please create a fork of the main repository, then submit your modified code through a Pull Request for review. A Pull Request also automatically creates an issue in the Issue Tracker, so if you have code to contribute, you do not need to do both. More InformationMore information on HTML_CodeSniffer can be found on its GitHub site, http://squizlabs.github.io/HTML_CodeSniffer/. This site provides:
Translation ContributorsSpecial thanks to:
LicenseLicensed under the BSD 3-Clause "New" or "Revised" License. License text also available in the |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论