Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow HTML source from file system and not just URLs. #75

Closed
andrewholgate opened this issue May 24, 2015 · 7 comments
Closed

Allow HTML source from file system and not just URLs. #75

andrewholgate opened this issue May 24, 2015 · 7 comments

Comments

@andrewholgate
Copy link

HTML Code Sniffer allows for files on file-system to be used as the source HTML.

This is very useful when you need to analyse many HTML files and want to break the process into 2 distinct phases:

  1. Download all HTML
  2. Analyse HTML files for WCAG compliance.
@whymarrh
Copy link

You can, as an example, download a bunch of HTML files, run a HTTP server locally, and test against that site. (There might be something in #10, #16, or #44 that gives you an idea.) Is that what you were thinking of?

e.g.

URL="tom.preston-werner.com"
wget --recursive --accept "*.html" "$URL"
cd "$URL"
python -m SimpleHTTPServer
# In another tab
pa11y http://localhost:8000/2010/08/23/readme-driven-development.html

@andrewholgate
Copy link
Author

Nice solution.

Using the PhantomJS HTMLCS_Run.js script that comes with HTML_CodeSniffer, this is possible without the need to load the HTML via an HTTP server:

wget tom.preston-werner.com -P html/
phantomjs node_modules/HTML_CodeSniffer/Contrib/PhantomJS/HTMLCS_Run.js html/index.html WCAG2A

@rowanmanning
Copy link
Member

Whymarrh's solution is what I'd go with for now. This feature might make it into pa11y 2.x, but I'm trying to reduce feature work on 1.x while that's in progress. I'll leave open until we have time to consider adding this :) thanks

@rowanmanning
Copy link
Member

@andrewholgate I'm not sure about Windows and Linux, but on a Mac you can actually test a file URL with pa11y like this:

pa11y file:///tmp/pa11y.html

Would this be a satisfactory solution? I don't want to add the breaking change of allowing the following, because we're currently adding http:// if a scheme is not provided:

pa11y /tmp/pa11y.html

@andrewholgate
Copy link
Author

Thanks, pa11y file:tmp/pa11y.html works on Linux (Ubuntu).

@andrewholgate
Copy link
Author

For anyone looking for a single command-line solution (so it can be used as a custom npm script) to load multiple HTML files into pa11y, this is what I have found to work (might need a slight tweek for Mac).

This command reads all of the *.html files from the directory output/ and performs the pa11y WCAG2A analysis on each one:

{
  "scripts": {
    "wcag": "for file in output/*.html; do pa11y --standard WCAG2A file:$file; done"
  }
}

Being an npm script, it can be execute with npm run wcag

@rowanmanning
Copy link
Member

Thanks @andrewholgate, I've added a ticket to create an example based on this so that it's easy to find :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants