| @@ 534-603 (lines=70) @@ | ||
| 531 | } |
|
| 532 | ||
| 533 | ||
| 534 | function doAnchors($text) { |
|
| 535 | # |
|
| 536 | # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 537 | # |
|
| 538 | if ($this->in_anchor) return $text; |
|
| 539 | $this->in_anchor = true; |
|
| 540 | ||
| 541 | # |
|
| 542 | # First, handle reference-style links: [link text] [id] |
|
| 543 | # |
|
| 544 | $text = preg_replace_callback('{ |
|
| 545 | ( # wrap whole match in $1 |
|
| 546 | \[ |
|
| 547 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 548 | \] |
|
| 549 | ||
| 550 | [ ]? # one optional space |
|
| 551 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
| 552 | ||
| 553 | \[ |
|
| 554 | (.*?) # id = $3 |
|
| 555 | \] |
|
| 556 | ) |
|
| 557 | }xs', |
|
| 558 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 559 | ||
| 560 | # |
|
| 561 | # Next, inline-style links: [link text](url "optional title") |
|
| 562 | # |
|
| 563 | $text = preg_replace_callback('{ |
|
| 564 | ( # wrap whole match in $1 |
|
| 565 | \[ |
|
| 566 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 567 | \] |
|
| 568 | \( # literal paren |
|
| 569 | [ \n]* |
|
| 570 | (?: |
|
| 571 | <(.+?)> # href = $3 |
|
| 572 | | |
|
| 573 | ('.$this->nested_url_parenthesis_re.') # href = $4 |
|
| 574 | ) |
|
| 575 | [ \n]* |
|
| 576 | ( # $5 |
|
| 577 | ([\'"]) # quote char = $6 |
|
| 578 | (.*?) # Title = $7 |
|
| 579 | \6 # matching quote |
|
| 580 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
|
| 581 | )? # title is optional |
|
| 582 | \) |
|
| 583 | ) |
|
| 584 | }xs', |
|
| 585 | array(&$this, '_doAnchors_inline_callback'), $text); |
|
| 586 | ||
| 587 | # |
|
| 588 | # Last, handle reference-style shortcuts: [link text] |
|
| 589 | # These must come last in case you've also got [link text][1] |
|
| 590 | # or [link text](/foo) |
|
| 591 | # |
|
| 592 | $text = preg_replace_callback('{ |
|
| 593 | ( # wrap whole match in $1 |
|
| 594 | \[ |
|
| 595 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
|
| 596 | \] |
|
| 597 | ) |
|
| 598 | }xs', |
|
| 599 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 600 | ||
| 601 | $this->in_anchor = false; |
|
| 602 | return $text; |
|
| 603 | } |
|
| 604 | function _doAnchors_reference_callback($matches) { |
|
| 605 | $whole_match = $matches[1]; |
|
| 606 | $link_text = $matches[2]; |
|
| @@ 2217-2287 (lines=71) @@ | ||
| 2214 | } |
|
| 2215 | ||
| 2216 | ||
| 2217 | function doAnchors($text) { |
|
| 2218 | # |
|
| 2219 | # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 2220 | # |
|
| 2221 | if ($this->in_anchor) return $text; |
|
| 2222 | $this->in_anchor = true; |
|
| 2223 | ||
| 2224 | # |
|
| 2225 | # First, handle reference-style links: [link text] [id] |
|
| 2226 | # |
|
| 2227 | $text = preg_replace_callback('{ |
|
| 2228 | ( # wrap whole match in $1 |
|
| 2229 | \[ |
|
| 2230 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 2231 | \] |
|
| 2232 | ||
| 2233 | [ ]? # one optional space |
|
| 2234 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
| 2235 | ||
| 2236 | \[ |
|
| 2237 | (.*?) # id = $3 |
|
| 2238 | \] |
|
| 2239 | ) |
|
| 2240 | }xs', |
|
| 2241 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 2242 | ||
| 2243 | # |
|
| 2244 | # Next, inline-style links: [link text](url "optional title") |
|
| 2245 | # |
|
| 2246 | $text = preg_replace_callback('{ |
|
| 2247 | ( # wrap whole match in $1 |
|
| 2248 | \[ |
|
| 2249 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 2250 | \] |
|
| 2251 | \( # literal paren |
|
| 2252 | [ \n]* |
|
| 2253 | (?: |
|
| 2254 | <(.+?)> # href = $3 |
|
| 2255 | | |
|
| 2256 | ('.$this->nested_url_parenthesis_re.') # href = $4 |
|
| 2257 | ) |
|
| 2258 | [ \n]* |
|
| 2259 | ( # $5 |
|
| 2260 | ([\'"]) # quote char = $6 |
|
| 2261 | (.*?) # Title = $7 |
|
| 2262 | \6 # matching quote |
|
| 2263 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
|
| 2264 | )? # title is optional |
|
| 2265 | \) |
|
| 2266 | (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes |
|
| 2267 | ) |
|
| 2268 | }xs', |
|
| 2269 | array(&$this, '_doAnchors_inline_callback'), $text); |
|
| 2270 | ||
| 2271 | # |
|
| 2272 | # Last, handle reference-style shortcuts: [link text] |
|
| 2273 | # These must come last in case you've also got [link text][1] |
|
| 2274 | # or [link text](/foo) |
|
| 2275 | # |
|
| 2276 | $text = preg_replace_callback('{ |
|
| 2277 | ( # wrap whole match in $1 |
|
| 2278 | \[ |
|
| 2279 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
|
| 2280 | \] |
|
| 2281 | ) |
|
| 2282 | }xs', |
|
| 2283 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 2284 | ||
| 2285 | $this->in_anchor = false; |
|
| 2286 | return $text; |
|
| 2287 | } |
|
| 2288 | function _doAnchors_reference_callback($matches) { |
|
| 2289 | $whole_match = $matches[1]; |
|
| 2290 | $link_text = $matches[2]; |
|