Plugin Directory

Changeset 1998464

Timestamp:
12/20/2018 01:58:12 AM (6 years ago)
Author:
Viper007Bond
Message:

https://github.com/Viper007Bond/syntaxhighlighter/releases/tag/v3.4.2

Location:
syntaxhighlighter/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • syntaxhighlighter/trunk

    • Property svn:ignore
      •  

        old new  
        1313assets
        1414src
         15
         16
         17
         18
  • syntaxhighlighter/trunk/readme.txt

    r1988517 r1998464  
    3737
    3838== ChangeLog ==
     39
     40
     41
     42
    3943
    4044= Version 3.4.1 =
  • syntaxhighlighter/trunk/syntaxhighlighter.php

    r1988517 r1998464  
    55Plugin Name:  SyntaxHighlighter Evolved
    66Plugin URI:   http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/
    7 Version:      3.4.1
     7Version:      3.4.
    88Description:  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.
    99Author:       Alex Mills (Viper007Bond)
     
    2222class SyntaxHighlighter {
    2323    // All of these variables are private. Filters are provided for things that can be modified.
    24     var $pluginver            = '3.4.1';  // Plugin version
     24    var $pluginver            = '3.4.';  // Plugin version
    2525    var $agshver              = false;    // Alex Gorbatchev's SyntaxHighlighter version (dynamically set below due to v2 vs v3)
    2626    var $shfolder             = false;    // Controls what subfolder to load SyntaxHighlighter from (v2 or v3)
     
    345345     * For the shortcode, brushes are activated by `shortcode_callback()`, but that won't detect brushes that were
    346346     * used in blocks. For that, we need to extract the data from the block's attributes.
     347
     348
     349
     350
     351
     352
    347353     */
    348354    function enable_brushes_used_in_blocks( $content ) {
     
    356362
    357363        // 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;
    360369        }
    361370
     
    369378
    370379        foreach ( $blocks as $block ) {
    371             if ( empty( $block['blockName'] ) || 'syntaxhighlighter/code' !== $block['blockName'] ) {
     380            if ( empty( $block['blockName'] ) ) {
    372381                continue;
    373382            }
    374383
    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                }
    379442            }
    380443        }
Note: See TracChangeset for help on using the changeset viewer.