Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

35 строки
1.1 KiB

  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow strict-local
  9. * @emails oncall+draft_js
  10. */
  11. 'use strict';
  12. const UserAgent = require("fbjs/lib/UserAgent");
  13. const invariant = require("fbjs/lib/invariant");
  14. const isOldIE = UserAgent.isBrowser('IE <= 9'); // Provides a dom node that will not execute scripts
  15. // https://developer.mozilla.org/en-US/docs/Web/API/DOMImplementation.createHTMLDocument
  16. // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/HTML_to_DOM
  17. function getSafeBodyFromHTML(html: string): ?Element {
  18. let doc;
  19. let root = null; // Provides a safe context
  20. if (!isOldIE && document.implementation && document.implementation.createHTMLDocument) {
  21. doc = document.implementation.createHTMLDocument('foo');
  22. invariant(doc.documentElement, 'Missing doc.documentElement');
  23. doc.documentElement.innerHTML = html;
  24. root = doc.getElementsByTagName('body')[0];
  25. }
  26. return root;
  27. }
  28. module.exports = getSafeBodyFromHTML;