| @@ 661-723 (lines=63) @@ | ||
| 658 | * @param string $text |
|
| 659 | * @return string |
|
| 660 | */ |
|
| 661 | protected function doAnchors($text) { |
|
| 662 | if ($this->in_anchor) { |
|
| 663 | return $text; |
|
| 664 | } |
|
| 665 | $this->in_anchor = true; |
|
| 666 | ||
| 667 | // First, handle reference-style links: [link text] [id] |
|
| 668 | $text = preg_replace_callback('{ |
|
| 669 | ( # wrap whole match in $1 |
|
| 670 | \[ |
|
| 671 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 672 | \] |
|
| 673 | ||
| 674 | [ ]? # one optional space |
|
| 675 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
| 676 | ||
| 677 | \[ |
|
| 678 | (.*?) # id = $3 |
|
| 679 | \] |
|
| 680 | ) |
|
| 681 | }xs', |
|
| 682 | array($this, '_doAnchors_reference_callback'), $text); |
|
| 683 | ||
| 684 | // Next, inline-style links: [link text](url "optional title") |
|
| 685 | $text = preg_replace_callback('{ |
|
| 686 | ( # wrap whole match in $1 |
|
| 687 | \[ |
|
| 688 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 689 | \] |
|
| 690 | \( # literal paren |
|
| 691 | [ \n]* |
|
| 692 | (?: |
|
| 693 | <(.+?)> # href = $3 |
|
| 694 | | |
|
| 695 | ('.$this->nested_url_parenthesis_re.') # href = $4 |
|
| 696 | ) |
|
| 697 | [ \n]* |
|
| 698 | ( # $5 |
|
| 699 | ([\'"]) # quote char = $6 |
|
| 700 | (.*?) # Title = $7 |
|
| 701 | \6 # matching quote |
|
| 702 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
|
| 703 | )? # title is optional |
|
| 704 | \) |
|
| 705 | ) |
|
| 706 | }xs', |
|
| 707 | array($this, '_doAnchors_inline_callback'), $text); |
|
| 708 | ||
| 709 | // Last, handle reference-style shortcuts: [link text] |
|
| 710 | // These must come last in case you've also got [link text][1] |
|
| 711 | // or [link text](/foo) |
|
| 712 | $text = preg_replace_callback('{ |
|
| 713 | ( # wrap whole match in $1 |
|
| 714 | \[ |
|
| 715 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
|
| 716 | \] |
|
| 717 | ) |
|
| 718 | }xs', |
|
| 719 | array($this, '_doAnchors_reference_callback'), $text); |
|
| 720 | ||
| 721 | $this->in_anchor = false; |
|
| 722 | return $text; |
|
| 723 | } |
|
| 724 | ||
| 725 | /** |
|
| 726 | * Callback method to parse referenced anchors |
|
| @@ 805-868 (lines=64) @@ | ||
| 802 | * @param string $text |
|
| 803 | * @return string |
|
| 804 | */ |
|
| 805 | protected function doAnchors($text) { |
|
| 806 | if ($this->in_anchor) { |
|
| 807 | return $text; |
|
| 808 | } |
|
| 809 | $this->in_anchor = true; |
|
| 810 | ||
| 811 | // First, handle reference-style links: [link text] [id] |
|
| 812 | $text = preg_replace_callback('{ |
|
| 813 | ( # wrap whole match in $1 |
|
| 814 | \[ |
|
| 815 | (' . $this->nested_brackets_re . ') # link text = $2 |
|
| 816 | \] |
|
| 817 | ||
| 818 | [ ]? # one optional space |
|
| 819 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
| 820 | ||
| 821 | \[ |
|
| 822 | (.*?) # id = $3 |
|
| 823 | \] |
|
| 824 | ) |
|
| 825 | }xs', |
|
| 826 | array($this, '_doAnchors_reference_callback'), $text); |
|
| 827 | ||
| 828 | // Next, inline-style links: [link text](url "optional title") |
|
| 829 | $text = preg_replace_callback('{ |
|
| 830 | ( # wrap whole match in $1 |
|
| 831 | \[ |
|
| 832 | (' . $this->nested_brackets_re . ') # link text = $2 |
|
| 833 | \] |
|
| 834 | \( # literal paren |
|
| 835 | [ \n]* |
|
| 836 | (?: |
|
| 837 | <(.+?)> # href = $3 |
|
| 838 | | |
|
| 839 | (' . $this->nested_url_parenthesis_re . ') # href = $4 |
|
| 840 | ) |
|
| 841 | [ \n]* |
|
| 842 | ( # $5 |
|
| 843 | ([\'"]) # quote char = $6 |
|
| 844 | (.*?) # Title = $7 |
|
| 845 | \6 # matching quote |
|
| 846 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
|
| 847 | )? # title is optional |
|
| 848 | \) |
|
| 849 | (?:[ ]? ' . $this->id_class_attr_catch_re . ' )? # $8 = id/class attributes |
|
| 850 | ) |
|
| 851 | }xs', |
|
| 852 | array($this, '_doAnchors_inline_callback'), $text); |
|
| 853 | ||
| 854 | // Last, handle reference-style shortcuts: [link text] |
|
| 855 | // These must come last in case you've also got [link text][1] |
|
| 856 | // or [link text](/foo) |
|
| 857 | $text = preg_replace_callback('{ |
|
| 858 | ( # wrap whole match in $1 |
|
| 859 | \[ |
|
| 860 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
|
| 861 | \] |
|
| 862 | ) |
|
| 863 | }xs', |
|
| 864 | array($this, '_doAnchors_reference_callback'), $text); |
|
| 865 | ||
| 866 | $this->in_anchor = false; |
|
| 867 | return $text; |
|
| 868 | } |
|
| 869 | ||
| 870 | /** |
|
| 871 | * Callback for reference anchors |
|