{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/draft-js/issues/586","repository_url":"https://api.github.com/repos/facebook/draft-js","labels_url":"https://api.github.com/repos/facebook/draft-js/issues/586/labels{/name}","comments_url":"https://api.github.com/repos/facebook/draft-js/issues/586/comments","events_url":"https://api.github.com/repos/facebook/draft-js/issues/586/events","html_url":"https://github.com/facebook/draft-js/issues/586","id":170070065,"number":586,"title":"Is it possible to call `convertFromHTML` on NodeJS?","user":{"login":"Rokt33r","id":5865853,"avatar_url":"https://avatars.githubusercontent.com/u/5865853?v=3","gravatar_id":"","url":"https://api.github.com/users/Rokt33r","html_url":"https://github.com/Rokt33r","followers_url":"https://api.github.com/users/Rokt33r/followers","following_url":"https://api.github.com/users/Rokt33r/following{/other_user}","gists_url":"https://api.github.com/users/Rokt33r/gists{/gist_id}","starred_url":"https://api.github.com/users/Rokt33r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rokt33r/subscriptions","organizations_url":"https://api.github.com/users/Rokt33r/orgs","repos_url":"https://api.github.com/users/Rokt33r/repos","events_url":"https://api.github.com/users/Rokt33r/events{/privacy}","received_events_url":"https://api.github.com/users/Rokt33r/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-09T02:47:40Z","updated_at":"2016-08-09T04:56:19Z","closed_at":null,"body":"**Do you want to request a *feature* or report a *bug*?**\r\n\r\nI want to migrate from my legacy html content in DB to Draft Raw Object.\r\n\r\n`var raw = converrtToRaw(ContentState.createFromBlockArray(convertFromHTML('<div></div>)))`\r\n\r\n**What is the current behavior?**\r\n\r\nconvertFromHTML requires `document` object.\r\n```\r\nReferenceError: document is not defined\r\n    at getSafeBodyFromHTML (/PROJECT_DIRECTORY/node_modules/draft-js/lib/getSafeBodyFromHTML.js:27:19)\r\n```\r\n\r\n**If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://jsfiddle.net or similar.**\r\n\r\nRun the below codes in Node\r\n```\r\nconst djs = require('draft-js')\r\nconsole.log(djs.convertFromHTML('<div></div>'))\r\n```\r\n\r\n**What is the expected behavior?**\r\n\r\nreturn `{blocks: [...], ....}`\r\n\r\n**Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js?**\r\n\r\nNode v4.4.4"},"comment":{"url":"https://api.github.com/repos/facebook/draft-js/issues/comments/238453581","html_url":"https://github.com/facebook/draft-js/issues/586#issuecomment-238453581","issue_url":"https://api.github.com/repos/facebook/draft-js/issues/586","id":238453581,"user":{"login":"Rokt33r","id":5865853,"avatar_url":"https://avatars.githubusercontent.com/u/5865853?v=3","gravatar_id":"","url":"https://api.github.com/users/Rokt33r","html_url":"https://github.com/Rokt33r","followers_url":"https://api.github.com/users/Rokt33r/followers","following_url":"https://api.github.com/users/Rokt33r/following{/other_user}","gists_url":"https://api.github.com/users/Rokt33r/gists{/gist_id}","starred_url":"https://api.github.com/users/Rokt33r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rokt33r/subscriptions","organizations_url":"https://api.github.com/users/Rokt33r/orgs","repos_url":"https://api.github.com/users/Rokt33r/repos","events_url":"https://api.github.com/users/Rokt33r/events{/privacy}","received_events_url":"https://api.github.com/users/Rokt33r/received_events","type":"User","site_admin":false},"created_at":"2016-08-09T04:56:19Z","updated_at":"2016-08-09T04:56:19Z","body":"It works.\r\n\r\nCode:\r\n```\r\nconst jsdom = require('jsdom')\r\njsdom.env('', function (err, window) {\r\n  global.window = window\r\n  global.document = window.document\r\n  global.navigator = window.navigator\r\n  global.HTMLElement = window.HTMLElement\r\n  const djs = require('draft-js')\r\n  console.log(djs.convertToRaw(djs.ContentState.createFromBlockArray(djs.convertFromHTML('<div>Hello</div>'))))\r\n  process.exit(0)\r\n})\r\n```\r\n\r\nResult:\r\n```\r\n{ entityMap: {},\r\n  blocks:\r\n   [ { key: '2scc',\r\n       text: 'Hello',\r\n       type: 'unstyled',\r\n       depth: 0,\r\n       inlineStyleRanges: [],\r\n       entityRanges: [] } ] }\r\n```\r\n\r\nBut, I should set global variables several things.\r\nIs there any better way?"}}
{"actor":{"display_login":"Rokt33r"}}