googledocsnormalizer.js 984 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /**
  6. * @module paste-from-office/normalizers/googledocsnormalizer
  7. */
  8. import removeBoldWrapper from '../filters/removeboldwrapper';
  9. import { unwrapParagraphInListItem } from '../filters/list';
  10. import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter';
  11. const googleDocsMatch = /id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;
  12. /**
  13. * Normalizer for the content pasted from Google Docs.
  14. *
  15. * @implements module:paste-from-office/normalizer~Normalizer
  16. */
  17. export default class GoogleDocsNormalizer {
  18. /**
  19. * @inheritDoc
  20. */
  21. isActive( htmlString ) {
  22. return googleDocsMatch.test( htmlString );
  23. }
  24. /**
  25. * @inheritDoc
  26. */
  27. execute( data ) {
  28. const writer = new UpcastWriter();
  29. removeBoldWrapper( data.content, writer );
  30. unwrapParagraphInListItem( data.content, writer );
  31. }
  32. }