@@ 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 |
@@ 816-879 (lines=64) @@ | ||
813 | * @param string $text |
|
814 | * @return string |
|
815 | */ |
|
816 | protected function doAnchors($text) { |
|
817 | if ($this->in_anchor) { |
|
818 | return $text; |
|
819 | } |
|
820 | $this->in_anchor = true; |
|
821 | ||
822 | // First, handle reference-style links: [link text] [id] |
|
823 | $text = preg_replace_callback('{ |
|
824 | ( # wrap whole match in $1 |
|
825 | \[ |
|
826 | (' . $this->nested_brackets_re . ') # link text = $2 |
|
827 | \] |
|
828 | ||
829 | [ ]? # one optional space |
|
830 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
831 | ||
832 | \[ |
|
833 | (.*?) # id = $3 |
|
834 | \] |
|
835 | ) |
|
836 | }xs', |
|
837 | array($this, '_doAnchors_reference_callback'), $text); |
|
838 | ||
839 | // Next, inline-style links: [link text](url "optional title") |
|
840 | $text = preg_replace_callback('{ |
|
841 | ( # wrap whole match in $1 |
|
842 | \[ |
|
843 | (' . $this->nested_brackets_re . ') # link text = $2 |
|
844 | \] |
|
845 | \( # literal paren |
|
846 | [ \n]* |
|
847 | (?: |
|
848 | <(.+?)> # href = $3 |
|
849 | | |
|
850 | (' . $this->nested_url_parenthesis_re . ') # href = $4 |
|
851 | ) |
|
852 | [ \n]* |
|
853 | ( # $5 |
|
854 | ([\'"]) # quote char = $6 |
|
855 | (.*?) # Title = $7 |
|
856 | \6 # matching quote |
|
857 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
|
858 | )? # title is optional |
|
859 | \) |
|
860 | (?:[ ]? ' . $this->id_class_attr_catch_re . ' )? # $8 = id/class attributes |
|
861 | ) |
|
862 | }xs', |
|
863 | array($this, '_doAnchors_inline_callback'), $text); |
|
864 | ||
865 | // Last, handle reference-style shortcuts: [link text] |
|
866 | // These must come last in case you've also got [link text][1] |
|
867 | // or [link text](/foo) |
|
868 | $text = preg_replace_callback('{ |
|
869 | ( # wrap whole match in $1 |
|
870 | \[ |
|
871 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
|
872 | \] |
|
873 | ) |
|
874 | }xs', |
|
875 | array($this, '_doAnchors_reference_callback'), $text); |
|
876 | ||
877 | $this->in_anchor = false; |
|
878 | return $text; |
|
879 | } |
|
880 | ||
881 | /** |
|
882 | * Callback for reference anchors |