8
0

basichtmlwriter.js 853 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module engine/dataprocessor/basichtmlwriter
  7. */
  8. /* globals document */
  9. /**
  10. * Basic HTML writer. It uses the native `innerHTML` property for basic conversion
  11. * from a document fragment to an HTML string.
  12. *
  13. * @implements module:engine/dataprocessor/htmlwriter~HtmlWriter
  14. */
  15. export default class BasicHtmlWriter {
  16. /**
  17. * Returns an HTML string created from the document fragment.
  18. *
  19. * @param {DocumentFragment} fragment
  20. * @returns {String}
  21. */
  22. getHtml( fragment ) {
  23. const doc = document.implementation.createHTMLDocument( '' );
  24. const container = doc.createElement( 'div' );
  25. container.appendChild( fragment );
  26. return container.innerHTML;
  27. }
  28. }