Skip to content

Commit

Permalink
Ensure HTML string is parsed reliably
Browse files Browse the repository at this point in the history
  • Loading branch information
domchristie committed Nov 27, 2017
1 parent 391ccb7 commit 85cd7b3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/root-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import { isBlock } from './utilities'
export default function RootNode (input) {
var root
if (typeof input === 'string') {
root = htmlParser().parseFromString(input, 'text/html').body
var doc = htmlParser().parseFromString(
// DOM parsers arrange elements in the <head> and <body>.
// Wrapping in a custom element ensures elements are reliably arranged in
// a single element.
'<x-turndown id="turndown-root">' + input + '</x-turndown>',
'text/html'
)
root = doc.getElementById('turndown-root')
} else {
root = input.cloneNode(true)
}
Expand Down

0 comments on commit 85cd7b3

Please sign in to comment.