mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-19 21:51:51 +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:
committed by
Ian Storm Taylor
parent
c3f188c39f
commit
6f889454d0
@@ -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
|
* @param {String} html
|
||||||
* @return {Object}
|
* @return {Object}
|
||||||
@@ -71,9 +72,8 @@ function defaultParseHtml(html) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const parsed = new DOMParser().parseFromString(html, 'text/html')
|
const parsed = new DOMParser().parseFromString(html, 'text/html')
|
||||||
// Unwrap from <html> and <body>.
|
const { body } = parsed
|
||||||
const fragment = parsed.childNodes[0].childNodes[1]
|
return body
|
||||||
return fragment
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user