@wordpress/blocks
Version:
Block API for WordPress.
8 lines (7 loc) • 4.04 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/api/raw-handling/index.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport { getPhrasingContentSchema } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { htmlToBlocks } from './html-to-blocks';\nimport parse from '../parser';\nimport normaliseBlocks from './normalise-blocks';\nimport specialCommentConverter from './special-comment-converter';\nimport listReducer from './list-reducer';\nimport blockquoteNormaliser from './blockquote-normaliser';\nimport figureContentReducer from './figure-content-reducer';\nimport shortcodeConverter from './shortcode-converter';\nimport { deepFilterHTML, getBlockContentSchema } from './utils';\n\nexport { pasteHandler } from './paste-handler';\n\nexport function deprecatedGetPhrasingContentSchema( context ) {\n\tdeprecated( 'wp.blocks.getPhrasingContentSchema', {\n\t\tsince: '5.6',\n\t\talternative: 'wp.dom.getPhrasingContentSchema',\n\t} );\n\treturn getPhrasingContentSchema( context );\n}\n\n/**\n * Converts an HTML string to known blocks.\n *\n * @param {Object} $1\n * @param {string} $1.HTML The HTML to convert.\n *\n * @return {Array} A list of blocks.\n */\nexport function rawHandler( { HTML = '' } ) {\n\t// If we detect block delimiters, parse entirely as blocks.\n\tif ( HTML.indexOf( '<!-- wp:' ) !== -1 ) {\n\t\tconst parseResult = parse( HTML );\n\t\tconst isSingleFreeFormBlock =\n\t\t\tparseResult.length === 1 &&\n\t\t\tparseResult[ 0 ].name === 'core/freeform';\n\t\tif ( ! isSingleFreeFormBlock ) {\n\t\t\treturn parseResult;\n\t\t}\n\t}\n\n\t// An array of HTML strings and block objects. The blocks replace matched\n\t// shortcodes.\n\tconst pieces = shortcodeConverter( HTML );\n\tconst blockContentSchema = getBlockContentSchema();\n\n\treturn pieces\n\t\t.map( ( piece ) => {\n\t\t\t// Already a block from shortcode.\n\t\t\tif ( typeof piece !== 'string' ) {\n\t\t\t\treturn piece;\n\t\t\t}\n\n\t\t\t// These filters are essential for some blocks to be able to transform\n\t\t\t// from raw HTML. These filters move around some content or add\n\t\t\t// additional tags, they do not remove any content.\n\t\t\tconst filters = [\n\t\t\t\t// Needed to adjust invalid lists.\n\t\t\t\tlistReducer,\n\t\t\t\t// Needed to create more and nextpage blocks.\n\t\t\t\tspecialCommentConverter,\n\t\t\t\t// Needed to create media blocks.\n\t\t\t\tfigureContentReducer,\n\t\t\t\t// Needed to create the quote block, which cannot handle text\n\t\t\t\t// without wrapper paragraphs.\n\t\t\t\tblockquoteNormaliser( { raw: true } ),\n\t\t\t];\n\n\t\t\tpiece = deepFilterHTML( piece, filters, blockContentSchema );\n\t\t\tpiece = normaliseBlocks( piece, { raw: true } );\n\n\t\t\treturn htmlToBlocks( piece, rawHandler );\n\t\t} )\n\t\t.flat()\n\t\t.filter( Boolean );\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AACvB,iBAAyC;AAKzC,4BAA6B;AAC7B,oBAAkB;AAClB,8BAA4B;AAC5B,uCAAoC;AACpC,0BAAwB;AACxB,mCAAiC;AACjC,oCAAiC;AACjC,iCAA+B;AAC/B,mBAAsD;AAEtD,2BAA6B;AAEtB,SAAS,mCAAoC,SAAU;AAC7D,wBAAAA,SAAY,sCAAsC;AAAA,IACjD,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AACF,aAAO,qCAA0B,OAAQ;AAC1C;AAUO,SAAS,WAAY,EAAE,OAAO,GAAG,GAAI;AAE3C,MAAK,KAAK,QAAS,UAAW,MAAM,IAAK;AACxC,UAAM,kBAAc,cAAAC,SAAO,IAAK;AAChC,UAAM,wBACL,YAAY,WAAW,KACvB,YAAa,CAAE,EAAE,SAAS;AAC3B,QAAK,CAAE,uBAAwB;AAC9B,aAAO;AAAA,IACR;AAAA,EACD;AAIA,QAAM,aAAS,2BAAAC,SAAoB,IAAK;AACxC,QAAM,yBAAqB,oCAAsB;AAEjD,SAAO,OACL,IAAK,CAAE,UAAW;AAElB,QAAK,OAAO,UAAU,UAAW;AAChC,aAAO;AAAA,IACR;AAKA,UAAM,UAAU;AAAA;AAAA,MAEf,oBAAAC;AAAA;AAAA,MAEA,iCAAAC;AAAA;AAAA,MAEA,8BAAAC;AAAA;AAAA;AAAA,UAGA,6BAAAC,SAAsB,EAAE,KAAK,KAAK,CAAE;AAAA,IACrC;AAEA,gBAAQ,6BAAgB,OAAO,SAAS,kBAAmB;AAC3D,gBAAQ,wBAAAC,SAAiB,OAAO,EAAE,KAAK,KAAK,CAAE;AAE9C,eAAO,oCAAc,OAAO,UAAW;AAAA,EACxC,CAAE,EACD,KAAK,EACL,OAAQ,OAAQ;AACnB;",
"names": ["deprecated", "parse", "shortcodeConverter", "listReducer", "specialCommentConverter", "figureContentReducer", "blockquoteNormaliser", "normaliseBlocks"]
}