forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLParser.js
More file actions
9183 lines (8730 loc) · 257 KB
/
HTMLParser.js
File metadata and controls
9183 lines (8730 loc) · 257 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'use strict';
module.exports = HTMLParser;
var Document = require('./Document');
var DocumentType = require('./DocumentType');
var Node = require('./Node');
var NAMESPACE = require('./utils').NAMESPACE;
var html = require('./htmlelts');
var impl = html.elements;
var pushAll = Function.prototype.apply.bind(Array.prototype.push);
/*
* This file contains an implementation of the HTML parsing algorithm.
* The algorithm and the implementation are complex because HTML
* explicitly defines how the parser should behave for all possible
* valid and invalid inputs.
*
* Usage:
*
* The file defines a single HTMLParser() function, which dom.js exposes
* publicly as document.implementation.mozHTMLParser(). This is a
* factory function, not a constructor.
*
* When you call document.implementation.mozHTMLParser(), it returns
* an object that has parse() and document() methods. To parse HTML text,
* pass the text (in one or more chunks) to the parse() method. When
* you've passed all the text (on the last chunk, or afterward) pass
* true as the second argument to parse() to tell the parser that there
* is no more coming. Call document() to get the document object that
* the parser is parsing into. You can call this at any time, before
* or after calling parse().
*
* The first argument to mozHTMLParser is the absolute URL of the document.
*
* The second argument is optional and is for internal use only. Pass an
* element as the fragmentContext to do innerHTML parsing for the
* element. To do innerHTML parsing on a document, pass null. Otherwise,
* omit the 2nd argument. See HTMLElement.innerHTML for an example. Note
* that if you pass a context element, the end() method will return an
* unwrapped document instead of a wrapped one.
*
* Implementation details:
*
* This is a long file of almost 7000 lines. It is structured as one
* big function nested within another big function. The outer
* function defines a bunch of constant data, utility functions
* that use that data, and a couple of classes used by the parser.
* The outer function also defines and returns the
* inner function. This inner function is the HTMLParser factory
* function that implements the parser and holds all the parser state
* as local variables. The HTMLParser function is quite big because
* it defines many nested functions that use those local variables.
*
* There are three tightly coupled parser stages: a scanner, a
* tokenizer and a tree builder. In a (possibly misguided) attempt at
* efficiency, the stages are not implemented as separate classes:
* everything shares state and is (mostly) implemented in imperative
* (rather than OO) style.
*
* The stages of the parser work like this: When the client code calls
* the parser's parse() method, the specified string is passed to
* scanChars(). The scanner loops through that string and passes characters
* (sometimes one at a time, sometimes in chunks) to the tokenizer stage.
* The tokenizer groups the characters into tokens: tags, endtags, runs
* of text, comments, doctype declarations, and the end-of-file (EOF)
* token. These tokens are then passed to the tree building stage via
* the insertToken() function. The tree building stage builds up the
* document tree.
*
* The tokenizer stage is a finite state machine. Each state is
* implemented as a function with a name that ends in "_state". The
* initial state is data_state(). The current tokenizer state is stored
* in the variable 'tokenizer'. Most state functions expect a single
* integer argument which represents a single UTF-16 codepoint. Some
* states want more characters and set a lookahead property on
* themselves. The scanChars() function in the scanner checks for this
* lookahead property. If it doesn't exist, then scanChars() just passes
* the next input character to the current tokenizer state function.
* Otherwise, scanChars() looks ahead (a given # of characters, or for a
* matching string, or for a matching regexp) and passes a string of
* characters to the current tokenizer state function.
*
* As a shortcut, certain states of the tokenizer use regular expressions
* to look ahead in the scanner's input buffer for runs of text, simple
* tags and attributes. For well-formed input, these shortcuts skip a
* lot of state transitions and speed things up a bit.
*
* When a tokenizer state function has consumed a complete token, it
* emits that token, by calling insertToken(), or by calling a utility
* function that itself calls insertToken(). These tokens are passed to
* the tree building stage, which is also a state machine. Like the
* tokenizer, the tree building states are implemented as functions, and
* these functions have names that end with _mode (because the HTML spec
* refers to them as insertion modes). The current insertion mode is held
* by the 'parser' variable. Each insertion mode function takes up to 4
* arguments. The first is a token type, represented by the constants
* TAG, ENDTAG, TEXT, COMMENT, DOCTYPE and EOF. The second argument is
* the value of the token: the text or comment data, or tagname or
* doctype. For tags, the 3rd argument is an array of attributes. For
* DOCTYPES it is the optional public id. For tags, the 4th argument is
* true if the tag is self-closing. For doctypes, the 4th argument is the
* optional system id.
*
* Search for "***" to find the major sub-divisions in the code.
*/
/***
* Data prolog. Lots of constants declared here, including some
* very large objects. They're used throughout the code that follows
*/
// Token types for the tree builder.
var EOF = -1;
var TEXT = 1;
var TAG = 2;
var ENDTAG = 3;
var COMMENT = 4;
var DOCTYPE = 5;
// A re-usable empty array
var NOATTRS = [];
// These DTD public ids put the browser in quirks mode
var quirkyPublicIds =
/^HTML$|^-\/\/W3O\/\/DTD W3 HTML Strict 3\.0\/\/EN\/\/$|^-\/W3C\/DTD HTML 4\.0 Transitional\/EN$|^\+\/\/Silmaril\/\/dtd html Pro v0r11 19970101\/\/|^-\/\/AdvaSoft Ltd\/\/DTD HTML 3\.0 asWedit \+ extensions\/\/|^-\/\/AS\/\/DTD HTML 3\.0 asWedit \+ extensions\/\/|^-\/\/IETF\/\/DTD HTML 2\.0 Level 1\/\/|^-\/\/IETF\/\/DTD HTML 2\.0 Level 2\/\/|^-\/\/IETF\/\/DTD HTML 2\.0 Strict Level 1\/\/|^-\/\/IETF\/\/DTD HTML 2\.0 Strict Level 2\/\/|^-\/\/IETF\/\/DTD HTML 2\.0 Strict\/\/|^-\/\/IETF\/\/DTD HTML 2\.0\/\/|^-\/\/IETF\/\/DTD HTML 2\.1E\/\/|^-\/\/IETF\/\/DTD HTML 3\.0\/\/|^-\/\/IETF\/\/DTD HTML 3\.2 Final\/\/|^-\/\/IETF\/\/DTD HTML 3\.2\/\/|^-\/\/IETF\/\/DTD HTML 3\/\/|^-\/\/IETF\/\/DTD HTML Level 0\/\/|^-\/\/IETF\/\/DTD HTML Level 1\/\/|^-\/\/IETF\/\/DTD HTML Level 2\/\/|^-\/\/IETF\/\/DTD HTML Level 3\/\/|^-\/\/IETF\/\/DTD HTML Strict Level 0\/\/|^-\/\/IETF\/\/DTD HTML Strict Level 1\/\/|^-\/\/IETF\/\/DTD HTML Strict Level 2\/\/|^-\/\/IETF\/\/DTD HTML Strict Level 3\/\/|^-\/\/IETF\/\/DTD HTML Strict\/\/|^-\/\/IETF\/\/DTD HTML\/\/|^-\/\/Metrius\/\/DTD Metrius Presentational\/\/|^-\/\/Microsoft\/\/DTD Internet Explorer 2\.0 HTML Strict\/\/|^-\/\/Microsoft\/\/DTD Internet Explorer 2\.0 HTML\/\/|^-\/\/Microsoft\/\/DTD Internet Explorer 2\.0 Tables\/\/|^-\/\/Microsoft\/\/DTD Internet Explorer 3\.0 HTML Strict\/\/|^-\/\/Microsoft\/\/DTD Internet Explorer 3\.0 HTML\/\/|^-\/\/Microsoft\/\/DTD Internet Explorer 3\.0 Tables\/\/|^-\/\/Netscape Comm\. Corp\.\/\/DTD HTML\/\/|^-\/\/Netscape Comm\. Corp\.\/\/DTD Strict HTML\/\/|^-\/\/O'Reilly and Associates\/\/DTD HTML 2\.0\/\/|^-\/\/O'Reilly and Associates\/\/DTD HTML Extended 1\.0\/\/|^-\/\/O'Reilly and Associates\/\/DTD HTML Extended Relaxed 1\.0\/\/|^-\/\/SoftQuad Software\/\/DTD HoTMetaL PRO 6\.0::19990601::extensions to HTML 4\.0\/\/|^-\/\/SoftQuad\/\/DTD HoTMetaL PRO 4\.0::19971010::extensions to HTML 4\.0\/\/|^-\/\/Spyglass\/\/DTD HTML 2\.0 Extended\/\/|^-\/\/SQ\/\/DTD HTML 2\.0 HoTMetaL \+ extensions\/\/|^-\/\/Sun Microsystems Corp\.\/\/DTD HotJava HTML\/\/|^-\/\/Sun Microsystems Corp\.\/\/DTD HotJava Strict HTML\/\/|^-\/\/W3C\/\/DTD HTML 3 1995-03-24\/\/|^-\/\/W3C\/\/DTD HTML 3\.2 Draft\/\/|^-\/\/W3C\/\/DTD HTML 3\.2 Final\/\/|^-\/\/W3C\/\/DTD HTML 3\.2\/\/|^-\/\/W3C\/\/DTD HTML 3\.2S Draft\/\/|^-\/\/W3C\/\/DTD HTML 4\.0 Frameset\/\/|^-\/\/W3C\/\/DTD HTML 4\.0 Transitional\/\/|^-\/\/W3C\/\/DTD HTML Experimental 19960712\/\/|^-\/\/W3C\/\/DTD HTML Experimental 970421\/\/|^-\/\/W3C\/\/DTD W3 HTML\/\/|^-\/\/W3O\/\/DTD W3 HTML 3\.0\/\/|^-\/\/WebTechs\/\/DTD Mozilla HTML 2\.0\/\/|^-\/\/WebTechs\/\/DTD Mozilla HTML\/\//i;
var quirkySystemId = 'http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd';
var conditionallyQuirkyPublicIds =
/^-\/\/W3C\/\/DTD HTML 4\.01 Frameset\/\/|^-\/\/W3C\/\/DTD HTML 4\.01 Transitional\/\//i;
// These DTD public ids put the browser in limited quirks mode
var limitedQuirkyPublicIds =
/^-\/\/W3C\/\/DTD XHTML 1\.0 Frameset\/\/|^-\/\/W3C\/\/DTD XHTML 1\.0 Transitional\/\//i;
// Element sets below. See the isA() function for a way to test
// whether an element is a member of a set
var specialSet = Object.create(null);
specialSet[NAMESPACE.HTML] = {
__proto__: null,
address: true,
applet: true,
area: true,
article: true,
aside: true,
base: true,
basefont: true,
bgsound: true,
blockquote: true,
body: true,
br: true,
button: true,
caption: true,
center: true,
col: true,
colgroup: true,
dd: true,
details: true,
dir: true,
div: true,
dl: true,
dt: true,
embed: true,
fieldset: true,
figcaption: true,
figure: true,
footer: true,
form: true,
frame: true,
frameset: true,
h1: true,
h2: true,
h3: true,
h4: true,
h5: true,
h6: true,
head: true,
header: true,
hgroup: true,
hr: true,
html: true,
iframe: true,
img: true,
input: true,
li: true,
link: true,
listing: true,
main: true,
marquee: true,
menu: true,
meta: true,
nav: true,
noembed: true,
noframes: true,
noscript: true,
object: true,
ol: true,
p: true,
param: true,
plaintext: true,
pre: true,
script: true,
section: true,
select: true,
source: true,
style: true,
summary: true,
table: true,
tbody: true,
td: true,
template: true,
textarea: true,
tfoot: true,
th: true,
thead: true,
title: true,
tr: true,
track: true,
// Note that "xmp" was removed from the "special" set in the latest
// spec, apparently by accident; see
// https://github.com/whatwg/html/pull/1919
ul: true,
wbr: true,
xmp: true,
};
specialSet[NAMESPACE.SVG] = {
__proto__: null,
foreignObject: true,
desc: true,
title: true,
};
specialSet[NAMESPACE.MATHML] = {
__proto__: null,
mi: true,
mo: true,
mn: true,
ms: true,
mtext: true,
'annotation-xml': true,
};
// The set of address, div, and p HTML tags
var addressdivpSet = Object.create(null);
addressdivpSet[NAMESPACE.HTML] = {
__proto__: null,
address: true,
div: true,
p: true,
};
var dddtSet = Object.create(null);
dddtSet[NAMESPACE.HTML] = {
__proto__: null,
dd: true,
dt: true,
};
var tablesectionrowSet = Object.create(null);
tablesectionrowSet[NAMESPACE.HTML] = {
__proto__: null,
table: true,
thead: true,
tbody: true,
tfoot: true,
tr: true,
};
var impliedEndTagsSet = Object.create(null);
impliedEndTagsSet[NAMESPACE.HTML] = {
__proto__: null,
dd: true,
dt: true,
li: true,
menuitem: true,
optgroup: true,
option: true,
p: true,
rb: true,
rp: true,
rt: true,
rtc: true,
};
var thoroughImpliedEndTagsSet = Object.create(null);
thoroughImpliedEndTagsSet[NAMESPACE.HTML] = {
__proto__: null,
caption: true,
colgroup: true,
dd: true,
dt: true,
li: true,
optgroup: true,
option: true,
p: true,
rb: true,
rp: true,
rt: true,
rtc: true,
tbody: true,
td: true,
tfoot: true,
th: true,
thead: true,
tr: true,
};
var tableContextSet = Object.create(null);
tableContextSet[NAMESPACE.HTML] = {
__proto__: null,
table: true,
template: true,
html: true,
};
var tableBodyContextSet = Object.create(null);
tableBodyContextSet[NAMESPACE.HTML] = {
__proto__: null,
tbody: true,
tfoot: true,
thead: true,
template: true,
html: true,
};
var tableRowContextSet = Object.create(null);
tableRowContextSet[NAMESPACE.HTML] = {
__proto__: null,
tr: true,
template: true,
html: true,
};
// See http://www.w3.org/TR/html5/forms.html#form-associated-element
var formassociatedSet = Object.create(null);
formassociatedSet[NAMESPACE.HTML] = {
__proto__: null,
button: true,
fieldset: true,
input: true,
keygen: true,
object: true,
output: true,
select: true,
textarea: true,
img: true,
};
var inScopeSet = Object.create(null);
inScopeSet[NAMESPACE.HTML] = {
__proto__: null,
applet: true,
caption: true,
html: true,
table: true,
td: true,
th: true,
marquee: true,
object: true,
template: true,
};
inScopeSet[NAMESPACE.MATHML] = {
__proto__: null,
mi: true,
mo: true,
mn: true,
ms: true,
mtext: true,
'annotation-xml': true,
};
inScopeSet[NAMESPACE.SVG] = {
__proto__: null,
foreignObject: true,
desc: true,
title: true,
};
var inListItemScopeSet = Object.create(inScopeSet);
inListItemScopeSet[NAMESPACE.HTML] = Object.create(inScopeSet[NAMESPACE.HTML]);
inListItemScopeSet[NAMESPACE.HTML].ol = true;
inListItemScopeSet[NAMESPACE.HTML].ul = true;
var inButtonScopeSet = Object.create(inScopeSet);
inButtonScopeSet[NAMESPACE.HTML] = Object.create(inScopeSet[NAMESPACE.HTML]);
inButtonScopeSet[NAMESPACE.HTML].button = true;
var inTableScopeSet = Object.create(null);
inTableScopeSet[NAMESPACE.HTML] = {
__proto__: null,
html: true,
table: true,
template: true,
};
// The set of elements for select scope is the everything *except* these
var invertedSelectScopeSet = Object.create(null);
invertedSelectScopeSet[NAMESPACE.HTML] = {
__proto__: null,
optgroup: true,
option: true,
};
var mathmlTextIntegrationPointSet = Object.create(null);
mathmlTextIntegrationPointSet[NAMESPACE.MATHML] = {
__proto__: null,
mi: true,
mo: true,
mn: true,
ms: true,
mtext: true,
};
var htmlIntegrationPointSet = Object.create(null);
htmlIntegrationPointSet[NAMESPACE.SVG] = {
__proto__: null,
foreignObject: true,
desc: true,
title: true,
};
var foreignAttributes = {
__proto__: null,
'xlink:actuate': NAMESPACE.XLINK,
'xlink:arcrole': NAMESPACE.XLINK,
'xlink:href': NAMESPACE.XLINK,
'xlink:role': NAMESPACE.XLINK,
'xlink:show': NAMESPACE.XLINK,
'xlink:title': NAMESPACE.XLINK,
'xlink:type': NAMESPACE.XLINK,
'xml:base': NAMESPACE.XML,
'xml:lang': NAMESPACE.XML,
'xml:space': NAMESPACE.XML,
xmlns: NAMESPACE.XMLNS,
'xmlns:xlink': NAMESPACE.XMLNS,
};
// Lowercase to mixed case mapping for SVG attributes and tagnames
var svgAttrAdjustments = {
__proto__: null,
attributename: 'attributeName',
attributetype: 'attributeType',
basefrequency: 'baseFrequency',
baseprofile: 'baseProfile',
calcmode: 'calcMode',
clippathunits: 'clipPathUnits',
diffuseconstant: 'diffuseConstant',
edgemode: 'edgeMode',
filterunits: 'filterUnits',
glyphref: 'glyphRef',
gradienttransform: 'gradientTransform',
gradientunits: 'gradientUnits',
kernelmatrix: 'kernelMatrix',
kernelunitlength: 'kernelUnitLength',
keypoints: 'keyPoints',
keysplines: 'keySplines',
keytimes: 'keyTimes',
lengthadjust: 'lengthAdjust',
limitingconeangle: 'limitingConeAngle',
markerheight: 'markerHeight',
markerunits: 'markerUnits',
markerwidth: 'markerWidth',
maskcontentunits: 'maskContentUnits',
maskunits: 'maskUnits',
numoctaves: 'numOctaves',
pathlength: 'pathLength',
patterncontentunits: 'patternContentUnits',
patterntransform: 'patternTransform',
patternunits: 'patternUnits',
pointsatx: 'pointsAtX',
pointsaty: 'pointsAtY',
pointsatz: 'pointsAtZ',
preservealpha: 'preserveAlpha',
preserveaspectratio: 'preserveAspectRatio',
primitiveunits: 'primitiveUnits',
refx: 'refX',
refy: 'refY',
repeatcount: 'repeatCount',
repeatdur: 'repeatDur',
requiredextensions: 'requiredExtensions',
requiredfeatures: 'requiredFeatures',
specularconstant: 'specularConstant',
specularexponent: 'specularExponent',
spreadmethod: 'spreadMethod',
startoffset: 'startOffset',
stddeviation: 'stdDeviation',
stitchtiles: 'stitchTiles',
surfacescale: 'surfaceScale',
systemlanguage: 'systemLanguage',
tablevalues: 'tableValues',
targetx: 'targetX',
targety: 'targetY',
textlength: 'textLength',
viewbox: 'viewBox',
viewtarget: 'viewTarget',
xchannelselector: 'xChannelSelector',
ychannelselector: 'yChannelSelector',
zoomandpan: 'zoomAndPan',
};
var svgTagNameAdjustments = {
__proto__: null,
altglyph: 'altGlyph',
altglyphdef: 'altGlyphDef',
altglyphitem: 'altGlyphItem',
animatecolor: 'animateColor',
animatemotion: 'animateMotion',
animatetransform: 'animateTransform',
clippath: 'clipPath',
feblend: 'feBlend',
fecolormatrix: 'feColorMatrix',
fecomponenttransfer: 'feComponentTransfer',
fecomposite: 'feComposite',
feconvolvematrix: 'feConvolveMatrix',
fediffuselighting: 'feDiffuseLighting',
fedisplacementmap: 'feDisplacementMap',
fedistantlight: 'feDistantLight',
feflood: 'feFlood',
fefunca: 'feFuncA',
fefuncb: 'feFuncB',
fefuncg: 'feFuncG',
fefuncr: 'feFuncR',
fegaussianblur: 'feGaussianBlur',
feimage: 'feImage',
femerge: 'feMerge',
femergenode: 'feMergeNode',
femorphology: 'feMorphology',
feoffset: 'feOffset',
fepointlight: 'fePointLight',
fespecularlighting: 'feSpecularLighting',
fespotlight: 'feSpotLight',
fetile: 'feTile',
feturbulence: 'feTurbulence',
foreignobject: 'foreignObject',
glyphref: 'glyphRef',
lineargradient: 'linearGradient',
radialgradient: 'radialGradient',
textpath: 'textPath',
};
// Data for parsing numeric and named character references
// These next 3 objects are direct translations of tables
// in the HTML spec into JavaScript object format
var numericCharRefReplacements = {
__proto__: null,
0x00: 0xfffd,
0x80: 0x20ac,
0x82: 0x201a,
0x83: 0x0192,
0x84: 0x201e,
0x85: 0x2026,
0x86: 0x2020,
0x87: 0x2021,
0x88: 0x02c6,
0x89: 0x2030,
0x8a: 0x0160,
0x8b: 0x2039,
0x8c: 0x0152,
0x8e: 0x017d,
0x91: 0x2018,
0x92: 0x2019,
0x93: 0x201c,
0x94: 0x201d,
0x95: 0x2022,
0x96: 0x2013,
0x97: 0x2014,
0x98: 0x02dc,
0x99: 0x2122,
0x9a: 0x0161,
0x9b: 0x203a,
0x9c: 0x0153,
0x9e: 0x017e,
0x9f: 0x0178,
};
/*
* This table is generated with test/tools/update-entities.js
*/
var namedCharRefs = {
__proto__: null,
AElig: 0xc6,
'AElig;': 0xc6,
AMP: 0x26,
'AMP;': 0x26,
Aacute: 0xc1,
'Aacute;': 0xc1,
'Abreve;': 0x102,
Acirc: 0xc2,
'Acirc;': 0xc2,
'Acy;': 0x410,
'Afr;': [0xd835, 0xdd04],
Agrave: 0xc0,
'Agrave;': 0xc0,
'Alpha;': 0x391,
'Amacr;': 0x100,
'And;': 0x2a53,
'Aogon;': 0x104,
'Aopf;': [0xd835, 0xdd38],
'ApplyFunction;': 0x2061,
Aring: 0xc5,
'Aring;': 0xc5,
'Ascr;': [0xd835, 0xdc9c],
'Assign;': 0x2254,
Atilde: 0xc3,
'Atilde;': 0xc3,
Auml: 0xc4,
'Auml;': 0xc4,
'Backslash;': 0x2216,
'Barv;': 0x2ae7,
'Barwed;': 0x2306,
'Bcy;': 0x411,
'Because;': 0x2235,
'Bernoullis;': 0x212c,
'Beta;': 0x392,
'Bfr;': [0xd835, 0xdd05],
'Bopf;': [0xd835, 0xdd39],
'Breve;': 0x2d8,
'Bscr;': 0x212c,
'Bumpeq;': 0x224e,
'CHcy;': 0x427,
COPY: 0xa9,
'COPY;': 0xa9,
'Cacute;': 0x106,
'Cap;': 0x22d2,
'CapitalDifferentialD;': 0x2145,
'Cayleys;': 0x212d,
'Ccaron;': 0x10c,
Ccedil: 0xc7,
'Ccedil;': 0xc7,
'Ccirc;': 0x108,
'Cconint;': 0x2230,
'Cdot;': 0x10a,
'Cedilla;': 0xb8,
'CenterDot;': 0xb7,
'Cfr;': 0x212d,
'Chi;': 0x3a7,
'CircleDot;': 0x2299,
'CircleMinus;': 0x2296,
'CirclePlus;': 0x2295,
'CircleTimes;': 0x2297,
'ClockwiseContourIntegral;': 0x2232,
'CloseCurlyDoubleQuote;': 0x201d,
'CloseCurlyQuote;': 0x2019,
'Colon;': 0x2237,
'Colone;': 0x2a74,
'Congruent;': 0x2261,
'Conint;': 0x222f,
'ContourIntegral;': 0x222e,
'Copf;': 0x2102,
'Coproduct;': 0x2210,
'CounterClockwiseContourIntegral;': 0x2233,
'Cross;': 0x2a2f,
'Cscr;': [0xd835, 0xdc9e],
'Cup;': 0x22d3,
'CupCap;': 0x224d,
'DD;': 0x2145,
'DDotrahd;': 0x2911,
'DJcy;': 0x402,
'DScy;': 0x405,
'DZcy;': 0x40f,
'Dagger;': 0x2021,
'Darr;': 0x21a1,
'Dashv;': 0x2ae4,
'Dcaron;': 0x10e,
'Dcy;': 0x414,
'Del;': 0x2207,
'Delta;': 0x394,
'Dfr;': [0xd835, 0xdd07],
'DiacriticalAcute;': 0xb4,
'DiacriticalDot;': 0x2d9,
'DiacriticalDoubleAcute;': 0x2dd,
'DiacriticalGrave;': 0x60,
'DiacriticalTilde;': 0x2dc,
'Diamond;': 0x22c4,
'DifferentialD;': 0x2146,
'Dopf;': [0xd835, 0xdd3b],
'Dot;': 0xa8,
'DotDot;': 0x20dc,
'DotEqual;': 0x2250,
'DoubleContourIntegral;': 0x222f,
'DoubleDot;': 0xa8,
'DoubleDownArrow;': 0x21d3,
'DoubleLeftArrow;': 0x21d0,
'DoubleLeftRightArrow;': 0x21d4,
'DoubleLeftTee;': 0x2ae4,
'DoubleLongLeftArrow;': 0x27f8,
'DoubleLongLeftRightArrow;': 0x27fa,
'DoubleLongRightArrow;': 0x27f9,
'DoubleRightArrow;': 0x21d2,
'DoubleRightTee;': 0x22a8,
'DoubleUpArrow;': 0x21d1,
'DoubleUpDownArrow;': 0x21d5,
'DoubleVerticalBar;': 0x2225,
'DownArrow;': 0x2193,
'DownArrowBar;': 0x2913,
'DownArrowUpArrow;': 0x21f5,
'DownBreve;': 0x311,
'DownLeftRightVector;': 0x2950,
'DownLeftTeeVector;': 0x295e,
'DownLeftVector;': 0x21bd,
'DownLeftVectorBar;': 0x2956,
'DownRightTeeVector;': 0x295f,
'DownRightVector;': 0x21c1,
'DownRightVectorBar;': 0x2957,
'DownTee;': 0x22a4,
'DownTeeArrow;': 0x21a7,
'Downarrow;': 0x21d3,
'Dscr;': [0xd835, 0xdc9f],
'Dstrok;': 0x110,
'ENG;': 0x14a,
ETH: 0xd0,
'ETH;': 0xd0,
Eacute: 0xc9,
'Eacute;': 0xc9,
'Ecaron;': 0x11a,
Ecirc: 0xca,
'Ecirc;': 0xca,
'Ecy;': 0x42d,
'Edot;': 0x116,
'Efr;': [0xd835, 0xdd08],
Egrave: 0xc8,
'Egrave;': 0xc8,
'Element;': 0x2208,
'Emacr;': 0x112,
'EmptySmallSquare;': 0x25fb,
'EmptyVerySmallSquare;': 0x25ab,
'Eogon;': 0x118,
'Eopf;': [0xd835, 0xdd3c],
'Epsilon;': 0x395,
'Equal;': 0x2a75,
'EqualTilde;': 0x2242,
'Equilibrium;': 0x21cc,
'Escr;': 0x2130,
'Esim;': 0x2a73,
'Eta;': 0x397,
Euml: 0xcb,
'Euml;': 0xcb,
'Exists;': 0x2203,
'ExponentialE;': 0x2147,
'Fcy;': 0x424,
'Ffr;': [0xd835, 0xdd09],
'FilledSmallSquare;': 0x25fc,
'FilledVerySmallSquare;': 0x25aa,
'Fopf;': [0xd835, 0xdd3d],
'ForAll;': 0x2200,
'Fouriertrf;': 0x2131,
'Fscr;': 0x2131,
'GJcy;': 0x403,
GT: 0x3e,
'GT;': 0x3e,
'Gamma;': 0x393,
'Gammad;': 0x3dc,
'Gbreve;': 0x11e,
'Gcedil;': 0x122,
'Gcirc;': 0x11c,
'Gcy;': 0x413,
'Gdot;': 0x120,
'Gfr;': [0xd835, 0xdd0a],
'Gg;': 0x22d9,
'Gopf;': [0xd835, 0xdd3e],
'GreaterEqual;': 0x2265,
'GreaterEqualLess;': 0x22db,
'GreaterFullEqual;': 0x2267,
'GreaterGreater;': 0x2aa2,
'GreaterLess;': 0x2277,
'GreaterSlantEqual;': 0x2a7e,
'GreaterTilde;': 0x2273,
'Gscr;': [0xd835, 0xdca2],
'Gt;': 0x226b,
'HARDcy;': 0x42a,
'Hacek;': 0x2c7,
'Hat;': 0x5e,
'Hcirc;': 0x124,
'Hfr;': 0x210c,
'HilbertSpace;': 0x210b,
'Hopf;': 0x210d,
'HorizontalLine;': 0x2500,
'Hscr;': 0x210b,
'Hstrok;': 0x126,
'HumpDownHump;': 0x224e,
'HumpEqual;': 0x224f,
'IEcy;': 0x415,
'IJlig;': 0x132,
'IOcy;': 0x401,
Iacute: 0xcd,
'Iacute;': 0xcd,
Icirc: 0xce,
'Icirc;': 0xce,
'Icy;': 0x418,
'Idot;': 0x130,
'Ifr;': 0x2111,
Igrave: 0xcc,
'Igrave;': 0xcc,
'Im;': 0x2111,
'Imacr;': 0x12a,
'ImaginaryI;': 0x2148,
'Implies;': 0x21d2,
'Int;': 0x222c,
'Integral;': 0x222b,
'Intersection;': 0x22c2,
'InvisibleComma;': 0x2063,
'InvisibleTimes;': 0x2062,
'Iogon;': 0x12e,
'Iopf;': [0xd835, 0xdd40],
'Iota;': 0x399,
'Iscr;': 0x2110,
'Itilde;': 0x128,
'Iukcy;': 0x406,
Iuml: 0xcf,
'Iuml;': 0xcf,
'Jcirc;': 0x134,
'Jcy;': 0x419,
'Jfr;': [0xd835, 0xdd0d],
'Jopf;': [0xd835, 0xdd41],
'Jscr;': [0xd835, 0xdca5],
'Jsercy;': 0x408,
'Jukcy;': 0x404,
'KHcy;': 0x425,
'KJcy;': 0x40c,
'Kappa;': 0x39a,
'Kcedil;': 0x136,
'Kcy;': 0x41a,
'Kfr;': [0xd835, 0xdd0e],
'Kopf;': [0xd835, 0xdd42],
'Kscr;': [0xd835, 0xdca6],
'LJcy;': 0x409,
LT: 0x3c,
'LT;': 0x3c,
'Lacute;': 0x139,
'Lambda;': 0x39b,
'Lang;': 0x27ea,
'Laplacetrf;': 0x2112,
'Larr;': 0x219e,
'Lcaron;': 0x13d,
'Lcedil;': 0x13b,
'Lcy;': 0x41b,
'LeftAngleBracket;': 0x27e8,
'LeftArrow;': 0x2190,
'LeftArrowBar;': 0x21e4,
'LeftArrowRightArrow;': 0x21c6,
'LeftCeiling;': 0x2308,
'LeftDoubleBracket;': 0x27e6,
'LeftDownTeeVector;': 0x2961,
'LeftDownVector;': 0x21c3,
'LeftDownVectorBar;': 0x2959,
'LeftFloor;': 0x230a,
'LeftRightArrow;': 0x2194,
'LeftRightVector;': 0x294e,
'LeftTee;': 0x22a3,
'LeftTeeArrow;': 0x21a4,
'LeftTeeVector;': 0x295a,
'LeftTriangle;': 0x22b2,
'LeftTriangleBar;': 0x29cf,
'LeftTriangleEqual;': 0x22b4,
'LeftUpDownVector;': 0x2951,
'LeftUpTeeVector;': 0x2960,
'LeftUpVector;': 0x21bf,
'LeftUpVectorBar;': 0x2958,
'LeftVector;': 0x21bc,
'LeftVectorBar;': 0x2952,
'Leftarrow;': 0x21d0,
'Leftrightarrow;': 0x21d4,
'LessEqualGreater;': 0x22da,
'LessFullEqual;': 0x2266,
'LessGreater;': 0x2276,
'LessLess;': 0x2aa1,
'LessSlantEqual;': 0x2a7d,
'LessTilde;': 0x2272,
'Lfr;': [0xd835, 0xdd0f],
'Ll;': 0x22d8,
'Lleftarrow;': 0x21da,
'Lmidot;': 0x13f,
'LongLeftArrow;': 0x27f5,
'LongLeftRightArrow;': 0x27f7,
'LongRightArrow;': 0x27f6,
'Longleftarrow;': 0x27f8,
'Longleftrightarrow;': 0x27fa,
'Longrightarrow;': 0x27f9,
'Lopf;': [0xd835, 0xdd43],
'LowerLeftArrow;': 0x2199,
'LowerRightArrow;': 0x2198,
'Lscr;': 0x2112,
'Lsh;': 0x21b0,
'Lstrok;': 0x141,
'Lt;': 0x226a,
'Map;': 0x2905,
'Mcy;': 0x41c,
'MediumSpace;': 0x205f,
'Mellintrf;': 0x2133,
'Mfr;': [0xd835, 0xdd10],
'MinusPlus;': 0x2213,
'Mopf;': [0xd835, 0xdd44],
'Mscr;': 0x2133,
'Mu;': 0x39c,
'NJcy;': 0x40a,
'Nacute;': 0x143,
'Ncaron;': 0x147,
'Ncedil;': 0x145,
'Ncy;': 0x41d,
'NegativeMediumSpace;': 0x200b,
'NegativeThickSpace;': 0x200b,
'NegativeThinSpace;': 0x200b,
'NegativeVeryThinSpace;': 0x200b,
'NestedGreaterGreater;': 0x226b,
'NestedLessLess;': 0x226a,
'NewLine;': 0xa,
'Nfr;': [0xd835, 0xdd11],
'NoBreak;': 0x2060,
'NonBreakingSpace;': 0xa0,
'Nopf;': 0x2115,
'Not;': 0x2aec,
'NotCongruent;': 0x2262,
'NotCupCap;': 0x226d,
'NotDoubleVerticalBar;': 0x2226,
'NotElement;': 0x2209,
'NotEqual;': 0x2260,
'NotEqualTilde;': [0x2242, 0x338],
'NotExists;': 0x2204,
'NotGreater;': 0x226f,
'NotGreaterEqual;': 0x2271,
'NotGreaterFullEqual;': [0x2267, 0x338],
'NotGreaterGreater;': [0x226b, 0x338],
'NotGreaterLess;': 0x2279,
'NotGreaterSlantEqual;': [0x2a7e, 0x338],
'NotGreaterTilde;': 0x2275,
'NotHumpDownHump;': [0x224e, 0x338],
'NotHumpEqual;': [0x224f, 0x338],
'NotLeftTriangle;': 0x22ea,
'NotLeftTriangleBar;': [0x29cf, 0x338],
'NotLeftTriangleEqual;': 0x22ec,
'NotLess;': 0x226e,
'NotLessEqual;': 0x2270,
'NotLessGreater;': 0x2278,
'NotLessLess;': [0x226a, 0x338],
'NotLessSlantEqual;': [0x2a7d, 0x338],
'NotLessTilde;': 0x2274,
'NotNestedGreaterGreater;': [0x2aa2, 0x338],
'NotNestedLessLess;': [0x2aa1, 0x338],
'NotPrecedes;': 0x2280,
'NotPrecedesEqual;': [0x2aaf, 0x338],
'NotPrecedesSlantEqual;': 0x22e0,
'NotReverseElement;': 0x220c,
'NotRightTriangle;': 0x22eb,
'NotRightTriangleBar;': [0x29d0, 0x338],
'NotRightTriangleEqual;': 0x22ed,
'NotSquareSubset;': [0x228f, 0x338],
'NotSquareSubsetEqual;': 0x22e2,
'NotSquareSuperset;': [0x2290, 0x338],
'NotSquareSupersetEqual;': 0x22e3,
'NotSubset;': [0x2282, 0x20d2],
'NotSubsetEqual;': 0x2288,
'NotSucceeds;': 0x2281,
'NotSucceedsEqual;': [0x2ab0, 0x338],
'NotSucceedsSlantEqual;': 0x22e1,
'NotSucceedsTilde;': [0x227f, 0x338],
'NotSuperset;': [0x2283, 0x20d2],
'NotSupersetEqual;': 0x2289,
'NotTilde;': 0x2241,
'NotTildeEqual;': 0x2244,
'NotTildeFullEqual;': 0x2247,
'NotTildeTilde;': 0x2249,
'NotVerticalBar;': 0x2224,
'Nscr;': [0xd835, 0xdca9],
Ntilde: 0xd1,
'Ntilde;': 0xd1,
'Nu;': 0x39d,
'OElig;': 0x152,
Oacute: 0xd3,
'Oacute;': 0xd3,
Ocirc: 0xd4,
'Ocirc;': 0xd4,
'Ocy;': 0x41e,
'Odblac;': 0x150,
'Ofr;': [0xd835, 0xdd12],
Ograve: 0xd2,
'Ograve;': 0xd2,
'Omacr;': 0x14c,
'Omega;': 0x3a9,
'Omicron;': 0x39f,
'Oopf;': [0xd835, 0xdd46],
'OpenCurlyDoubleQuote;': 0x201c,
'OpenCurlyQuote;': 0x2018,
'Or;': 0x2a54,
'Oscr;': [0xd835, 0xdcaa],
Oslash: 0xd8,
'Oslash;': 0xd8,
Otilde: 0xd5,
'Otilde;': 0xd5,
'Otimes;': 0x2a37,
Ouml: 0xd6,
'Ouml;': 0xd6,
'OverBar;': 0x203e,
'OverBrace;': 0x23de,
'OverBracket;': 0x23b4,
'OverParenthesis;': 0x23dc,
'PartialD;': 0x2202,
'Pcy;': 0x41f,
'Pfr;': [0xd835, 0xdd13],
'Phi;': 0x3a6,
'Pi;': 0x3a0,
'PlusMinus;': 0xb1,
'Poincareplane;': 0x210c,