html-document
Version:
Partial implementation of document, HTMLElement for node
66 lines (46 loc) • 2.34 kB
Markdown
html-document [![NPM version][npm-image]][npm-url] [![Build Status][build-status-image]][build-status-url] [![Code Climate][code-climate-image]][code-climate-url] [![Coverage][coverage-image]][coverage-url]
============================
Partial implementation of the DOM, document for node.
```js
import Document from 'html-document'; // or var Document = require('html-document');
const document = new Document();
let textNode = document.createTextNode('Hello');
let h1 = document.createElement('h1');
h1.setAttribute('id', 'title');
h1.appendChild(textNode);
expect(h1.outerHTML, '<h1 id="title">Hello</h1>');
```
The partial implementation allows you to build html like you would in the browser, with the DOM API.
This library will never implement all specifications of the W3C.
See the generated API [here](http://christophehurpeau.github.io/html-document/docs/).
Inject `window`, `document`, `Document`, `DocumentFragment`, `Node` and `Event` [in the global scope](src/global.js).
```js
import 'html-document/lib/global'; // or var Document = require('html-document/lib/global');
let textNode = document.createTextNode('Hello');
expect(textNode.textContent, 'Hello');
```
Create an HTML layout
```js
let document = new Document();
let fragment = document.createDocumentFragment();
fragment.appendChild(new Doctype());
let html = document.createElement('html');
fragment.appendChild(html);
let head = document.createElement('head');
html.appendChild(head);
let body = document.createElement('body');
html.appendChild(body);
expect(fragment.innerHTML, '<!DOCTYPE html><html><head></head><body></body></html>');
```
[]: https://circleci.com/gh/christophehurpeau/html-document.svg?style=svg
[]: https://circleci.com/gh/christophehurpeau/html-document
[]: https://img.shields.io/npm/v/html-document.svg?style=flat
[]: https://npmjs.org/package/html-document
[]: https://codeclimate.com/github/christophehurpeau/html-document/badges/coverage.svg
[]: http://christophehurpeau.github.io/html-document/coverage/lcov-report/
[]: https://codeclimate.com/github/christophehurpeau/html-document/badges/gpa.svg
[]: https://codeclimate.com/github/christophehurpeau/html-document