| @@ 915-944 (lines=30) @@ | ||
| 912 | } |
|
| 913 | ||
| 914 | ||
| 915 | function doHeaders($text) { |
|
| 916 | # Setext-style headers: |
|
| 917 | # Header 1 |
|
| 918 | # ======== |
|
| 919 | # |
|
| 920 | # Header 2 |
|
| 921 | # -------- |
|
| 922 | # |
|
| 923 | $text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx', |
|
| 924 | array(&$this, '_doHeaders_callback_setext'), $text); |
|
| 925 | ||
| 926 | # atx-style headers: |
|
| 927 | # # Header 1 |
|
| 928 | # ## Header 2 |
|
| 929 | # ## Header 2 with closing hashes ## |
|
| 930 | # ... |
|
| 931 | # ###### Header 6 |
|
| 932 | # |
|
| 933 | $text = preg_replace_callback('{ |
|
| 934 | ^(\#{1,6}) # $1 = string of #\'s |
|
| 935 | [ ]* |
|
| 936 | (.+?) # $2 = Header text |
|
| 937 | [ ]* |
|
| 938 | \#* # optional closing #\'s (not counted) |
|
| 939 | \n+ |
|
| 940 | }xm', |
|
| 941 | array(&$this, '_doHeaders_callback_atx'), $text); |
|
| 942 | ||
| 943 | return $text; |
|
| 944 | } |
|
| 945 | function _doHeaders_callback_setext($matches) { |
|
| 946 | # Terrible hack to check we haven't found an empty list item. |
|
| 947 | if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) |
|
| @@ 563-602 (lines=40) @@ | ||
| 560 | } |
|
| 561 | ||
| 562 | ||
| 563 | function doHeaders($text) { |
|
| 564 | # |
|
| 565 | # Redefined to add id attribute support. |
|
| 566 | # |
|
| 567 | # Setext-style headers: |
|
| 568 | # Header 1 {#header1} |
|
| 569 | # ======== |
|
| 570 | # |
|
| 571 | # Header 2 {#header2} |
|
| 572 | # -------- |
|
| 573 | # |
|
| 574 | $text = preg_replace_callback( |
|
| 575 | '{ |
|
| 576 | (^.+?) # $1: Header text |
|
| 577 | (?:[ ]+\{\#([-_:a-zA-Z0-9]+)\})? # $2: Id attribute |
|
| 578 | [ ]*\n(=+|-+)[ ]*\n+ # $3: Header footer |
|
| 579 | }mx', |
|
| 580 | array(&$this, '_doHeaders_callback_setext'), $text); |
|
| 581 | ||
| 582 | # atx-style headers: |
|
| 583 | # # Header 1 {#header1} |
|
| 584 | # ## Header 2 {#header2} |
|
| 585 | # ## Header 2 with closing hashes ## {#header3} |
|
| 586 | # ... |
|
| 587 | # ###### Header 6 {#header2} |
|
| 588 | # |
|
| 589 | $text = preg_replace_callback('{ |
|
| 590 | ^(\#{1,6}) # $1 = string of #\'s |
|
| 591 | [ ]* |
|
| 592 | (.+?) # $2 = Header text |
|
| 593 | [ ]* |
|
| 594 | \#* # optional closing #\'s (not counted) |
|
| 595 | (?:[ ]+\{\#([-_:a-zA-Z0-9]+)\})? # id attribute |
|
| 596 | [ ]* |
|
| 597 | \n+ |
|
| 598 | }xm', |
|
| 599 | array(&$this, '_doHeaders_callback_atx'), $text); |
|
| 600 | ||
| 601 | return $text; |
|
| 602 | } |
|
| 603 | function _doHeaders_attr($attr) { |
|
| 604 | if (empty($attr)) return ""; |
|
| 605 | return " id=\"$attr\""; |
|