normalizehtml.js 789 B

123456789101112131415161718192021
  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. /**
  9. * Parses given string of HTML and returns normalized HTML.
  10. *
  11. * @param {String} html HTML string to normalize.
  12. * @returns {String} Normalized HTML string.
  13. */
  14. export default function normalizeHtml( html ) {
  15. const processor = new HtmlDataProcessor( new StylesProcessor() );
  16. const parsed = processor.toView( html );
  17. return stringify( parsed );
  18. }