normalizehtml.js 874 B

12345678910111213141516171819202122
  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. import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
  6. import { stringify } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  7. import { StylesProcessor } from '@ckeditor/ckeditor5-engine/src/view/stylesmap';
  8. import Document from '@ckeditor/ckeditor5-engine/src/view/document';
  9. /**
  10. * Parses given string of HTML and returns normalized HTML.
  11. *
  12. * @param {String} html HTML string to normalize.
  13. * @returns {String} Normalized HTML string.
  14. */
  15. export default function normalizeHtml( html ) {
  16. const processor = new HtmlDataProcessor( new Document( new StylesProcessor() ) );
  17. const parsed = processor.toView( html );
  18. return stringify( parsed );
  19. }