Making WordPress.org

Changeset 12627


Ignore:
Timestamp:
06/07/2023 02:27:06 AM (22 months ago)
Author:
dd32
Message:

Trac: PRs: Try to convert tables, again?

See #6555

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/functions.php

    r12169 r12627  
    337337 *
    338338 * This:
    339  *  - Strips standard boilerplate text
     339 *  - Strips standard boilerplate texts
    340340 *  - format_github_content_for_trac_comment();
    341341 *
     
    348348    // Remove the final line if it matches the specific boilerplate format.
    349349    $desc = preg_replace( "#---\r?\n\*\*.+\*\*$#", '', $desc );
     350
     351    // Or the 'Trac Ticket: ...' reference.
     352    $desc = preg_replace( '!^(Trac )?Ticket:\s*https://[a-z0-9.#/:]+$!im', '', $desc );
    350353
    351354    return format_github_content_for_trac_comment( $desc );
     
    360363 *  - Converts image embeds
    361364 *  - Converts links
     365 *  - Converts tables
    362366 *
    363367 * @param string $desc.
     
    365369 */
    366370function format_github_content_for_trac_comment( $desc ) {
     371    // Standardise on \n.
     372    $desc = str_replace( "\r\n", "\n", $desc );
     373
    367374    // Remove HTML comments
    368375    $desc = preg_replace( '#<!--.+?-->#s', '', $desc );
     
    391398    $desc = preg_replace( '#\[(.+?)\]\((.+?)\)#', '[$2 $1]', $desc );
    392399
    393     // Convert Tables. This doesn't convert GitHub table headers to Trac headers.
     400    // Convert Tables.
    394401    $desc = preg_replace_callback(
    395402        '#^[|].+[|]$#m',
     
    397404            // Headers such as `| --- |---|`
    398405            if ( preg_match( '#^[- |]+$#', $m[0] ) ) {
    399                 return '|| ||'; // Empty row.
     406                return '~~~TABLEHEADER~~~';
    400407            }
    401408
     
    405412        $desc
    406413    );
     414    // Markup the headers now. Trac table headers are in the format of ||= Header =||
     415    $desc = preg_replace_callback(
     416        "#^([|].+[|])\n(~~~TABLEHEADER~~~)#m",
     417        function( $m ) {
     418            $headers = $m[1];
     419            $headers = preg_replace( '#[|]{2}([^|=])#', '||=$1', $headers );
     420            $headers = preg_replace( '#([^|=])[|]{2}#', '$1=||', $headers );
     421
     422            return $headers;
     423        },
     424        $desc
     425    );
     426
     427    // It shouldn't exist at this point, but if it does, replace it back with it's original content.
     428    $desc = str_replace( '~~~TABLEHEADER~~~', '|| ||', $desc );
    407429
    408430    return trim( $desc );
Note: See TracChangeset for help on using the changeset viewer.