File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -102,13 +102,14 @@ function formatDOM(nodes, parentNode) {
102102 * @return {Object } - The DOM nodes.
103103 */
104104function htmlToDOMClient ( html ) {
105- var match = typeof html === 'string' ? html . match ( / < ( .+ ?) > / ) : null ;
105+ // from `<p>` or `<p style="">` get `p`
106+ var match = typeof html === 'string' ? html . match ( / < ( .+ ?) [ > \s ] / ) : null ;
106107 var tagName ;
107108 var parentNode ;
108109 var nodes ;
109110
110111 if ( match && typeof match [ 1 ] === 'string' ) {
111- tagName = match [ 1 ] . toLowerCase ( ) ;
112+ tagName = match [ 1 ] . trim ( ) . toLowerCase ( ) ;
112113 }
113114
114115 // `DOMParser` can parse full HTML
Original file line number Diff line number Diff line change @@ -55,9 +55,35 @@ describe('html-to-dom', function() {
5555 data . html . comment +
5656 data . html . script
5757 ) ;
58- helpers . deepEqualCircular ( htmlToDOMClient ( html ) , htmlToDOMServer ( html ) ) ;
58+
59+ helpers . deepEqualCircular (
60+ htmlToDOMClient ( html ) ,
61+ htmlToDOMServer ( html )
62+ ) ;
5963 } ) ;
6064
65+ it ( 'works with `window.DOMParser`' , function ( ) {
66+ var html = (
67+ data . html . attributes +
68+ data . html . nested +
69+ data . html . comment +
70+ data . html . script
71+ ) ;
72+
73+ // mock `window.DOMParser`
74+ // https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
75+ window . DOMParser = function ( ) {
76+ this . parseFromString = function ( html ) {
77+ jsdomify . create ( html ) ;
78+ return document ;
79+ } ;
80+ } ;
81+
82+ helpers . deepEqualCircular (
83+ htmlToDOMClient ( html ) ,
84+ htmlToDOMServer ( html )
85+ ) ;
86+ } ) ;
6187 } ) ;
6288
6389} ) ;
You can’t perform that action at this time.
0 commit comments