@@ 528-597 (lines=70) @@ | ||
525 | } |
|
526 | ||
527 | ||
528 | protected function doAnchors($text) { |
|
529 | # |
|
530 | # Turn Markdown link shortcuts into XHTML <a> tags. |
|
531 | # |
|
532 | if ($this->in_anchor) return $text; |
|
533 | $this->in_anchor = true; |
|
534 | ||
535 | # |
|
536 | # First, handle reference-style links: [link text] [id] |
|
537 | # |
|
538 | $text = preg_replace_callback('{ |
|
539 | ( # wrap whole match in $1 |
|
540 | \[ |
|
541 | ('.$this->nested_brackets_re.') # link text = $2 |
|
542 | \] |
|
543 | ||
544 | [ ]? # one optional space |
|
545 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
546 | ||
547 | \[ |
|
548 | (.*?) # id = $3 |
|
549 | \] |
|
550 | ) |
|
551 | }xs', |
|
552 | array($this, '_doAnchors_reference_callback'), $text); |
|
553 | ||
554 | # |
|
555 | # Next, inline-style links: [link text](url "optional title") |
|
556 | # |
|
557 | $text = preg_replace_callback('{ |
|
558 | ( # wrap whole match in $1 |
|
559 | \[ |
|
560 | ('.$this->nested_brackets_re.') # link text = $2 |
|
561 | \] |
|
562 | \( # literal paren |
|
563 | [ \n]* |
|
564 | (?: |
|
565 | <(.+?)> # href = $3 |
|
566 | | |
|
567 | ('.$this->nested_url_parenthesis_re.') # href = $4 |
|
568 | ) |
|
569 | [ \n]* |
|
570 | ( # $5 |
|
571 | ([\'"]) # quote char = $6 |
|
572 | (.*?) # Title = $7 |
|
573 | \6 # matching quote |
|
574 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
|
575 | )? # title is optional |
|
576 | \) |
|
577 | ) |
|
578 | }xs', |
|
579 | array($this, '_doAnchors_inline_callback'), $text); |
|
580 | ||
581 | # |
|
582 | # Last, handle reference-style shortcuts: [link text] |
|
583 | # These must come last in case you've also got [link text][1] |
|
584 | # or [link text](/foo) |
|
585 | # |
|
586 | $text = preg_replace_callback('{ |
|
587 | ( # wrap whole match in $1 |
|
588 | \[ |
|
589 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
|
590 | \] |
|
591 | ) |
|
592 | }xs', |
|
593 | array($this, '_doAnchors_reference_callback'), $text); |
|
594 | ||
595 | $this->in_anchor = false; |
|
596 | return $text; |
|
597 | } |
|
598 | protected function _doAnchors_reference_callback($matches) { |
|
599 | $whole_match = $matches[1]; |
|
600 | $link_text = $matches[2]; |
@@ 704-774 (lines=71) @@ | ||
701 | } |
|
702 | ||
703 | ||
704 | protected function doAnchors($text) { |
|
705 | # |
|
706 | # Turn Markdown link shortcuts into XHTML <a> tags. |
|
707 | # |
|
708 | if ($this->in_anchor) return $text; |
|
709 | $this->in_anchor = true; |
|
710 | ||
711 | # |
|
712 | # First, handle reference-style links: [link text] [id] |
|
713 | # |
|
714 | $text = preg_replace_callback('{ |
|
715 | ( # wrap whole match in $1 |
|
716 | \[ |
|
717 | ('.$this->nested_brackets_re.') # link text = $2 |
|
718 | \] |
|
719 | ||
720 | [ ]? # one optional space |
|
721 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
722 | ||
723 | \[ |
|
724 | (.*?) # id = $3 |
|
725 | \] |
|
726 | ) |
|
727 | }xs', |
|
728 | array($this, '_doAnchors_reference_callback'), $text); |
|
729 | ||
730 | # |
|
731 | # Next, inline-style links: [link text](url "optional title") |
|
732 | # |
|
733 | $text = preg_replace_callback('{ |
|
734 | ( # wrap whole match in $1 |
|
735 | \[ |
|
736 | ('.$this->nested_brackets_re.') # link text = $2 |
|
737 | \] |
|
738 | \( # literal paren |
|
739 | [ \n]* |
|
740 | (?: |
|
741 | <(.+?)> # href = $3 |
|
742 | | |
|
743 | ('.$this->nested_url_parenthesis_re.') # href = $4 |
|
744 | ) |
|
745 | [ \n]* |
|
746 | ( # $5 |
|
747 | ([\'"]) # quote char = $6 |
|
748 | (.*?) # Title = $7 |
|
749 | \6 # matching quote |
|
750 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
|
751 | )? # title is optional |
|
752 | \) |
|
753 | (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes |
|
754 | ) |
|
755 | }xs', |
|
756 | array($this, '_doAnchors_inline_callback'), $text); |
|
757 | ||
758 | # |
|
759 | # Last, handle reference-style shortcuts: [link text] |
|
760 | # These must come last in case you've also got [link text][1] |
|
761 | # or [link text](/foo) |
|
762 | # |
|
763 | $text = preg_replace_callback('{ |
|
764 | ( # wrap whole match in $1 |
|
765 | \[ |
|
766 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
|
767 | \] |
|
768 | ) |
|
769 | }xs', |
|
770 | array($this, '_doAnchors_reference_callback'), $text); |
|
771 | ||
772 | $this->in_anchor = false; |
|
773 | return $text; |
|
774 | } |
|
775 | protected function _doAnchors_reference_callback($matches) { |
|
776 | $whole_match = $matches[1]; |
|
777 | $link_text = $matches[2]; |