Giter VIP home page Giter VIP logo

a11y-string's Introduction

Build Status

a11y String

This is a simple, fast module that allows you to run a range of accessibility tests against a string of HTML.

Installation

  npm install a11y-string

Example

const a11y = require('a11y-string')

a11y('<html><head><title>Test title</title></head><body><img src="foo.jpg" /></body></html>')
// Throws Error: All images must have an alt attribute

Reasoning

There are a lot of great a11y tools that exist today but all of them require an external URL or are framework specific. This project aims to be a lightweight alternative for people who need to run accessibility tests against just a string of HTML.

a11y-string's People

Contributors

jkup avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

a11y-string's Issues

What is the best approach for walking this DOM?

Currently we just take the string passed in and send it to htmlparser2. Right now we're using htmlparser's event system but that's just not going to look nice. Currently the code looks like:

  var parser = new htmlparser.Parser({
    onopentag: function(name, attributes){
      if (name === 'img' && attributes.alt === undefined)
        throw new Error('All images must have an alt attribute')

      tags.push({name: name, attributes: attributes})
    }
  }, {decodeEntities: true});

but we'll want a cleaner way to execute a bunch of a11y checks. Additionally we'll need some sort of tree because for things like form labels we'll need to walk form elements backwards to see if they have a label.

I think it's probably best to use https://github.com/fb55/domhandler. Anyone else have thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.