/** * Callback for gist shortcode. * * @since 2.8.0 * * @param array $atts Attributes found in the shortcode. * @param string $content Content enclosed by the shortcode. * * @return string The gist HTML. */ function github_gist_shortcode($atts, $content = '') { if (empty($atts[0]) && empty($content)) { return '<!-- Missing Gist ID -->'; } $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 '<!-- Invalid Gist ID -->'; } wp_enqueue_script('jetpack-gist-embed', plugins_url('js/gist.js', __FILE__), 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 = '<style>.gist table { margin-bottom: 0; }</style><div class="gist-oembed" data-gist="' . esc_attr($id) . '"></div>'; if (isset($_POST['type']) && 'embed' === $_POST['type'] && isset($_POST['action']) && 'parse-embed' === $_POST['action']) { return github_gist_simple_embed($id); } return $return; }
function github_gist_shortcode($atts, $content = '') { if (empty($atts[0]) && empty($content)) { return '<!-- Missing Gist ID -->'; } $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 '<!-- Invalid Gist ID -->'; } if (!empty($atts['file'])) { $file = '?file=' . urlencode($atts['file']); } else { $file = ''; } $embed_url = "{$id}.json" . $file; // inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables $return = '<style>.gist table { margin-bottom: 0; }</style>' . '<div class="gist-oembed" data-gist="' . esc_attr($embed_url) . '"></div>'; if (isset($_POST['type']) && 'embed' === $_POST['type'] && isset($_POST['action']) && 'parse-embed' === $_POST['action']) { return github_gist_simple_embed($id, $file); } return $return; }