From 2667105b94990ebbec1ee1e460cd451fc0591a0a Mon Sep 17 00:00:00 2001 From: Anthony Barnes Date: Thu, 25 Aug 2016 14:30:59 +1000 Subject: [PATCH] Added Node & JSDom example. --- README.markdown | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.markdown b/README.markdown index 7f4df3fb..a3598c8a 100644 --- a/README.markdown +++ b/README.markdown @@ -64,6 +64,8 @@ debugging purposes, follow the above steps, but run grunt build-debugContrib/PhantomJS/HTMLCS_Run.js file for more information. +#### Node & JSDom. + +HTML_CodeSniffer requires a dom to run, however, it is possible to run it entirely +server side without a headless browser using Node on arbitrary fragments of HTML using +an environment wrapper like [JSDom](https://github.com/tmpvar/jsdom). + +An example node script: +```javascript +var jsdom = require('jsdom'); +var fs = require('fs'); + +var vConsole = jsdom.createVirtualConsole(); + +// Forward messages to the console. +vConsole.on('log', function(message) { + console.log(message); +}) + +jsdom.env({ + html: '', + src: [fs.readFileSync('./build/HTMLCS.js')], + virtualConsole: vConsole, + done: function (err, window) { + window.HTMLCS_RUNNER.run('WCAG2AA'); + } +}); +``` + ### Contributing and reporting issues To report any issues with using HTML_CodeSniffer, please use the