File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 *
55 * @see {@link https://github.com/substack/node-browserify#browser-field }
66 */
7- module . exports = require ( './lib/server/html-to-dom' ) ;
7+ var HTMLDOMParser = require ( './lib/server/html-to-dom' ) ;
8+
9+ module . exports = HTMLDOMParser ;
10+ module . exports . default = HTMLDOMParser ;
Original file line number Diff line number Diff line change 1+ import domparser from './domparser' ;
2+ import { formatDOM } from './utilities' ;
3+
4+ var DIRECTIVE_REGEX = / < ( ! [ a - z A - Z \s ] + ) > / ; // e.g., <!doctype html>
5+
6+ /**
7+ * Parses HTML string to DOM nodes in browser.
8+ *
9+ * @param {string } html - HTML markup.
10+ * @return {DomElement[] } - DOM elements.
11+ */
12+ function HTMLDOMParser ( html ) {
13+ if ( typeof html !== 'string' ) {
14+ throw new TypeError ( 'First argument must be a string' ) ;
15+ }
16+
17+ if ( html === '' ) {
18+ return [ ] ;
19+ }
20+
21+ // match directive
22+ var match = html . match ( DIRECTIVE_REGEX ) ;
23+ var directive ;
24+
25+ if ( match && match [ 1 ] ) {
26+ directive = match [ 1 ] ;
27+ }
28+
29+ return formatDOM ( domparser ( html ) , null , directive ) ;
30+ }
31+
32+ module . exports = HTMLDOMParser ;
33+ module . exports . default = HTMLDOMParser ;
Original file line number Diff line number Diff line change 8686 " /lib"
8787 ],
8888 "browser" : {
89- "./index.js" : " ./lib/client/html-to-dom.js"
89+ "./index.js" : " ./lib/client/html-to-dom.js" ,
90+ "./index.mjs" : " ./lib/client/html-to-dom.mjs"
9091 },
9192 "react-native" : {
9293 "./index.js" : " ./lib/server/html-to-dom.js"
You can’t perform that action at this time.
0 commit comments