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

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