Making WordPress.org

Changeset 10067


Ignore:
Timestamp:
07/13/2020 09:44:22 PM (5 years ago)
Author:
coffee2code
Message:

Developer theme: Fix the fix for the parsing bug regarding 'code' tags misapplied during parsing.

Bug became evident in text containing multiple code tags where some 'code' tags were correctly present in the original text.

Props ocean90, coffee2code.
Fixes #5304.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/formatting.php

    r9770 r10067  
    3939        add_filter( 'devhub-format-description', array( __CLASS__, 'autolink_references' ) );
    4040        add_filter( 'devhub-format-description', array( __CLASS__, 'fix_param_hash_formatting' ), 9 );
    41         add_filter( 'devhub-format-description', array( __CLASS__, 'fix_param_description_parsedown_bug' ) );
    4241        add_filter( 'devhub-format-description', array( __CLASS__, 'fix_param_description_html_as_code' ) );
     42
     43        add_filter( 'devhub-format-hash-param-description', array( __CLASS__, 'autolink_references' ) );
     44        add_filter( 'devhub-format-hash-param-description', array( __CLASS__, 'fix_param_description_parsedown_bug' ) );
    4345
    4446        add_filter( 'devhub-function-return-type', array( __CLASS__, 'autolink_references' ) );
     
    229231                    sanitize_title_with_dashes( html_entity_decode( $link ) );
    230232        }
    231        
     233
    232234        if ( $url ) {
    233235            $link = self::generate_link( $url, $link );
     
    265267        return sprintf( '<a%s>%s</a>', $attributes, esc_html( $text ) );
    266268    }
    267    
     269
    268270    /**
    269271     * Fixes unintended markup generated by Markdown during parsing.
     
    511513            list( $wordtype, $type, $name, $description ) = explode( ' ', $part . '    ', 4 ); // extra spaces ensure we'll always have 4 items.
    512514            $description = trim( $description );
    513             $description = self::autolink_references( $description );
     515
     516            $description = apply_filters( 'devhub-format-hash-param-description', $description );
    514517
    515518            $skip_closing_li = false;
     
    582585            '/`(.+)<code>/'        => '<code>$1</code>',
    583586            '/<\/code>(.+)`/'      => ' <code>$1</code>',
    584             '/<\/code>(.+)<code>/' => ' <code>$1</code>',
    585587        );
    586588
     589        // Determine if code tags look inverted.
     590        $first_start = strpos( $text, '<code>' );
     591        $first_end = strpos( $text, '</code>' );
     592        if ( false !== $first_start && false !== $first_end && $first_end < $first_start ) {
     593            $fixes[ '~</code>(.+)<code>~U' ] = ' <code>$1</code>';
     594        }
     595
    587596        $matched = true;
    588597
    589598        foreach ( $fixes as $regex => $replace ) {
    590             if ( $matched && $matched = preg_match( $regex, $text, $match ) ) {
    591                 $text = preg_replace( $regex, $replace, $text );
    592             }
     599            $text = preg_replace( $regex, $replace, $text );
    593600        }
    594601
Note: See TracChangeset for help on using the changeset viewer.