-
Notifications
You must be signed in to change notification settings - Fork 800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gist Shortcode: Remove jQuery Dependency #16700
Gist Shortcode: Remove jQuery Dependency #16700
Conversation
Thank you for the great PR description! When this PR is ready for review, please apply the E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-16700 Scheduled Jetpack release: September 1, 2020. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests appear to be failing right now. Could you take a look?
https://github.com/Automattic/jetpack/pull/16700/checks?check_run_id=944382555
I think that I've fixed the tests now! :) |
Thank you. I'm a bit worried of us removing a CSS class that may be used by some to customize the look of the embed on their site. Maybe we should keep it around? |
It may be worth testing to see if this also happens to fix #10161. 🤞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests well for me. I would have a few suggestions though, see below.
Here is a diff incorporating the different changes I suggested. Let me know what you think about it!
diff --git a/modules/shortcodes/gist.php b/modules/shortcodes/gist.php
index ad51b5119..c8403257c 100644
--- a/modules/shortcodes/gist.php
+++ b/modules/shortcodes/gist.php
@@ -201,22 +201,29 @@ function github_gist_shortcode( $atts, $content = '' ) {
}
// URL points to the entire gist, including the file name if there was one.
- $id = ( ! empty( $file ) ? $id . '?file=' . $file : $id );
+ $id = ( ! empty( $file ) ? $id . '?file=' . $file : $id );
$return = false;
- $request = wp_remote_get( "https://gist.github.com/" . esc_attr( $id ) );
+ $request = wp_remote_get( esc_url_raw( 'https://gist.github.com/' . esc_attr( $id ) ) );
$request_code = wp_remote_retrieve_response_code( $request );
if ( 200 === $request_code ) {
$request_body = wp_remote_retrieve_body( $request );
$request_data = json_decode( $request_body );
- wp_enqueue_style( 'jetpack-gist-styling', $request_data->stylesheet );
+ wp_enqueue_style( 'jetpack-gist-styling', esc_url( $request_data->stylesheet ), array(), JETPACK__VERSION );
- $gist = substr_replace( $request_data->div, sprintf( 'style="tab-size: %1$s" ', absint( $tab_size ) ), 5, 0 );
+ // Add inline styles for the tab style in the opening div of the gist.
+ $gist = preg_replace(
+ '#(\<div\s)+(id=\"gist[0-9]+\")+(\sclass=\"gist\"\>)?#',
+ sprintf( '$1style="tab-size: %1$s" $2$3', absint( $tab_size ) ),
+ $request_data->div,
+ 1
+ );
- // inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables.
+ // Add inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables.
$return = sprintf( '<style>.gist table { margin-bottom: 0; }</style>%1$s', $gist );
+
}
if (
Thank you - I've updated the PR to use that approach instead! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, but I'd appreciate an additional pair of eyes on this as I've contributed code to that PR.
r212543-wpcom |
Part of #16409
Changes proposed in this Pull Request:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Nope.
Testing instructions:
Try using a Gist shortcode with different ts parameters. For example:
Verify that the Gist appears with the additional styling, and the
tab-size
style is also inserted.Proposed changelog entry for your changes: