1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-19 05:31:56 +02:00

Fix error when pasted HTML includes a doctype (#1160)

* Fix error when pasted HTML includes a doctype

When pasted HTML includes a doctype definition, `parsed.childNodes[0]`
is the doctype node, not the `<html>` node, so it's not safe to assume
that `parsed.childNodes[0].childNodes[1]` is the `<body>` node.

Using `parsed.body` ensures that we always get the `<body>` node no
matter where it is in the document.

* Update index.js
This commit is contained in:
Ryan Grove
2017-09-21 14:41:08 -07:00
committed by Ian Storm Taylor
parent c3f188c39f
commit 6f889454d0

View File

@@ -59,7 +59,8 @@ const TEXT_RULE = {
}
/**
* A default `parseHtml` option using the native `DOMParser`.
* A default `parseHtml` function that returns the `<body>` using the
* native `DOMParser`.
*
* @param {String} html
* @return {Object}
@@ -71,9 +72,8 @@ function defaultParseHtml(html) {
}
const parsed = new DOMParser().parseFromString(html, 'text/html')
// Unwrap from <html> and <body>.
const fragment = parsed.childNodes[0].childNodes[1]
return fragment
const { body } = parsed
return body
}
/**