1 | 'use strict';
|
2 |
|
3 | var node = ['tag', 'script', 'style'],
|
4 | singular = [
|
5 | 'area', 'base', 'br', 'col', 'command', 'embed', 'hr',
|
6 | 'img', 'input', 'link', 'meta', 'param', 'source', 'wbr',
|
7 | 'track'
|
8 | ];
|
9 |
|
10 | function attributes(element) {
|
11 | var attr = element.attribs;
|
12 |
|
13 | if (!attr || typeof attr !== 'object') {
|
14 | return '';
|
15 | }
|
16 |
|
17 | return Object.keys(attr).reduce(function (result, key) {
|
18 | return result + ' ' + key + '="' + attr[key] + '"';
|
19 | }, '');
|
20 | }
|
21 |
|
22 | exports.tag = exports.script = exports.style = function tag(element) {
|
23 | return '<' + element.name + attributes(element) + '>';
|
24 | };
|
25 |
|
26 | exports.text = function text(element) {
|
27 | return element.data;
|
28 | };
|
29 |
|
30 | exports.comment = function comment(element) {
|
31 | return '<!--' + element.data + '-->';
|
32 | };
|
33 |
|
34 | exports.directive = function directive(element) {
|
35 | return '<' + element.data + '>';
|
36 | };
|
37 |
|
38 | exports.close = function close(element) {
|
39 | return ~node.indexOf(element.type) && !~singular.indexOf(element.name)
|
40 | ? '</' + element.name + '>'
|
41 | : '';
|
42 | };
|