Changeset 3788 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
- Timestamp:
- 08/09/2016 06:06:41 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
r3754 r3788 45 45 */ 46 46 require __DIR__ . '/inc/user-content.php'; 47 48 /** 49 * User-submitted content preview. 50 */ 51 require __DIR__ . '/inc/user-content-preview.php'; 47 52 48 53 /** … … 112 117 113 118 add_filter( 'document_title_separator', __NAMESPACE__ . '\\theme_title_separator', 10, 2 ); 119 120 add_filter( 'syntaxhighlighter_htmlresult', __NAMESPACE__ . '\\syntaxhighlighter_htmlresult' ); 114 121 } 115 122 … … 277 284 } 278 285 } 286 287 /** 288 * If a syntax highlighted code block exceeds a given number of lines, wrap the 289 * markup with other markup to trigger the code expansion/collapse JS handling 290 * already implemented for the code reference. 291 * 292 * @param string $text The pending result of the syntax highlighting. 293 * @return string 294 */ 295 function syntaxhighlighter_htmlresult( $text ) { 296 297 // is_admin() is true in front end AJAX requests. 298 if ( is_admin() && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { 299 return $text; 300 } 301 302 $new_text = ''; 303 // Collapse is handled for >10 lines. But just go ahead and show the full 304 // code if that is just barely being exceeded (no one wants to expand to 305 // see one or two more lines). 306 $lines_to_show = 12; 307 $do_collapse = ( substr_count( $text, "\n" ) - 1 ) > $lines_to_show; 308 309 if ( $do_collapse ) { 310 $new_text .= '<section class="source-content">'; 311 $new_text .= '<div class="source-code-container">'; 312 } 313 314 $new_text .= $text; 315 316 if ( $do_collapse ) { 317 $new_text .= '</div>'; 318 $new_text .= '<p class="source-code-links"><span>'; 319 $new_text .= '<a href="#" class="show-complete-source">' . __( 'Expand full source code', 'wporg' ) . '</a>'; 320 $new_text .= '<a href="#" class="less-complete-source">' . __( 'Collapse full source code', 'wporg' ) . '</a>'; 321 $new_text .= '</span></p>'; 322 $new_text .= '</section>'; 323 } 324 325 return $new_text; 326 }
Note: See TracChangeset
for help on using the changeset viewer.