Making WordPress.org

Changeset 4573


Ignore:
Timestamp:
12/23/2016 04:25:57 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: When parsing sections such as FAQ, only use ** bolded lines ** as headings when standard headings (## heading, = Heading =) aren't present.

See https://wordpress.slack.com/archives/pluginreview/p1482436390000554
See #2336

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php

    r4571 r4573  
    561561            $lines = explode( "\n", $lines );
    562562        }
     563        $trimmed_lines = array_map( 'trim', $lines );
    563564
    564565        /*
    565566         * The heading style being matched in the block. Can be 'heading' or 'bold'.
    566          * Standard Markdown headings (## .. and == ... ==) are matched if they exist.
    567          * Full line bolding is otherwise used as the heading style.
    568          * This will match sections based on which ever style is encountered in a block of text first.
     567         * Standard Markdown headings (## .. and == ... ==) are used, but if none are present.
     568         * full line bolding will be used as a heading style.
    569569         */
    570         $heading_style = false; // 'heading' or 'bold'
    571 
    572         while ( ( $line = array_shift( $lines ) ) !== null ) {
    573             $trimmed = trim( $line );
     570        $heading_style = 'bold'; // 'heading' or 'bold'
     571        foreach ( $trimmed_lines as $trimmed ) {
     572            if ( $trimmed[0] == '#' || $trimmed[0] == '=' ) {
     573                $heading_style = 'heading';
     574                break;
     575            }
     576        }
     577
     578        $line_count = count( $lines );
     579        for ( $i = 0; $i < $line_count; $i++ ) {
     580            $line = &$lines[ $i ];
     581            $trimmed = &$trimmed_lines[ $i ];
    574582            if ( ! $trimmed ) {
    575583                $value .= "\n";
     
    578586
    579587            $is_heading = false;
    580             if (
    581                 ( ! $heading_style || 'heading' == $heading_style ) &&
    582                 ( $trimmed[0] == '#' || $trimmed[0] == '=' )
    583                 ) {
    584                 $heading_style = 'heading';
     588            if ( 'heading' == $heading_style && ( $trimmed[0] == '#' || $trimmed[0] == '=' ) ) {
    585589                $is_heading = true;
    586             } elseif (
    587                 ( ! $heading_style || 'bold' == $heading_style ) &&
    588                 ( substr( $trimmed, 0, 2 ) == '**' && substr( $trimmed, -2 ) == '**' )
    589                 ) {
    590                 $heading_style = 'bold';
     590            } elseif ( 'bold' == $heading_style && ( substr( $trimmed, 0, 2 ) == '**' && substr( $trimmed, -2 ) == '**' ) ) {
    591591                $is_heading = true;
    592592            }
Note: See TracChangeset for help on using the changeset viewer.