| @@ 687-756 (lines=70) @@ | ||
| 684 | } |
|
| 685 | ||
| 686 | ||
| 687 | function doAnchors($text) { |
|
| 688 | # |
|
| 689 | # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 690 | # |
|
| 691 | if ($this->in_anchor) return $text; |
|
| 692 | $this->in_anchor = true; |
|
| 693 | ||
| 694 | # |
|
| 695 | # First, handle reference-style links: [link text] [id] |
|
| 696 | # |
|
| 697 | $text = preg_replace_callback('{ |
|
| 698 | ( # wrap whole match in $1 |
|
| 699 | \[ |
|
| 700 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 701 | \] |
|
| 702 | ||
| 703 | [ ]? # one optional space |
|
| 704 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
| 705 | ||
| 706 | \[ |
|
| 707 | (.*?) # id = $3 |
|
| 708 | \] |
|
| 709 | ) |
|
| 710 | }xs', |
|
| 711 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 712 | ||
| 713 | # |
|
| 714 | # Next, inline-style links: [link text](url "optional title") |
|
| 715 | # |
|
| 716 | $text = preg_replace_callback('{ |
|
| 717 | ( # wrap whole match in $1 |
|
| 718 | \[ |
|
| 719 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 720 | \] |
|
| 721 | \( # literal paren |
|
| 722 | [ \n]* |
|
| 723 | (?: |
|
| 724 | <(.+?)> # href = $3 |
|
| 725 | | |
|
| 726 | ('.$this->nested_url_parenthesis_re.') # href = $4 |
|
| 727 | ) |
|
| 728 | [ \n]* |
|
| 729 | ( # $5 |
|
| 730 | ([\'"]) # quote char = $6 |
|
| 731 | (.*?) # Title = $7 |
|
| 732 | \6 # matching quote |
|
| 733 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
|
| 734 | )? # title is optional |
|
| 735 | \) |
|
| 736 | ) |
|
| 737 | }xs', |
|
| 738 | array(&$this, '_doAnchors_inline_callback'), $text); |
|
| 739 | ||
| 740 | # |
|
| 741 | # Last, handle reference-style shortcuts: [link text] |
|
| 742 | # These must come last in case you've also got [link text][1] |
|
| 743 | # or [link text](/foo) |
|
| 744 | # |
|
| 745 | $text = preg_replace_callback('{ |
|
| 746 | ( # wrap whole match in $1 |
|
| 747 | \[ |
|
| 748 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
|
| 749 | \] |
|
| 750 | ) |
|
| 751 | }xs', |
|
| 752 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 753 | ||
| 754 | $this->in_anchor = false; |
|
| 755 | return $text; |
|
| 756 | } |
|
| 757 | function _doAnchors_reference_callback($matches) { |
|
| 758 | $whole_match = $matches[1]; |
|
| 759 | $link_text = $matches[2]; |
|
| @@ 2370-2440 (lines=71) @@ | ||
| 2367 | } |
|
| 2368 | ||
| 2369 | ||
| 2370 | function doAnchors($text) { |
|
| 2371 | # |
|
| 2372 | # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 2373 | # |
|
| 2374 | if ($this->in_anchor) return $text; |
|
| 2375 | $this->in_anchor = true; |
|
| 2376 | ||
| 2377 | # |
|
| 2378 | # First, handle reference-style links: [link text] [id] |
|
| 2379 | # |
|
| 2380 | $text = preg_replace_callback('{ |
|
| 2381 | ( # wrap whole match in $1 |
|
| 2382 | \[ |
|
| 2383 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 2384 | \] |
|
| 2385 | ||
| 2386 | [ ]? # one optional space |
|
| 2387 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
| 2388 | ||
| 2389 | \[ |
|
| 2390 | (.*?) # id = $3 |
|
| 2391 | \] |
|
| 2392 | ) |
|
| 2393 | }xs', |
|
| 2394 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 2395 | ||
| 2396 | # |
|
| 2397 | # Next, inline-style links: [link text](url "optional title") |
|
| 2398 | # |
|
| 2399 | $text = preg_replace_callback('{ |
|
| 2400 | ( # wrap whole match in $1 |
|
| 2401 | \[ |
|
| 2402 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 2403 | \] |
|
| 2404 | \( # literal paren |
|
| 2405 | [ \n]* |
|
| 2406 | (?: |
|
| 2407 | <(.+?)> # href = $3 |
|
| 2408 | | |
|
| 2409 | ('.$this->nested_url_parenthesis_re.') # href = $4 |
|
| 2410 | ) |
|
| 2411 | [ \n]* |
|
| 2412 | ( # $5 |
|
| 2413 | ([\'"]) # quote char = $6 |
|
| 2414 | (.*?) # Title = $7 |
|
| 2415 | \6 # matching quote |
|
| 2416 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
|
| 2417 | )? # title is optional |
|
| 2418 | \) |
|
| 2419 | (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes |
|
| 2420 | ) |
|
| 2421 | }xs', |
|
| 2422 | array(&$this, '_doAnchors_inline_callback'), $text); |
|
| 2423 | ||
| 2424 | # |
|
| 2425 | # Last, handle reference-style shortcuts: [link text] |
|
| 2426 | # These must come last in case you've also got [link text][1] |
|
| 2427 | # or [link text](/foo) |
|
| 2428 | # |
|
| 2429 | $text = preg_replace_callback('{ |
|
| 2430 | ( # wrap whole match in $1 |
|
| 2431 | \[ |
|
| 2432 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
|
| 2433 | \] |
|
| 2434 | ) |
|
| 2435 | }xs', |
|
| 2436 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 2437 | ||
| 2438 | $this->in_anchor = false; |
|
| 2439 | return $text; |
|
| 2440 | } |
|
| 2441 | function _doAnchors_reference_callback($matches) { |
|
| 2442 | $whole_match = $matches[1]; |
|
| 2443 | $link_text = $matches[2]; |
|