This inspiration for this project came in a recent interview where I was asked to describe how I would implement a script for determining if an html/xml document was well-formed. In my response I suggested that a stack-based implementation would be great for testing whether tags were properly nested.
Using the parser if very easy.
- Require
parser.js
andstack.js
- Initialize a parser with the html 'parser = Parser.new("html_source_code")'
- Make a call to the parser's
wellFormed()
method. This will return true of false
An example is available at example/index.html
The parser currently breaks when tags have attributes that contain /
characters (such as the src
attribute on an image)
This library is built in coffeescript and then compiled to javascript. It is tested using the Jasmine library.
- Set up the
coffee
utility to watch thecoffeescripts
directory and compile into thejavascripts
directory. - Start the jasmine server by running
rake jasmine JASMINE_PORT=2222
- Start guard by running
guard
You can now edit the coffeescript files and the specs will automatically run in the terminal. Alternatively you can check the specs in the browser at localhost:2222