This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
html.js
74 lines (59 loc) · 1.95 KB
/
html.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module.exports = function( exports ) {
var tags = [
// open
"A ABBR ADDRESS ARTICLE ASIDE AUDIO B BB BDO BLOCKQUOTE BODY BUTTON\
CANVAS CAPTION CITE CODE COLGROUP DATAGRID DATALIST DD DEL DETAILS\
DFN DIALOG DIV DL DOCTYPE DT EM EVENTSOURCE FIELDSET FIGURE FOOTER\
FORM H1 H2 H3 H4 H5 H6 HEAD HEADER HTML I IFRAME INS KBD LABEL\
LEGEND LI MAP MARK MENU METER NAV NOSCRIPT OBJECT OL OPTGROUP\
OPTION OUTPUT P PRE PROGRESS Q RP RT RUBY SAMP SCRIPT SECTION\
SELECT SMALL SPAN STRONG STYLE SUB SUP TABLE TBODY TD TEXTAREA\
TFOOT TH THEAD TIME TITLE TR UL VAR VIDEO".split( " " ),
// closed
"AREA BASE BR COL COMMAND EMBED HR IMG INPUT KEYGEN LINK META PARAM\
SOURCE WBR".split( " " )
];
for ( var isVoid = 0, names; names = tags[ isVoid ]; isVoid++ ) {
for ( var i = 0, name; name = names[ i++ ]; ) {
elem[ name ] = elem( name.toLowerCase(), !!isVoid );
}
}
elem.DOCTYPE = function( write, dec ) {
return write( "<!DOCTYPE " )( dec )( ">\n" );
}
elem.COMMENT = function( write ) {
write = write( "<!-- " );
return function read( obj ) {
if ( !arguments.length ) return write( " -->" );
write = write( obj );
return read;
}
}
return exports( elem );
function elem( name, isVoid ) {
return function( write, obj ) {
write = write( "<" + name );
write = attrs( write )( obj )( ">" );
if ( isVoid ) return write;
return function read( arg ) {
if ( !arguments.length ) return write( "</" + name + ">" );
write = write.apply( undefined, arguments );
return read;
};
}
}
function attrs( write ) {
return function read( obj ) {
for ( var name in obj ) {
write = write( " " )( name )( "=" );
write = attr( write )( obj[ name ] );
}
return write;
}
}
function attr( write ) {
return function read( value ) {
return write( "\"" )( value )( "\"" );
}
}
};