# Parse HTML

> Parse HTML files to an AST

Parses HTML output files to an abstract syntax tree.

---

- [Install](#install)
- [API](#api)
  - [ParseHtml](#parsehtml)
    - [See Also](#see-also)
    - [.sources](#sources)
    - [#getAttribute](#getattribute)
- [License](#license)

---

## Install

```
yarn add makestatic-parse-html
```

## API

### ParseHtml

Parses HTML files to abstract syntax trees.

#### See Also

* [Parse5](http://inikulin.github.io/parse5/ "Parse5")
* [Css Select](https://github.com/fb55/css-select "Css Select")

#### .sources

```javascript
ParseHtml.prototype.sources(file, context[, options])
```

Parse a file to an abstract syntax tree, the AST is assigned to
`file.ast.html`.

This implementation assigns a `seal` function to the file so that when
the file content is updated it will correspond to the current state of
the AST.

The generated AST is decorated with `querySelector` and `querySelectorAll`
functions so that you can query the AST for desired nodes.

It also adds an `adapter` getter that allows access to the static DOM
adapter function.

* `file` Object the current file.
* `context` Object the processing context.
* `options` Object options for `postcss`.

#### #getAttribute

```javascript
static getAttribute(el, name[, value])
```

Utility to get an attribute from a node.

Iterates the attribute list and gets the first attribute that has
the given name and optionally a specific value.

Note this is an extension to the interface required by `css-select`.

Returns the attribute or undefined.

* `el` Object the node.
* `name` String the attribute name.
* `value` String the attribute value.

## License

MIT

---

Created by [mkdoc](https://github.com/mkdoc/mkdoc) on March 12, 2017

[docs]: https://makestatic.ws/docs/ "Documentation"
[standalone manual]: https://github.com/makestatic/website/blob/master/MANUAL.md "Standalone Manual"
[yarn]: https://yarnpkg.com "Yarn"
[webpack]: https://webpack.js.org "Webpack"
[babel]: https://babeljs.io "Babel"
[postcss]: http://postcss.org "Postcss"
[sugarss]: https://github.com/postcss/sugarss "Sugarss"
[reshape]: https://github.com/reshape/reshape "Reshape Source Code"
[reshapeml]: https://reshape.ml "Reshape"
[clean-css]: https://github.com/jakubpawlowicz/clean-css "Clean CSS"
[html-minifier]: https://github.com/kangax/html-minifier "Html Minifier"
[uglify-js]: https://github.com/mishoo/UglifyJS2 "Uglify JS"
[imagemin]: https://github.com/imagemin/imagemin "Imagemin"
[mkdoc]: https://github.com/mkdoc/mkdoc "Mkdoc"
[browsersync]: https://www.browsersync.io "Browsersync"
[yeoman]: http://yeoman.io "Yeoman"
[spike]: https://www.spike.cf "Spike"
[validator]: https://github.com/validator/validator "HTML Validator"
[github pages]: https://pages.github.com "Github Pages"
[amazon s3]: https://aws.amazon.com/s3/ "Amazon S3"
[google sitemaps]: https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190 "Google Sitemaps"
[sitemaps]: https://www.sitemaps.org/ "Sitemaps"

