Code Duplication    Length = 15-39 lines in 5 locations

3pp/php-markdown/Michelf/Markdown.php 5 locations

@@ 182-215 (lines=34) @@
179
		);
180
181
182
	protected function stripLinkDefinitions($text) {
183
	#
184
	# Strips link definitions from text, stores the URLs and titles in
185
	# hash references.
186
	#
187
		$less_than_tab = $this->tab_width - 1;
188
189
		# Link defs are in the form: ^[id]: url "optional title"
190
		$text = preg_replace_callback('{
191
							^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?:	# id = $1
192
							  [ ]*
193
							  \n?				# maybe *one* newline
194
							  [ ]*
195
							(?:
196
							  <(.+?)>			# url = $2
197
							|
198
							  (\S+?)			# url = $3
199
							)
200
							  [ ]*
201
							  \n?				# maybe one newline
202
							  [ ]*
203
							(?:
204
								(?<=\s)			# lookbehind for whitespace
205
								["(]
206
								(.*?)			# title = $4
207
								[")]
208
								[ ]*
209
							)?	# title is optional
210
							(?:\n+|\Z)
211
			}xm',
212
			array(&$this, '_stripLinkDefinitions_callback'),
213
			$text);
214
		return $text;
215
	}
216
	protected function _stripLinkDefinitions_callback($matches) {
217
		$link_id = strtolower($matches[1]);
218
		$url = $matches[2] == '' ? $matches[3] : $matches[2];
@@ 1688-1722 (lines=35) @@
1685
	}
1686
1687
1688
	protected function stripLinkDefinitions($text) {
1689
	#
1690
	# Strips link definitions from text, stores the URLs and titles in
1691
	# hash references.
1692
	#
1693
		$less_than_tab = $this->tab_width - 1;
1694
1695
		# Link defs are in the form: ^[id]: url "optional title"
1696
		$text = preg_replace_callback('{
1697
							^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?:	# id = $1
1698
							  [ ]*
1699
							  \n?				# maybe *one* newline
1700
							  [ ]*
1701
							(?:
1702
							  <(.+?)>			# url = $2
1703
							|
1704
							  (\S+?)			# url = $3
1705
							)
1706
							  [ ]*
1707
							  \n?				# maybe one newline
1708
							  [ ]*
1709
							(?:
1710
								(?<=\s)			# lookbehind for whitespace
1711
								["(]
1712
								(.*?)			# title = $4
1713
								[")]
1714
								[ ]*
1715
							)?	# title is optional
1716
					(?:[ ]* '.$this->id_class_attr_catch_re.' )?  # $5 = extra id & class attr
1717
							(?:\n+|\Z)
1718
			}xm',
1719
			array(&$this, '_stripLinkDefinitions_callback'),
1720
			$text);
1721
		return $text;
1722
	}
1723
	protected function _stripLinkDefinitions_callback($matches) {
1724
		$link_id = strtolower($matches[1]);
1725
		$url = $matches[2] == '' ? $matches[3] : $matches[2];
@@ 2769-2807 (lines=39) @@
2766
	}
2767
2768
2769
	protected function doFencedCodeBlocks($text) {
2770
	#
2771
	# Adding the fenced code block syntax to regular Markdown:
2772
	#
2773
	# ~~~
2774
	# Code block
2775
	# ~~~
2776
	#
2777
		$less_than_tab = $this->tab_width;
2778
		
2779
		$text = preg_replace_callback('{
2780
				(?:\n|\A)
2781
				# 1: Opening marker
2782
				(
2783
					(?:~{3,}|`{3,}) # 3 or more tildes/backticks.
2784
				)
2785
				[ ]*
2786
				(?:
2787
					\.?([-_:a-zA-Z0-9]+) # 2: standalone class name
2788
				|
2789
					'.$this->id_class_attr_catch_re.' # 3: Extra attributes
2790
				)?
2791
				[ ]* \n # Whitespace and newline following marker.
2792
				
2793
				# 4: Content
2794
				(
2795
					(?>
2796
						(?!\1 [ ]* \n)	# Not a closing marker.
2797
						.*\n+
2798
					)+
2799
				)
2800
				
2801
				# Closing marker.
2802
				\1 [ ]* (?= \n )
2803
			}xm',
2804
			array(&$this, '_doFencedCodeBlocks_callback'), $text);
2805
2806
		return $text;
2807
	}
2808
	protected function _doFencedCodeBlocks_callback($matches) {
2809
		$classname =& $matches[2];
2810
		$attrs     =& $matches[3];
@@ 2894-2920 (lines=27) @@
2891
	
2892
	### Footnotes
2893
	
2894
	protected function stripFootnotes($text) {
2895
	#
2896
	# Strips link definitions from text, stores the URLs and titles in
2897
	# hash references.
2898
	#
2899
		$less_than_tab = $this->tab_width - 1;
2900
2901
		# Link defs are in the form: [^id]: url "optional title"
2902
		$text = preg_replace_callback('{
2903
			^[ ]{0,'.$less_than_tab.'}\[\^(.+?)\][ ]?:	# note_id = $1
2904
			  [ ]*
2905
			  \n?					# maybe *one* newline
2906
			(						# text = $2 (no blank lines allowed)
2907
				(?:					
2908
					.+				# actual text
2909
				|
2910
					\n				# newlines but 
2911
					(?!\[\^.+?\]:\s)# negative lookahead for footnote marker.
2912
					(?!\n+[ ]{0,3}\S)# ensure line is not blank and followed 
2913
									# by non-indented content
2914
				)*
2915
			)		
2916
			}xm',
2917
			array(&$this, '_stripFootnotes_callback'),
2918
			$text);
2919
		return $text;
2920
	}
2921
	protected function _stripFootnotes_callback($matches) {
2922
		$note_id = $this->fn_id_prefix . $matches[1];
2923
		$this->footnotes[$note_id] = $this->outdent($matches[2]);
@@ 3049-3063 (lines=15) @@
3046
	
3047
	### Abbreviations ###
3048
	
3049
	protected function stripAbbreviations($text) {
3050
	#
3051
	# Strips abbreviations from text, stores titles in hash references.
3052
	#
3053
		$less_than_tab = $this->tab_width - 1;
3054
3055
		# Link defs are in the form: [id]*: url "optional title"
3056
		$text = preg_replace_callback('{
3057
			^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?:	# abbr_id = $1
3058
			(.*)					# text = $2 (no blank lines allowed)	
3059
			}xm',
3060
			array(&$this, '_stripAbbreviations_callback'),
3061
			$text);
3062
		return $text;
3063
	}
3064
	protected function _stripAbbreviations_callback($matches) {
3065
		$abbr_word = $matches[1];
3066
		$abbr_desc = $matches[2];