@wordpress/block-library
Version:
Block library for the WordPress editor.
8 lines (7 loc) • 2.27 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/code/utils.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { pipe } from '@wordpress/compose';\n\n/**\n * Escapes ampersands, shortcodes, and links.\n *\n * @param {string} content The content of a code block.\n * @return {string} The given content with some characters escaped.\n */\nexport function escape( content ) {\n\treturn pipe(\n\t\tescapeOpeningSquareBrackets,\n\t\tescapeProtocolInIsolatedUrls\n\t)( content || '' );\n}\n\n/**\n * Returns the given content with all opening shortcode characters converted\n * into their HTML entity counterpart (i.e. [ => [). For instance, a\n * shortcode like [embed] becomes [embed]\n *\n * This function replicates the escaping of HTML tags, where a tag like\n * <strong> becomes <strong>.\n *\n * @param {string} content The content of a code block.\n * @return {string} The given content with its opening shortcode characters\n * converted into their HTML entity counterpart\n * (i.e. [ => [)\n */\nfunction escapeOpeningSquareBrackets( content ) {\n\treturn content.replace( /\\[/g, '[' );\n}\n\n/**\n * Converts the first two forward slashes of any isolated URL into their HTML\n * counterparts (i.e. // => //). For instance, https://youtube.com/watch?x\n * becomes https://youtube.com/watch?x.\n *\n * An isolated URL is a URL that sits in its own line, surrounded only by spacing\n * characters.\n *\n * See https://github.com/WordPress/wordpress-develop/blob/5.1.1/src/wp-includes/class-wp-embed.php#L403\n *\n * @param {string} content The content of a code block.\n * @return {string} The given content with its ampersands converted into\n * their HTML entity counterpart (i.e. & => &)\n */\nfunction escapeProtocolInIsolatedUrls( content ) {\n\treturn content.replace(\n\t\t/^(\\s*https?:)\\/\\/([^\\s<>\"]+\\s*)$/m,\n\t\t'$1//$2'\n\t);\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAqB;AAQd,SAAS,OAAQ,SAAU;AACjC,aAAO;AAAA,IACN;AAAA,IACA;AAAA,EACD,EAAG,WAAW,EAAG;AAClB;AAeA,SAAS,4BAA6B,SAAU;AAC/C,SAAO,QAAQ,QAAS,OAAO,OAAQ;AACxC;AAgBA,SAAS,6BAA8B,SAAU;AAChD,SAAO,QAAQ;AAAA,IACd;AAAA,IACA;AAAA,EACD;AACD;",
"names": []
}