/* Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ /** * A lightweight representation of an HTML DOM structure. * @constructor * @example */ CKEDITOR.htmlParser.fragment = function() { /** * The nodes contained in the root of this fragment. * @type Array * @example * var fragment = CKEDITOR.htmlParser.fragment.fromHtml( 'Sample Text' ); * alert( fragment.children.length ); "2" */ this.children = []; /** * Get the fragment parent. Should always be null. * @type Object * @default null * @example */ this.parent = null; /** @private */ this._ = { isBlockLike : true, hasInlineStarted : false }; }; (function() { // Block-level elements whose internal structure should be respected during // parser fixing. var nonBreakingBlocks = CKEDITOR.tools.extend( { table:1,ul:1,ol:1,dl:1 }, CKEDITOR.dtd.table, CKEDITOR.dtd.ul, CKEDITOR.dtd.ol, CKEDITOR.dtd.dl ); // IE < 8 don't output the close tag on definition list items. (#6975) var optionalCloseTags = CKEDITOR.env.ie && CKEDITOR.env.version < 8 ? { dd : 1, dt :1 } : {}; var listBlocks = { ol:1, ul:1 }; // Dtd of the fragment element, basically it accept anything except for intermediate structure, e.g. orphan
  • . var rootDtd = CKEDITOR.tools.extend( {}, { html: 1 }, CKEDITOR.dtd.html, CKEDITOR.dtd.body, CKEDITOR.dtd.head, { style:1,script:1 } ); function isRemoveEmpty( node ) { // Empty link is to be removed when empty but not anchor. (#7894) return node.name == 'a' && node.attributes.href || CKEDITOR.dtd.$removeEmpty[ node.name ]; } /** * Creates a {@link CKEDITOR.htmlParser.fragment} from an HTML string. * @param {String} fragmentHtml The HTML to be parsed, filling the fragment. * @param {Number} [fixForBody=false] Wrap body with specified element if needed. * @param {CKEDITOR.htmlParser.element} contextNode Parse the html as the content of this element. * @returns CKEDITOR.htmlParser.fragment The fragment created. * @example * var fragment = CKEDITOR.htmlParser.fragment.fromHtml( 'Sample Text' ); * alert( fragment.children[0].name ); "b" * alert( fragment.children[1].value ); " Text" */ CKEDITOR.htmlParser.fragment.fromHtml = function( fragmentHtml, fixForBody, contextNode ) { var parser = new CKEDITOR.htmlParser(), fragment = contextNode || new CKEDITOR.htmlParser.fragment(), pendingInline = [], pendingBRs = [], currentNode = fragment, // Indicate we're inside a