Changeset 1998464
- Timestamp:
- 12/20/2018 01:58:12 AM (6 years ago)
- Location:
- syntaxhighlighter/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
syntaxhighlighter/trunk
- Property svn:ignore
-
old new 13 13 assets 14 14 src 15 16 17 18
-
- Property svn:ignore
-
syntaxhighlighter/trunk/readme.txt
r1988517 r1998464 37 37 38 38 == ChangeLog == 39 40 41 42 39 43 40 44 = Version 3.4.1 = -
syntaxhighlighter/trunk/syntaxhighlighter.php
r1988517 r1998464 5 5 Plugin Name: SyntaxHighlighter Evolved 6 6 Plugin URI: http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/ 7 Version: 3.4. 17 Version: 3.4. 8 8 Description: Easily post syntax-highlighted code to your site without having to modify the code at all. Uses Alex Gorbatchev's <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter">SyntaxHighlighter</a>. <strong>TIP:</strong> Don't use the Visual editor if you don't want your code mangled. TinyMCE will "clean up" your HTML. 9 9 Author: Alex Mills (Viper007Bond) … … 22 22 class SyntaxHighlighter { 23 23 // All of these variables are private. Filters are provided for things that can be modified. 24 var $pluginver = '3.4. 1'; // Plugin version24 var $pluginver = '3.4.'; // Plugin version 25 25 var $agshver = false; // Alex Gorbatchev's SyntaxHighlighter version (dynamically set below due to v2 vs v3) 26 26 var $shfolder = false; // Controls what subfolder to load SyntaxHighlighter from (v2 or v3) … … 345 345 * For the shortcode, brushes are activated by `shortcode_callback()`, but that won't detect brushes that were 346 346 * used in blocks. For that, we need to extract the data from the block's attributes. 347 348 349 350 351 352 347 353 */ 348 354 function enable_brushes_used_in_blocks( $content ) { … … 356 362 357 363 // Lower overhead than a full parse. 358 if ( ! has_block( 'syntaxhighlighter/code', $content ) ) { 359 return $content; 364 if ( 365 ! has_block( 'syntaxhighlighter/code', $content ) 366 && ! has_block( 'core/block', $content ) // Reusable 367 ) { 368 //return $content; 360 369 } 361 370 … … 369 378 370 379 foreach ( $blocks as $block ) { 371 if ( empty( $block['blockName'] ) || 'syntaxhighlighter/code' !== $block['blockName']) {380 if ( empty( $block['blockName'] ) ) { 372 381 continue; 373 382 } 374 383 375 $language = ( ! empty( $block['attrs']['language'] ) ) ? $block['attrs']['language'] : 'plain'; 376 377 if ( in_array( $language, $this->brushes, true ) ) { 378 $this->usedbrushes[ $this->brushes[ $language ] ] = true; 384 switch ( $block['blockName'] ) { 385 // Normal block usage 386 case 'syntaxhighlighter/code': 387 $language = ( ! empty( $block['attrs']['language'] ) ) ? $block['attrs']['language'] : 'plain'; 388 389 if ( in_array( $language, $this->brushes, true ) ) { 390 $this->usedbrushes[ $this->brushes[ $language ] ] = true; 391 } 392 393 break; 394 395 // But the block could also be used inside of a reusable block 396 case 'core/block': 397 /** 398 * Rather than going down the block parsing rabbit hole of dynamic blocks, 399 * let's just hook in post-render and look for our HTML. 400 */ 401 add_filter( 'the_content', array( $this, 'enable_brushes_via_raw_html_parsing' ), 10 ); 402 403 break; 404 } 405 } 406 407 return $content; 408 } 409 410 /** 411 * Parses raw HTML looking for SyntaxHighlighter's <pre> tags and queues brushes 412 * for the languages used. 413 * 414 * This filter only runs when a reusable block is used in a post. 415 * It was easier to implement than loading the block, which then could 416 * have child blocks and so forth. Technically this means that we're 417 * parsing any regular SyntaxHighlighter blocks again, but oh well. :) 418 * 419 * @since 3.4.2 420 * 421 * @param string $content The post content. 422 * 423 * @return string Unmodified $content. 424 */ 425 public function enable_brushes_via_raw_html_parsing( $content ) { 426 if ( false === strpos( $content,'<pre class="wp-block-syntaxhighlighter-code' ) ) { 427 return $content; 428 } 429 430 preg_match_all( 431 '/<pre class="wp-block-syntaxhighlighter-code brush: ([^;]+);/', 432 $content, 433 $languages, 434 PREG_PATTERN_ORDER 435 ); 436 437 if ( is_array( $languages ) ) { 438 foreach ( $languages[1] as $language ) { 439 if ( in_array( $language, $this->brushes, true ) ) { 440 $this->usedbrushes[ $this->brushes[ $language ] ] = true; 441 } 379 442 } 380 443 }
Note: See TracChangeset
for help on using the changeset viewer.