File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * DOMParser HTML extension
3+ * 2012-09-04
4+ *
5+ * By Eli Grey, http://eligrey.com
6+ * Public domain.
7+ * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
8+ */
9+
10+ /*! @source https://gist.github.com/1129031 */
11+ /*global document, DOMParser*/
12+
13+ ( function ( DOMParser ) {
14+ "use strict" ;
15+
16+ var
17+ DOMParser_proto = DOMParser . prototype
18+ , real_parseFromString = DOMParser_proto . parseFromString
19+ ;
20+
21+ // Firefox/Opera/IE throw errors on unsupported types
22+ try {
23+ // WebKit returns null on unsupported types
24+ if ( ( new DOMParser ) . parseFromString ( "" , "text/html" ) ) {
25+ // text/html parsing is natively supported
26+ return ;
27+ }
28+ } catch ( ex ) { }
29+
30+ DOMParser_proto . parseFromString = function ( markup , type ) {
31+ if ( / ^ \s * t e x t \/ h t m l \s * (?: ; | $ ) / i. test ( type ) ) {
32+ var
33+ doc = document . implementation . createHTMLDocument ( "" )
34+ ;
35+ if ( markup . toLowerCase ( ) . indexOf ( '<!doctype' ) > - 1 ) {
36+ doc . documentElement . innerHTML = markup ;
37+ }
38+ else {
39+ doc . body . innerHTML = markup ;
40+ }
41+ return doc ;
42+ } else {
43+ return real_parseFromString . apply ( this , arguments ) ;
44+ }
45+ } ;
46+ } ( DOMParser ) ) ;
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ module.exports = function(config) {
127127 testCore = true ;
128128 }
129129
130+ files . push ( corePath + 'tests/html-domparser.js' ) ;
130131 files . push ( 'core/js/dist/main.js' ) ;
131132 // core mocks
132133 files . push ( corePath + 'tests/specHelper.js' ) ;
You can’t perform that action at this time.
0 commit comments