Ticket #4067: 4067_3.patch

File 4067_3.patch, 23.1 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/htmlwriter/plugin.js

     
    6767
    6868                var dtd = CKEDITOR.dtd;
    6969
    70                 for ( var e in CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
     70                for ( var e in CKEDITOR.tools.extend( {}, dtd.$noneBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
    7171                {
    7272                        this.setRules( e,
    7373                                {
  • _source/core/htmlparser/element.js

     
    3535        this.children = [];
    3636
    3737        var dtd                 = CKEDITOR.dtd,
    38                 isBlockLike     = !!( dtd.$block[ name ] || dtd.$listItem[ name ] || dtd.$tableContent[ name ] ),
     38                isBlockLike     = !!( dtd.$noneBodyContent[ name ] || dtd.$block[ name ] || dtd.$listItem[ name ] || dtd.$tableContent[ name ] ),
    3939                isEmpty         = !!dtd.$empty[ name ];
    4040
    4141        this.isEmpty    = isEmpty;
  • _source/plugins/wysiwygarea/plugin.js

     
    1515         */
    1616        var nonExitableElementNames = { table:1,pre:1 };
    1717        // Matching an empty paragraph at the end of document.
    18         var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|&#160;)\s*(:?<\/\1>)?\s*$/gi;
     18        var emptyParagraphRegexp = /\s*<(p|div|address|h\d|center)[^>]*>\s*(?:<br[^>]*>|&nbsp;|&#160;)\s*(:?<\/\1>)?\s*(:?$|<\/body>)/gi;
    1919
    2020        function onInsertHtml( evt )
    2121        {
     
    550550                                                        {
    551551                                                                isLoadingData = true;
    552552
    553                                                                 // Get the HTML version of the data.
     553                                                                // Get the full page HTML version of the data.
    554554                                                                if ( editor.dataProcessor )
    555555                                                                {
    556                                                                         data = editor.dataProcessor.toHtml( data, fixForBody );
     556                                                                        data = editor.dataProcessor.toHtml( data, fixForBody,
     557                                                                                        editor.config.fullPage, editor.config.docType );
    557558                                                                }
    558559
    559                                                                 data =
    560                                                                         editor.config.docType +
    561                                                                         '<html dir="' + editor.config.contentsLangDirection + '">' +
    562                                                                         '<head>' +
    563                                                                                 '<link type="text/css" rel="stylesheet" href="' +
    564                                                                                 [].concat( editor.config.contentsCss ).join( '"><link type="text/css" rel="stylesheet" href="' ) +
    565                                                                                 '">' +
    566                                                                                 '<style type="text/css" _fcktemp="true">' +
    567                                                                                         editor._.styles.join( '\n' ) +
    568                                                                                 '</style>'+
    569                                                                         '</head>' +
    570                                                                         '<body>' +
    571                                                                                 data +
    572                                                                         '</body>' +
    573                                                                         '</html>' +
    574                                                                         activationScript;
     560                                                                // Provide basic fixings even without the full-page plugin.
     561                                                                if( !editor.config.fullPage )
     562                                                                {
     563                                                                        data =
     564                                                                                editor.config.docType +
     565                                                                                '<html dir="' + editor.config.contentsLangDirection + '">' +
     566                                                                                '<head>' +
     567                                                                                        '<link type="text/css" rel="stylesheet" href="' +
     568                                                                                        [].concat( editor.config.contentsCss ).join( '"><link type="text/css" rel="stylesheet" href="' ) +
     569                                                                                        '">' +
     570                                                                                        '<style type="text/css" _cke_temp="true">' +
     571                                                                                                editor._.styles.join( '\n' ) +
     572                                                                                        '</style>'+
     573                                                                                '</head>' +
     574                                                                                '<body>' +
     575                                                                                        data +
     576                                                                                '</body>' +
     577                                                                                '</html>';
     578                                                                }
    575579
     580                                                                data += activationScript;
     581
    576582                                                                window[ '_cke_htmlToLoad_' + editor.name ] = data;
    577583                                                                CKEDITOR._[ 'contentDomReady' + editor.name ] = contentDomReady;
    578584                                                                createIFrame();
     
    589595
    590596                                                        getData : function()
    591597                                                        {
    592                                                                 var data = iframe.getFrameDocument().getBody().getHtml();
     598                                                                var frameDoc = iframe.getFrameDocument(),
     599                                                                        documentElement = frameDoc.getDocumentElement(),
     600                                                                        docTypeAttr = documentElement.getAttribute( 'cke_docType' ),
     601                                                                        data = editor.config.fullPage ?
     602                                                                                        ( docTypeAttr ? decodeURIComponent( docTypeAttr ) : '' ) + documentElement.getOuterHtml()
     603                                                                                        : frameDoc.getBody().getHtml();
    593604
    594605                                                                if ( editor.dataProcessor )
    595                                                                         data = editor.dataProcessor.toDataFormat( data, fixForBody );
     606                                                                        data = editor.dataProcessor.toDataFormat( data, fixForBody, editor.config.fullPage );
    596607
    597608                                                                // Strip the last blank paragraph within document.
    598609                                                                if ( editor.config.ignoreEmptyParagraph )
  • _source/core/dom/element.js

     
    328328                 */
    329329                getHtml : function()
    330330                {
    331                         return this.$.innerHTML;
     331                        var retval = this.$.innerHTML;
     332                        // Strip <?xml:namespace> tag in the output HTML of
     333                        // namespaced element in IE(#3341).
     334                        return CKEDITOR.env.ie ? retval.replace( /<\?[^>]*>/g, '' ) : retval;
    332335                },
    333336
    334337                getOuterHtml : function()
  • _source/core/htmlparser/filter.js

     
    127127
    128128        function addItemsToList( list, items, priority )
    129129        {
     130                if( typeof items == 'function' )
     131                        items = [ items ];
     132
    130133                var i, j,
    131134                        listLength = list.length,
    132135                        itemsLength = items && items.length;
  • _source/plugins/fullpage/plugin.js

     
     1/*
     2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5
     6/**
     7 * @fileOverview The "wysiwygarea" plugin. It registers the "wysiwyg" editing
     8 *              mode, which handles the main editing area space.
     9 */
     10
     11( function()
     12{
     13        var dtd = CKEDITOR.dtd;
     14        CKEDITOR.plugins.add( 'fullpage',
     15        {
     16                requires : [ 'htmldataprocessor' ],
     17                afterInit : function( editor )
     18                {
     19                        var fullPageDataFilterRules =
     20                        {
     21                                // Full page support. ( #4067 )
     22                                elements :
     23                                {
     24                                        $ : function( element )
     25                                        {
     26                                                // Fix fullPage elements at the fragment element.
     27                                                if ( ( element._.fullPage !== false ) && !element.name )
     28                                                {
     29                                                        var firstChild = element.children[ 0 ];
     30                                                        // Full document.
     31                                                        if ( firstChild && firstChild.name == 'html' )
     32                                                                return;
     33                                                        // Missing <html>.
     34                                                        if ( !firstChild || firstChild.name in dtd.html )
     35                                                                wrapContent( element, 'html' );
     36                                                        // Missing <html> and <body>/<head>.
     37                                                        else
     38                                                        {
     39                                                                wrapContent( wrapContent( element, 'html' ),
     40                                                                                firstChild.name in dtd.head ? 'head' : 'body' );
     41                                                        }
     42                                                }
     43                                        },
     44
     45                                        html : function ( element )
     46                                        {
     47                                                // Both <head> and <body> are mandatory.
     48                                                if ( !childByTagName( element, 'head' ) )
     49                                                        element.children.splice( 0, 0, new CKEDITOR.htmlParser.element( 'head', {} ) );
     50                                                if ( !childByTagName( element, 'body' ) )
     51                                                        element.children.splice( element.children.length, 0, new CKEDITOR.htmlParser.element( 'body', {} ) );
     52
     53                                                // 1. Save doc-type as a custom attribute;
     54                                                // 2. Adding missing xml namespace attribute;
     55                                                // 3. Adding missing language direction attribute.
     56                                                var attrs = element.attributes,
     57                                                                docType = element.parent._.docType,
     58                                                                configDir = editor.config.contentsLangDirection;
     59                                                if ( docType )
     60                                                {
     61                                                        attrs.cke_docType = encodeURIComponent( docType );
     62                                                        docType.match( /xhtml/i )
     63                                                                        && !attrs.xmlns
     64                                                                        && ( attrs.xmlns = 'http://www.w3.org/1999/xhtml' );
     65                                                }
     66                                                !attrs.dir && configDir && ( attrs.dir = configDir );
     67                                        },
     68
     69                                        head : function ( element )
     70                                        {
     71                                                // <title> is mandatory.
     72                                                if ( !childByTagName( element, 'title' ) )
     73                                                        element.children.splice( 0, 0, new CKEDITOR.htmlParser.element( 'title', {} ) );
     74
     75                                                // Adding default styles.
     76                                                var styleLinks = [].concat( editor.config.contentsCss ),
     77                                                                styleText = editor._.styles.join( '\n' );
     78
     79                                                if ( styleLinks )
     80                                                {
     81                                                        for ( var i = 0; i < styleLinks.length; i++ )
     82                                                        {
     83                                                                var link = new CKEDITOR.htmlParser.element( 'link',
     84                                                                {
     85                                                                        type: 'text/css' ,
     86                                                                        rel : 'stylesheet',
     87                                                                        href : styleLinks[ i ],
     88                                                                        cke_temp : 1
     89                                                                } );
     90                                                                element.add( link );
     91                                                        }
     92                                                }
     93                                                if ( styleText )
     94                                                {
     95                                                        var style = new CKEDITOR.htmlParser.element( 'style',
     96                                                        {
     97                                                                type: 'text/css',
     98                                                                cke_temp : 1
     99                                                        } );
     100                                                        style.add( new CKEDITOR.htmlParser.text( styleText ) );
     101                                                        element.add( style );
     102                                                }
     103                                        }
     104                                }
     105                        };
     106
     107                        var fullPageHtmlFilterRules =
     108                        {
     109                                elements :
     110                                {
     111                                        html : function ( element )
     112                                        {
     113                                                delete element.attributes.cke_doctype;
     114                                                // Preserve only body contents in non-fullPage mode.
     115                                                if( element.parent._.fullPage === false )
     116                                                {
     117                                                        var children = element.children,
     118                                                                contents,
     119                                                                child;
     120                                                        for ( var i = 0; i < children.length; i++ )
     121                                                        {
     122                                                                child = children[ i ];
     123                                                                if ( 'body' == child.name )
     124                                                                {
     125                                                                        contents = child.children;
     126                                                                        break;
     127                                                                }
     128                                                        }
     129
     130                                                        element.children = contents;
     131                                                        delete element.name;
     132                                                }
     133                                        },
     134
     135                                        body : function( element )
     136                                        {
     137                                                delete element.attributes.spellcheck;
     138                                                delete element.attributes.contenteditable;
     139                                        },
     140                                        // Elements used interally in 'wysiwyg' mode shouldn't appear in output.
     141                                        style : removeInternal,
     142                                        link : removeInternal
     143                                },
     144                                attributeNames :
     145                                [
     146                                        [ 'hidefocus', '' ]
     147                                ]
     148                        };
     149
     150                        var dataProcessor = editor.dataProcessor;
     151                        dataProcessor.dataFilter.addRules( fullPageDataFilterRules );
     152                        dataProcessor.htmlFilter.addRules( fullPageHtmlFilterRules );
     153                }
     154        } );
     155
     156        function removeInternal( element )
     157        {
     158                if( element.attributes.cke_temp )
     159                        return false;
     160        }
     161
     162        function childByTagName( element, tagName )
     163        {
     164                var children = element.children,
     165                        child;
     166                for ( var i = 0; i < children.length; i++ )
     167                {
     168                        child = children[ i ];
     169                        if( child.name && child.name == tagName )
     170                                return child;
     171                }
     172        }
     173        function wrapContent( element, tagName )
     174        {
     175                var childrens = element.children,
     176                        root = new CKEDITOR.htmlParser.element( tagName, {} );
     177                element.children = [];
     178                element.add( root );
     179                for ( var i = 0; i < childrens.length; i++ )
     180                {
     181                        root.add( childrens[ i ] );
     182                }
     183                return root;
     184        }
     185
     186} )();
  • _source/core/config.js

     
    198198         * @type String
    199199         * @example
    200200         */
    201         plugins : 'about,basicstyles,blockquote,button,clipboard,colorbutton,colordialog,contextmenu,elementspath,enterkey,entities,filebrowser,find,flash,font,format,forms,horizontalrule,htmldataprocessor,image,indent,justify,keystrokes,link,list,maximize,newpage,pagebreak,pastefromword,pastetext,popup,preview,print,removeformat,resize,save,scayt,smiley,showblocks,sourcearea,stylescombo,table,tabletools,specialchar,tab,templates,toolbar,undo,wysiwygarea,wsc',
     201        plugins : 'about,basicstyles,blockquote,button,clipboard,colorbutton,colordialog,contextmenu,elementspath,enterkey,entities,filebrowser,find,flash,font,format,forms,fullpage,horizontalrule,htmldataprocessor,image,indent,justify,keystrokes,link,list,maximize,newpage,pagebreak,pastefromword,pastetext,popup,preview,print,removeformat,resize,save,scayt,smiley,showblocks,sourcearea,stylescombo,table,tabletools,specialchar,tab,templates,toolbar,undo,wysiwygarea,wsc',
    202202
    203203        /**
    204204         * List of additional plugins to be loaded. This is a tool setting which
  • _source/core/dtd.js

     
    5151                N = {'#':1},
    5252                O = X({param:1},K),
    5353                P = X({form:1},A,D,E,I),
    54                 Q = {li:1};
     54                Q = {li:1},
     55        R = {style:1,script:1},
     56        S = {base:1,link:1,meta:1,title:1},
     57                T = X(S,R),
     58                U = {head:1,body:1},
     59                V = {html:1};
    5560
    56         var block = {address:1,blockquote:1,center:1,dir:1,div:1,dl:1,fieldset:1,form:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,hr:1,isindex:1,menu:1,noframes:1,ol:1,p:1,pre:1,table:1,ul:1};
     61        var block = {address:1,blockquote:1,center:1,dir:1,div:1,dl:1,fieldset:1,form:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,hr:1,isindex:1,menu:1,noframes:1,ol:1,p:1,pre:1,table:1,ul:1},
     62                inline = {a:1,abbr:1,acronym:1,b:1,basefont:1,bdo:1,big:1,br:1,cite:1,code:1,dfn:1,em:1,font:1,i:1,img:1,input:1,kbd:1,label:1,q:1,s:1,samp:1,select:1,small:1,span:1,strike:1,strong:1,sub:1,sup:1,textarea:1,tt:1,u:1,'var':1,applet:1,button:1,del:1,iframe:1,ins:1,map:1,object:1,script:1};
    5763
    5864    return /** @lends CKEDITOR.dtd */ {
    5965
    6066                // The "$" items have been added manually.
    6167
    62                 /**
     68            $ : V,
     69
     70            // List of elements won't appear in body.
     71            $noneBodyContent: X(V,U,S),
     72
     73            /**
    6374                 * List of block elements, like "p" or "div".
    6475                 * @type Object
    6576                 * @example
    6677                 */
    6778                $block : block,
    6879
    69                 $body : X({script:1}, block),
     80            $inline : inline,
    7081
     82                $body : X({script:1,style:1}, block),
     83
    7184                $cdata : {script:1,style:1},
    7285
    7386                /**
     
    120133                 */
    121134                $tableContent : {caption:1,col:1,colgroup:1,tbody:1,td:1,tfoot:1,th:1,thead:1,tr:1},
    122135
    123         col : {},
     136        html: U,
     137            head: T,
     138            style: N,
     139            script: N,
     140            body: X(inline, block),
     141            col : {},
    124142        tr : {td:1,th:1},
    125143        img : {},
    126144        colgroup : {col:1},
     
    200218        pre : X(G,C),
    201219        p : L,
    202220        em : L,
    203         dfn : L
     221        dfn : L,
     222            base: {},
     223                link: {},
     224            meta: {},
     225            title: N
    204226    };
    205227})();
    206228
  • _source/core/htmlparser/basicwriter.js

     
    1515
    1616        proto :
    1717        {
     18                docType : function( docType )
     19                {
     20                        this._.output.push( docType );
     21                },
     22
    1823                /**
    1924                 * Writes the tag opening part for a opener tag.
    2025                 * @param {String} tagName The element name for this tag.
     
    117122                reset : function()
    118123                {
    119124                        this._.output = [];
     125                        this._.indent = false;
    120126                },
    121127
    122128                /**
  • _source/core/htmlparser/fragment.js

     
    1818         * alert( fragment.children.length );  "2"
    1919         */
    2020        this.children = [];
     21        this.attributes = {};
    2122
    2223        /**
    2324         * Get the fragment parent. Should always be null.
     
    3031        /** @private */
    3132        this._ =
    3233        {
     34                fullPage : true,
     35                docType : '',
    3336                isBlockLike : true,
    3437                hasInlineStarted : false
    3538        };
     
    114117                                        elementName = realElementName;
    115118                                else
    116119                                        elementName =  element.name;
    117                                 if ( !( elementName in CKEDITOR.dtd.$body ) )
     120                                if ( elementName
     121                                                && !( elementName in CKEDITOR.dtd.$body )
     122                                                && !( elementName in CKEDITOR.dtd.$noneBodyContent )  )
    118123                                {
    119124                                        var savedCurrent = currentNode;
    120125
     
    156161                        }
    157162                }
    158163
     164                parser.onDocType = function ( docType )
     165                {
     166                        fragment._.docType = docType;
     167                };
     168
    159169                parser.onTagOpen = function( tagName, attributes, selfClosing )
    160170                {
    161171                        var element = new CKEDITOR.htmlParser.element( tagName, attributes );
     
    180190                        }
    181191
    182192                        var currentName = currentNode.name,
    183                                 currentDtd = ( currentName && CKEDITOR.dtd[ currentName ] ) || ( currentNode._.isBlockLike ? CKEDITOR.dtd.div : CKEDITOR.dtd.span );
     193                                currentDtd = currentName &&
     194                                             ( CKEDITOR.dtd[ currentName ]
     195                                                       || ( currentNode._.isBlockLike ? CKEDITOR.dtd.div : CKEDITOR.dtd.span ) );
    184196
    185197                        // If the element cannot be child of the current element.
    186                         if ( !element.isUnknown && !currentNode.isUnknown && !currentDtd[ tagName ] )
     198                        if ( currentDtd   // Fragment could receive any elements.
     199                                 && !element.isUnknown && !currentNode.isUnknown && !currentDtd[ tagName ] )
    187200                        {
    188                                 // If this is the fragment node, just ignore this tag and add
    189                                 // its children.
    190                                 if ( !currentName )
    191                                         return;
    192201
    193202                                var reApply = false,
    194203                                        addPoint;   // New position to start adding nodes.
     
    330339                                        index--;
    331340                                }
    332341                        }
     342
     343                        if( tagName == 'body' )
     344                                fixForBody = false;
    333345                };
    334346
    335347                parser.onText = function( text )
     
    345357
    346358                        checkPending();
    347359
    348                         if ( fixForBody && !currentNode.type )
     360                        if ( fixForBody
     361                                 && CKEDITOR.tools.trim( text )
     362                                 && ( !currentNode.type || currentNode.name == 'body' ) )
    349363                                this.onTagOpen( fixForBody, {} );
    350364
    351365                        // Shrinking consequential spaces into one single for all elements
     
    375389                        var parent = currentNode.parent,
    376390                                node = currentNode;
    377391
    378                         if ( fixForBody && !parent.type && !CKEDITOR.dtd.$body[ node.name ] )
     392                        if ( fixForBody
     393                                 && ( !parent.type || parent.name == 'body' )
     394                                 && !CKEDITOR.dtd.$body[ node.name ] )
    379395                        {
    380396                                currentNode = parent;
    381397                                parser.onTagOpen( fixForBody, {} );
     
    444460                 */
    445461                writeHtml : function( writer, filter )
    446462                {
     463                        // Call element filter on fragment as well as write doc-type.
     464                        if( !this.name )
     465                        {
     466                                filter && filter.onElement( this );
     467                                this._.docType && writer.docType( this._.docType );
     468                        }
     469
    447470                        for ( var i = 0, len = this.children.length ; i < len ; i++ )
    448471                                this.children[i].writeHtml( writer, filter );
    449472                }
  • _source/plugins/htmldataprocessor/plugin.js

     
    206206                return html.replace( protectAttributeRegex, '$& _cke_saved_$1' );
    207207        }
    208208
    209         var protectStyleTagsRegex = /<(style)(?=[ >])[^>]*>[^<]*<\/\1>/gi;
     209        var protectStyleTagsRegex = /<(style)(?=[ >])[^>]*>[^<]*<\/\1>/gi,
     210                protectFullPageElementsRegex = /<(:?link|meta|base).*?>/;
    210211        var encodedTagsRegex = /<cke:encoded>([^<]*)<\/cke:encoded>/gi;
    211212        var protectElementNamesRegex = /(<\/?)((?:object|embed|param).*?>)/gi;
     213        var shelvefullPageElementsRegex = /(<\/?)((?:html|body|head|title).*?>)/gi,
     214                shelvedElementsRegex = /(<\/?)cke_fullpage:([^>]*>)/gi;
    212215        var protectSelfClosingRegex = /<cke:param(.*?)\/>/gi;
    213216
    214         function protectStyleTagsMatch( match )
     217        function encodeMatched( match )
    215218        {
    216219                return '<cke:encoded>' + encodeURIComponent( match ) + '</cke:encoded>';
    217220        }
    218221
     222        function shelveTags( html, isUnShelve )
     223        {
     224                if ( isUnShelve )
     225                        return unprotectEncodedTags( html.replace( shelvedElementsRegex, '$1$2' ) );
     226                else
     227                {
     228                        return html
     229                                        .replace( shelvefullPageElementsRegex, '$1cke_fullpage:$2' )
     230                                        .replace( protectFullPageElementsRegex, encodeMatched );
     231                }
     232        }
     233
    219234        function protectStyleTags( html )
    220235        {
    221                 return html.replace( protectStyleTagsRegex, protectStyleTagsMatch );
     236                return html.replace( protectStyleTagsRegex, encodeMatched );
    222237        }
    223238        function protectElementsNames( html )
    224239        {
     
    309324
    310325        CKEDITOR.htmlDataProcessor.prototype =
    311326        {
    312                 toHtml : function( data, fixForBody )
     327                toHtml : function( data, fixForBody, fullPage, docType )
    313328                {
    314329                        // The source data is already HTML, but we need to clean
    315330                        // it up and apply the filter.
     
    333348                        // protecting them into open-close.(#3591)
    334349                        data = protectSelfClosingElements( data );
    335350
     351                        data = shelveTags( data );
    336352                        // Call the browser to help us fixing a possibly invalid HTML
    337353                        // structure.
    338                         var div = document.createElement( 'div' );
     354                        var div = new CKEDITOR.dom.element( 'div' );
    339355                        // Add fake character to workaround IE comments bug. (#3801)
    340                         div.innerHTML = 'a' + data;
    341                         data = div.innerHTML.substr( 1 );
     356                        div.setHtml( 'a' + data );
     357                        data = div.getHtml().substr( 1 );
    342358
     359                        data = shelveTags( data, true );
    343360                        if ( CKEDITOR.env.ie )
    344361                                data = unprotectEncodedTags( data );
    345362
     
    348365                        var fragment = CKEDITOR.htmlParser.fragment.fromHtml( data, fixForBody ),
    349366                                writer = new CKEDITOR.htmlParser.basicWriter();
    350367
     368                        // Is docType missing and been explicitly defined in configuration?
     369                        docType && !fragment._.docType && ( fragment._.docType = docType );
     370
     371                        // Is HTML snippet mode instead of full page ?
     372                        ( fullPage !== true )
     373                                && ( fragment._.fullPage = false, delete fragment._.docType );
     374
    351375                        fragment.writeHtml( writer, this.dataFilter );
    352376
    353377                        return writer.getHtml( true );
    354378                },
    355379
    356                 toDataFormat : function( html, fixForBody )
     380                toDataFormat : function( html, fixForBody, fullPage )
    357381                {
    358382                        var writer = this.writer,
    359383                                fragment = CKEDITOR.htmlParser.fragment.fromHtml( html, fixForBody );
    360384
    361                         writer.reset();
     385                        // Is HTML snippet mode instead of full page ?
     386                        ( fullPage !== true )
     387                                && ( fragment._.fullPage = false, delete fragment._.docType );
    362388
     389                        writer.reset();
    363390                        fragment.writeHtml( writer, this.htmlFilter );
    364391
    365392                        return writer.getHtml( true );
  • _source/core/htmlparser.js

     
    1212{
    1313        this._ =
    1414        {
    15                 htmlPartsRegex : new RegExp( '<(?:(?:\\/([^>]+)>)|(?:!--([\\S|\\s]*?)-->)|(?:([^\\s>]+)\\s*((?:(?:[^"\'>]+)|(?:"[^"]*")|(?:\'[^\']*\'))*)\\/?>))', 'g' )
     15                htmlPartsRegex : new RegExp( '<(?:(?:\\/([^>]+)>)|(?:!--([\\S|\\s]*?)-->)|(?:([^\\s>]+)\\s*((?:(?:[^"\'>]+)|(?:"[^"]*")|(?:\'[^\']*\'))*)\\/?>))', 'g' ),
     16                docTypeRegex : /<!DOCTYPE[^>]*>/i
    1617        };
    1718};
    1819
     
    2425        CKEDITOR.htmlParser.prototype =
    2526        {
    2627                /**
     28                 * Function to be fired when a docType defintion is found. This function
     29                 * should be overriden when using this class.
     30                 * @param {String} docType The declaration text.
     31                 */
     32                onDocType : function() {},
     33
     34                /**
    2735                 * Function to be fired when a tag opener is found. This function
    2836                 * should be overriden when using this class.
    2937                 * @param {String} tagName The tag name. The name is guarantted to be
     
    113121                 */
    114122                parse : function( html )
    115123                {
     124                        // Remove docType declaration at first.
     125                        var self = this;
     126                        html = html.replace( this._.docTypeRegex, function( match )
     127                        {
     128                                self.onDocType( match );
     129                                return '';
     130                        } );
     131
    116132                        var parts,
    117133                                tagName,
    118134                                nextIndex = 0,
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy