| @@ 899-928 (lines=30) @@ | ||
| 896 | } |
|
| 897 | ||
| 898 | ||
| 899 | function doHeaders($text) { |
|
| 900 | # Setext-style headers: |
|
| 901 | # Header 1 |
|
| 902 | # ======== |
|
| 903 | # |
|
| 904 | # Header 2 |
|
| 905 | # -------- |
|
| 906 | # |
|
| 907 | $text = preg_replace_callback('{ ^(.+?)[ ]*\n(=+|-+)[ ]*\n+ }mx', |
|
| 908 | array(&$this, '_doHeaders_callback_setext'), $text); |
|
| 909 | ||
| 910 | # atx-style headers: |
|
| 911 | # # Header 1 |
|
| 912 | # ## Header 2 |
|
| 913 | # ## Header 2 with closing hashes ## |
|
| 914 | # ... |
|
| 915 | # ###### Header 6 |
|
| 916 | # |
|
| 917 | $text = preg_replace_callback('{ |
|
| 918 | ^(\#{1,6}) # $1 = string of #\'s |
|
| 919 | [ ]* |
|
| 920 | (.+?) # $2 = Header text |
|
| 921 | [ ]* |
|
| 922 | \#* # optional closing #\'s (not counted) |
|
| 923 | \n+ |
|
| 924 | }xm', |
|
| 925 | array(&$this, '_doHeaders_callback_atx'), $text); |
|
| 926 | ||
| 927 | return $text; |
|
| 928 | } |
|
| 929 | function _doHeaders_callback_setext($matches) { |
|
| 930 | # Terrible hack to check we haven't found an empty list item. |
|
| 931 | if ($matches[2] == '-' && preg_match('{^-(?: |$)}', $matches[1])) |
|
| @@ 2223-2262 (lines=40) @@ | ||
| 2220 | } |
|
| 2221 | ||
| 2222 | ||
| 2223 | function doHeaders($text) { |
|
| 2224 | # |
|
| 2225 | # Redefined to add id attribute support. |
|
| 2226 | # |
|
| 2227 | # Setext-style headers: |
|
| 2228 | # Header 1 {#header1} |
|
| 2229 | # ======== |
|
| 2230 | # |
|
| 2231 | # Header 2 {#header2} |
|
| 2232 | # -------- |
|
| 2233 | # |
|
| 2234 | $text = preg_replace_callback( |
|
| 2235 | '{ |
|
| 2236 | (^.+?) # $1: Header text |
|
| 2237 | (?:[ ]+\{\#([-_:a-zA-Z0-9]+)\})? # $2: Id attribute |
|
| 2238 | [ ]*\n(=+|-+)[ ]*\n+ # $3: Header footer |
|
| 2239 | }mx', |
|
| 2240 | array(&$this, '_doHeaders_callback_setext'), $text); |
|
| 2241 | ||
| 2242 | # atx-style headers: |
|
| 2243 | # # Header 1 {#header1} |
|
| 2244 | # ## Header 2 {#header2} |
|
| 2245 | # ## Header 2 with closing hashes ## {#header3} |
|
| 2246 | # ... |
|
| 2247 | # ###### Header 6 {#header2} |
|
| 2248 | # |
|
| 2249 | $text = preg_replace_callback('{ |
|
| 2250 | ^(\#{1,6}) # $1 = string of #\'s |
|
| 2251 | [ ]* |
|
| 2252 | (.+?) # $2 = Header text |
|
| 2253 | [ ]* |
|
| 2254 | \#* # optional closing #\'s (not counted) |
|
| 2255 | (?:[ ]+\{\#([-_:a-zA-Z0-9]+)\})? # id attribute |
|
| 2256 | [ ]* |
|
| 2257 | \n+ |
|
| 2258 | }xm', |
|
| 2259 | array(&$this, '_doHeaders_callback_atx'), $text); |
|
| 2260 | ||
| 2261 | return $text; |
|
| 2262 | } |
|
| 2263 | function _doHeaders_attr($attr) { |
|
| 2264 | if (empty($attr)) return ""; |
|
| 2265 | return " id=\"$attr\""; |
|