Making WordPress.org


Ignore:
Timestamp:
01/26/2018 11:08:46 PM (9 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Fix an upstream Parsedown bug that introduces unbalanced 'code' tags.

The bug still exists upstream and this "fix" merely seeks to undo the damage. Can be removed if/when Parsedown is fixed (but shouldn't pose a problem if it isn't).

Props pbiron.
See https://github.com/erusev/parsedown/pull/515.
Fixes #2900.

File:
1 edited

Legend:

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

    r6382 r6448  
    3434                add_filter( 'the_excerpt', array( __CLASS__, 'autolink_references' ), 11 );
    3535                add_filter( 'the_content', array( __CLASS__, 'autolink_references' ), 11 );
     36
     37                add_filter( 'devhub-parameter-type', array( __CLASS__, 'autolink_references' ) );
     38
    3639                add_filter( 'devhub-format-description', array( __CLASS__, 'autolink_references' ) );
    37                 add_filter( 'devhub-parameter-type', array( __CLASS__, 'autolink_references' ) );
    38 
    3940                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' ) );
    4042
    4143                add_filter( 'devhub-function-return-type', array( __CLASS__, 'autolink_references' ) );
     
    507509        }
    508510
     511        /**
     512         * Fix Parsedown bug that introduces unbalanced 'code' tags.
     513         *
     514         * Under very specific criteria, a bug in the Parsedown package used by the
     515         * parser causes backtick-to-code-tag conversions to get mishandled, skipping
     516         * conversion of a backtick and causing subsequent backticks to be converted
     517         * incorrectly as an open or close 'code' tag (opposite of what it should've
     518         * been). See referenced tickets for more details.
     519         *
     520         * Intended to be a temporary fix until/unless Parsedown is fixed.
     521         *
     522         * @see https://meta.trac.wordpress.org/ticket/2900
     523         * @see https://github.com/erusev/parsedown/pull/515
     524         */
     525        public static function fix_param_description_parsedown_bug( $text ) {
     526                $fixes = array(
     527                        '/`(.+)<code>/'        => '<code>$1</code>',
     528                        '/<\/code>(.+)`/'      => ' <code>$1</code>',
     529                        '/<\/code>(.+)<code>/' => ' <code>$1</code>',
     530                );
     531
     532                $matched = true;
     533
     534                foreach ( $fixes as $regex => $replace ) {
     535                        if ( $matched && $matched = preg_match( $regex, $text, $match ) ) {
     536                                $text = preg_replace( $regex, $replace, $text );
     537                        }
     538                }
     539
     540                return $text;
     541        }
     542
    509543} // DevHub_Formatting
    510544
Note: See TracChangeset for help on using the changeset viewer.