'; } $id = ( ! empty( $content ) ) ? $content : $atts[0]; // Parse a URL if ( ! is_numeric( $id ) ) { $id = preg_replace( '#https?://gist.github.com/([a-zA-Z0-9]+)#', '$1', $id ); } if ( ! $id ) { return ''; } wp_enqueue_script( 'jetpack-gist-embed', Jetpack::get_file_url_for_environment( '_inc/build/shortcodes/js/gist.min.js', 'modules/shortcodes/js/gist.js' ), array( 'jquery' ), false, true ); if ( false !== strpos( $id, '#file-' ) ) { // URL points to a specific file in the gist $id = str_replace( '#file-', '.json?file=', $id ); $id = preg_replace( '/\-(?!.*\-)/', '.', $id ); } else { $file = ( ! empty( $atts['file'] ) ) ? '?file=' . urlencode( $atts['file'] ) : ''; // URL points to the entire gist $id .= ".json$file"; } // inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables $return = '
'; if ( isset( $_POST[ 'type' ] ) && 'embed' === $_POST[ 'type' ] && isset( $_POST[ 'action' ] ) && 'parse-embed' === $_POST['action'] ) { return github_gist_simple_embed( $id ); } return $return; } /** * Use script tag to load shortcode in editor. * * @since 3.9.0 * * @param string $id The ID of the gist. * * @return string */ function github_gist_simple_embed( $id ) { $id = str_replace( 'json', 'js', $id ); return ''; }