Code Duplication    Length = 63-64 lines in 2 locations

Michelf/Markdown.php 1 location

@@ 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

Michelf/MarkdownExtra.php 1 location

@@ 790-853 (lines=64) @@
787
	 * @param  string $text
788
	 * @return string
789
	 */
790
	protected function doAnchors($text) {
791
		if ($this->in_anchor) {
792
			return $text;
793
		}
794
		$this->in_anchor = true;
795
796
		// First, handle reference-style links: [link text] [id]
797
		$text = preg_replace_callback('{
798
			(					# wrap whole match in $1
799
			  \[
800
				(' . $this->nested_brackets_re . ')	# link text = $2
801
			  \]
802
803
			  [ ]?				# one optional space
804
			  (?:\n[ ]*)?		# one optional newline followed by spaces
805
806
			  \[
807
				(.*?)		# id = $3
808
			  \]
809
			)
810
			}xs',
811
			array($this, '_doAnchors_reference_callback'), $text);
812
813
		// Next, inline-style links: [link text](url "optional title")
814
		$text = preg_replace_callback('{
815
			(				# wrap whole match in $1
816
			  \[
817
				(' . $this->nested_brackets_re . ')	# link text = $2
818
			  \]
819
			  \(			# literal paren
820
				[ \n]*
821
				(?:
822
					<(.+?)>	# href = $3
823
				|
824
					(' . $this->nested_url_parenthesis_re . ')	# href = $4
825
				)
826
				[ \n]*
827
				(			# $5
828
				  ([\'"])	# quote char = $6
829
				  (.*?)		# Title = $7
830
				  \6		# matching quote
831
				  [ \n]*	# ignore any spaces/tabs between closing quote and )
832
				)?			# title is optional
833
			  \)
834
			  (?:[ ]? ' . $this->id_class_attr_catch_re . ' )?	 # $8 = id/class attributes
835
			)
836
			}xs',
837
			array($this, '_doAnchors_inline_callback'), $text);
838
839
		// Last, handle reference-style shortcuts: [link text]
840
		// These must come last in case you've also got [link text][1]
841
		// or [link text](/foo)
842
		$text = preg_replace_callback('{
843
			(					# wrap whole match in $1
844
			  \[
845
				([^\[\]]+)		# link text = $2; can\'t contain [ or ]
846
			  \]
847
			)
848
			}xs',
849
			array($this, '_doAnchors_reference_callback'), $text);
850
851
		$this->in_anchor = false;
852
		return $text;
853
	}
854
855
	/**
856
	 * Callback for reference anchors