Changeset 12627
- Timestamp:
- 06/07/2023 02:27:06 AM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/trac/pr/functions.php
r12169 r12627 337 337 * 338 338 * This: 339 * - Strips standard boilerplate text 339 * - Strips standard boilerplate texts 340 340 * - format_github_content_for_trac_comment(); 341 341 * … … 348 348 // Remove the final line if it matches the specific boilerplate format. 349 349 $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 ); 350 353 351 354 return format_github_content_for_trac_comment( $desc ); … … 360 363 * - Converts image embeds 361 364 * - Converts links 365 * - Converts tables 362 366 * 363 367 * @param string $desc. … … 365 369 */ 366 370 function format_github_content_for_trac_comment( $desc ) { 371 // Standardise on \n. 372 $desc = str_replace( "\r\n", "\n", $desc ); 373 367 374 // Remove HTML comments 368 375 $desc = preg_replace( '#<!--.+?-->#s', '', $desc ); … … 391 398 $desc = preg_replace( '#\[(.+?)\]\((.+?)\)#', '[$2 $1]', $desc ); 392 399 393 // Convert Tables. This doesn't convert GitHub table headers to Trac headers.400 // Convert Tables. 394 401 $desc = preg_replace_callback( 395 402 '#^[|].+[|]$#m', … … 397 404 // Headers such as `| --- |---|` 398 405 if ( preg_match( '#^[- |]+$#', $m[0] ) ) { 399 return ' || ||'; // Empty row.406 return '~~~TABLEHEADER~~~'; 400 407 } 401 408 … … 405 412 $desc 406 413 ); 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 ); 407 429 408 430 return trim( $desc );
Note: See TracChangeset
for help on using the changeset viewer.