Ticket #1810: 1810.2.diff
File 1810.2.diff, 3.7 KB (added by , 9 years ago) |
---|
-
readme/class-parser.php
67 67 public $screenshots = array(); 68 68 69 69 /** 70 * @var array 71 */ 72 public $faq = array(); 73 74 /** 70 75 * These are the readme sections that we expect. 71 76 * 72 77 * @var array … … 286 291 287 292 // Parse out the Upgrade Notice section into it's own data. 288 293 if ( isset( $this->sections['upgrade_notice'] ) ) { 289 $lines = explode( "\n", $this->sections['upgrade_notice'] ); 290 $version = null; 291 $current = ''; 292 while ( ( $line = array_shift( $lines ) ) !== null ) { 293 $trimmed = trim( $line ); 294 if ( empty( $trimmed ) ) { 295 continue; 296 } 297 298 if ( '=' === $trimmed[0] || '#' === $trimmed[0] ) { 299 if ( ! empty( $current ) ) { 300 $this->upgrade_notice[ $version ] = $this->sanitize_text( trim( $current ) ); 301 } 302 303 $current = ''; 304 $version = trim( $line, "#= \t" ); 305 continue; 306 } 307 308 $current .= $line . "\n"; 309 } 310 if ( ! empty( $version ) && ! empty( $current ) ) { 311 $this->upgrade_notice[ $version ] = $this->sanitize_text( trim( $current ) ); 312 } 294 $this->upgrade_notice = $this->parse_section( $this->sections['upgrade_notice'] ); 313 295 unset( $this->sections['upgrade_notice'] ); 314 296 } 315 297 298 // Display FAQs as a definition list. 299 if ( isset( $this->sections['faq'] ) ) { 300 $this->faq = $this->parse_section( $this->sections['faq'] ); 301 $this->sections['faq'] = ''; 302 } 303 316 304 // Markdownify! 317 305 $this->sections = array_map( array( $this, 'parse_markdown' ), $this->sections ); 318 306 $this->upgrade_notice = array_map( array( $this, 'parse_markdown' ), $this->upgrade_notice ); 307 $this->faq = array_map( array( $this, 'parse_markdown' ), $this->faq ); 319 308 320 309 // Sanitize and trim the short_description to match requirements. 321 310 $this->short_description = $this->sanitize_text( $this->short_description ); … … 334 323 unset( $this->sections['screenshots'] ); 335 324 } 336 325 326 if ( ! empty( $this->faq ) ) { 327 $plain_text = false; 328 329 foreach( $this->faq as $question => $answer ) { 330 if ( empty( $question ) ) { 331 $this->sections['faq'] = $answer; 332 $plain_text = true; 333 break; 334 } 335 336 $this->sections['faq'] .= "<dt>{$question}</dt>\n<dd>{$answer}</dd>\n"; 337 } 338 339 if ( ! $plain_text ) { 340 $this->sections['faq'] = "<dl>{$this->sections['faq']}</dl>\n"; 341 } 342 343 unset( $this->faq ); 344 } 345 337 346 // Filter the HTML. 338 347 $this->sections = array_map( array( $this, 'filter_text' ), $this->sections ); 339 348 … … 413 422 'strong' => true, 414 423 'ul' => true, 415 424 'ol' => true, 425 'dl' => true, 426 'dt' => true, 427 'dd' => true, 416 428 'li' => true, 417 429 'h3' => true, 418 430 'h4' => true, … … 494 506 return $stable_tag; 495 507 } 496 508 509 protected function parse_section( $lines ) { 510 $key = $value = ''; 511 $return = array(); 512 513 if ( ! is_array( $lines ) ) { 514 $lines = explode( "\n", $lines ); 515 } 516 517 while ( ( $line = array_shift( $lines ) ) !== null ) { 518 $trimmed = trim( $line ); 519 if ( empty( $trimmed ) ) { 520 continue; 521 } 522 523 if ( in_array( $trimmed[0], array( '=', '#', '*' ), true ) ) { 524 if ( ! empty( $value ) ) { 525 $return[ $key ] = $this->sanitize_text( trim( $value ) ); 526 } 527 528 $value = ''; 529 $key = trim( $line, "=#* \t" ); 530 continue; 531 } 532 533 $value .= $line . "\n"; 534 } 535 536 if ( ! empty( $key ) || ! empty( $value ) ) { 537 $return[ $key ] = $this->sanitize_text( trim( $value ) ); 538 } 539 540 return $return; 541 } 542 497 543 /** 498 544 * @param string $text 499 545 * @return string