@wordpress/blocks
Version:
Block API for WordPress.
8 lines (7 loc) • 3.25 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/api/raw-handling/phrasing-content-reducer.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { wrap, replaceTag } from '@wordpress/dom';\n\nexport default function phrasingContentReducer( node, doc ) {\n\t// In jsdom-jscore, 'node.style' can be null.\n\t// TODO: Explore fixing this by patching jsdom-jscore.\n\tif ( node.nodeName === 'SPAN' && node.style ) {\n\t\tconst {\n\t\t\tfontWeight,\n\t\t\tfontStyle,\n\t\t\ttextDecorationLine,\n\t\t\ttextDecoration,\n\t\t\tverticalAlign,\n\t\t} = node.style;\n\n\t\tif ( fontWeight === 'bold' || fontWeight === '700' ) {\n\t\t\twrap( doc.createElement( 'strong' ), node );\n\t\t}\n\n\t\tif ( fontStyle === 'italic' ) {\n\t\t\twrap( doc.createElement( 'em' ), node );\n\t\t}\n\n\t\t// Some DOM implementations (Safari, JSDom) don't support\n\t\t// style.textDecorationLine, so we check style.textDecoration as a\n\t\t// fallback.\n\t\tif (\n\t\t\ttextDecorationLine === 'line-through' ||\n\t\t\ttextDecoration.includes( 'line-through' )\n\t\t) {\n\t\t\twrap( doc.createElement( 's' ), node );\n\t\t}\n\n\t\tif ( verticalAlign === 'super' ) {\n\t\t\twrap( doc.createElement( 'sup' ), node );\n\t\t} else if ( verticalAlign === 'sub' ) {\n\t\t\twrap( doc.createElement( 'sub' ), node );\n\t\t}\n\t} else if ( node.nodeName === 'B' ) {\n\t\tnode = replaceTag( node, 'strong' );\n\t} else if ( node.nodeName === 'I' ) {\n\t\tnode = replaceTag( node, 'em' );\n\t} else if ( node.nodeName === 'A' ) {\n\t\t// In jsdom-jscore, 'node.target' can be null.\n\t\t// TODO: Explore fixing this by patching jsdom-jscore.\n\t\tif ( node.target && node.target.toLowerCase() === '_blank' ) {\n\t\t\tnode.rel = 'noreferrer noopener';\n\t\t} else {\n\t\t\tnode.removeAttribute( 'target' );\n\t\t\tnode.removeAttribute( 'rel' );\n\t\t}\n\n\t\t// Saves anchor elements name attribute as id\n\t\tif ( node.name && ! node.id ) {\n\t\t\tnode.id = node.name;\n\t\t}\n\n\t\t// Keeps id only if there is an internal link pointing to it\n\t\tif (\n\t\t\tnode.id &&\n\t\t\t! node.ownerDocument.querySelector( `[href=\"#${ node.id }\"]` )\n\t\t) {\n\t\t\tnode.removeAttribute( 'id' );\n\t\t}\n\t}\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAiC;AAElB,SAAR,uBAAyC,MAAM,KAAM;AAG3D,MAAK,KAAK,aAAa,UAAU,KAAK,OAAQ;AAC7C,UAAM;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD,IAAI,KAAK;AAET,QAAK,eAAe,UAAU,eAAe,OAAQ;AACpD,2BAAM,IAAI,cAAe,QAAS,GAAG,IAAK;AAAA,IAC3C;AAEA,QAAK,cAAc,UAAW;AAC7B,2BAAM,IAAI,cAAe,IAAK,GAAG,IAAK;AAAA,IACvC;AAKA,QACC,uBAAuB,kBACvB,eAAe,SAAU,cAAe,GACvC;AACD,2BAAM,IAAI,cAAe,GAAI,GAAG,IAAK;AAAA,IACtC;AAEA,QAAK,kBAAkB,SAAU;AAChC,2BAAM,IAAI,cAAe,KAAM,GAAG,IAAK;AAAA,IACxC,WAAY,kBAAkB,OAAQ;AACrC,2BAAM,IAAI,cAAe,KAAM,GAAG,IAAK;AAAA,IACxC;AAAA,EACD,WAAY,KAAK,aAAa,KAAM;AACnC,eAAO,uBAAY,MAAM,QAAS;AAAA,EACnC,WAAY,KAAK,aAAa,KAAM;AACnC,eAAO,uBAAY,MAAM,IAAK;AAAA,EAC/B,WAAY,KAAK,aAAa,KAAM;AAGnC,QAAK,KAAK,UAAU,KAAK,OAAO,YAAY,MAAM,UAAW;AAC5D,WAAK,MAAM;AAAA,IACZ,OAAO;AACN,WAA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