Skip to content

Commit 23194b7

Browse files
committed
use DOMParser instead of JSDOM
1 parent 988e7e0 commit 23194b7

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/dist
1+
/dist

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1212
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
1313
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1414
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
15-
THIS SOFTWARE.
15+
THIS SOFTWARE.

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Transform a DOM tree to HAST",
55
"main": "dist/hast-util-from-dom.js",
66
"module": "dist/hast-util-from-dom.mjs",
7-
"repository": "https://github.com/kmck/hast-util-from/dom/issues",
7+
"repository": "https://github.com/kmck/hast-util-from-dom",
88
"author": "Keith McKnight <[email protected]> (https://keith.mcknig.ht)",
99
"license": "ISC",
1010
"scripts": {
@@ -23,13 +23,12 @@
2323
"eslint-plugin-import": "^2.12.0",
2424
"glob": "^7.1.2",
2525
"jest-cli": "^23.1.0",
26-
"jsdom": "^11.11.0",
2726
"rollup": "^0.59.4"
2827
},
29-
"files": [
30-
"dist"
31-
],
3228
"dependencies": {
3329
"hastscript": "^3.1.0"
34-
}
30+
},
31+
"files": [
32+
"dist"
33+
]
3534
}

src/index.test.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
import fs from 'fs';
22
import path from 'path';
33
import glob from 'glob';
4-
import jsdom from 'jsdom';
54

65
import fromDOM from './index';
76

8-
const { JSDOM } = jsdom;
9-
10-
function createDocumentFromHtml(htmlString) {
11-
const dom = new JSDOM(htmlString);
12-
return dom.window.document.documentElement.parentNode;
13-
}
14-
157
function createFragmentFromHtml(htmlString) {
168
const fragment = document.createDocumentFragment();
179
const tempEl = document.createElement('body');
@@ -24,6 +16,11 @@ function createFragmentFromHtml(htmlString) {
2416
return fragment;
2517
}
2618

19+
function createDocumentFromHtml(htmlString) {
20+
const parser = new DOMParser();
21+
return parser.parseFromString(htmlString, 'text/html');
22+
}
23+
2724
describe('hast-util-from-dom', () => {
2825
it('should transform a complete document', () => {
2926
const fixtureHtml = '<title>Hello!</title><h1>World!';

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2517,7 +2517,7 @@ jsbn@~0.1.0:
25172517
version "0.1.1"
25182518
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
25192519

2520-
jsdom@^11.11.0, jsdom@^11.5.1:
2520+
jsdom@^11.5.1:
25212521
version "11.11.0"
25222522
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-11.11.0.tgz#df486efad41aee96c59ad7a190e2449c7eb1110e"
25232523
dependencies:

0 commit comments

Comments
 (0)