美文网首页
ckeditor解决wps复制粘贴问题

ckeditor解决wps复制粘贴问题

作者: 周郭郭先生 | 来源:发表于2019-05-24 11:50 被阅读0次

    1、ckeditor5-paste-from-office插件中space.js中

    export function normalizeSpacerunSpans( htmlDocument ) {  

      htmlDocument.querySelectorAll( 'span[style*=spacerun]' ).forEach( el => {

        // Use `el.childNodes[ 0 ].data.length` instead of `el.innerText.length`. For `el.innerText.length` which

        // contains spaces mixed with ` ` Edge browser returns incorrect length.

        if (el.childNodes[ 0 ].data) {

          const innerTextLength = el.childNodes[ 0 ].data.length;

          el.innerHTML = Array( innerTextLength + 1 ).join( '\u00A0 ' ).substr( 0, innerTextLength );

        }

      } );

    }

    2、ckeditor5-paste-from-office插件中image.js中

    function extractImageDataFromRtf( rtfData ) {

      if ( !rtfData ) {

        return [];

      }

      //office

      let regexPictureHeader = /{\\pict[\s\S]+?\\bliptag-?\d+(\\blipupi-?\d+)?({\\\*\\blipuid\s?[\da-fA-F]+)?[\s}]*?/;

      let regexPicture = new RegExp( '(?:(' + regexPictureHeader.source + '))([\\da-fA-F\\s]+)\\}', 'g' );

      let images = rtfData.match( regexPicture );

      let result = [];

      if ( !images ) {

        regexPictureHeader = /{\\pict[\s\S]+?(\\pngblip-?\d+)?(\\wmetafile8-?\d+)?{\\\*\\blipuid\s?[\da-fA-F]+[\s}]*?/;

        regexPicture = new RegExp( '(?:(' + regexPictureHeader.source + '))([\\da-fA-F\\s]+)\\}', 'g' );

        images = rtfData.match( regexPicture );

      }

      if ( images ) {

        for ( const image of images ) {

          let imageType = false;

          if ( image.includes( '\\pngblip' ) ) {

            imageType = 'image/png';

          } else if ( image.includes( '\\jpegblip' ) ) {

            imageType = 'image/jpeg';

          }

          if ( imageType ) {

            result.push( {

              hex: image.replace( regexPictureHeader, '' ).replace( /[^\da-fA-F]/g, '' ),

              type: imageType

            } );

          }

        }

      }

      return result;

    }

    相关文章

      网友评论

          本文标题:ckeditor解决wps复制粘贴问题

          本文链接:https://www.haomeiwen.com/subject/kehgzqtx.html