Code Duplication    Length = 12-32 lines in 4 locations

Michelf/Markdown.php 1 location

@@ 280-311 (lines=32) @@
277
	 * @param  string $text
278
	 * @return string
279
	 */
280
	protected function stripLinkDefinitions($text) {
281
282
		$less_than_tab = $this->tab_width - 1;
283
284
		// Link defs are in the form: ^[id]: url "optional title"
285
		$text = preg_replace_callback('{
286
							^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?:	# id = $1
287
							  [ ]*
288
							  \n?				# maybe *one* newline
289
							  [ ]*
290
							(?:
291
							  <(.+?)>			# url = $2
292
							|
293
							  (\S+?)			# url = $3
294
							)
295
							  [ ]*
296
							  \n?				# maybe one newline
297
							  [ ]*
298
							(?:
299
								(?<=\s)			# lookbehind for whitespace
300
								["(]
301
								(.*?)			# title = $4
302
								[")]
303
								[ ]*
304
							)?	# title is optional
305
							(?:\n+|\Z)
306
			}xm',
307
			array($this, '_stripLinkDefinitions_callback'),
308
			$text
309
		);
310
		return $text;
311
	}
312
313
	/**
314
	 * The callback to strip link definitions

Michelf/MarkdownExtra.php 3 locations

@@ 293-323 (lines=31) @@
290
	 * @param  string $text
291
	 * @return string
292
	 */
293
	protected function stripLinkDefinitions($text) {
294
		$less_than_tab = $this->tab_width - 1;
295
296
		// Link defs are in the form: ^[id]: url "optional title"
297
		$text = preg_replace_callback('{
298
							^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?:	# id = $1
299
							  [ ]*
300
							  \n?				# maybe *one* newline
301
							  [ ]*
302
							(?:
303
							  <(.+?)>			# url = $2
304
							|
305
							  (\S+?)			# url = $3
306
							)
307
							  [ ]*
308
							  \n?				# maybe one newline
309
							  [ ]*
310
							(?:
311
								(?<=\s)			# lookbehind for whitespace
312
								["(]
313
								(.*?)			# title = $4
314
								[")]
315
								[ ]*
316
							)?	# title is optional
317
					(?:[ ]* '.$this->id_class_attr_catch_re.' )?  # $5 = extra id & class attr
318
							(?:\n+|\Z)
319
			}xm',
320
			array($this, '_stripLinkDefinitions_callback'),
321
			$text);
322
		return $text;
323
	}
324
325
	/**
326
	 * Strip link definition callback
@@ 1618-1640 (lines=23) @@
1615
	 * @param  string $text
1616
	 * @return string
1617
	 */
1618
	protected function stripFootnotes($text) {
1619
		$less_than_tab = $this->tab_width - 1;
1620
1621
		// Link defs are in the form: [^id]: url "optional title"
1622
		$text = preg_replace_callback('{
1623
			^[ ]{0,' . $less_than_tab . '}\[\^(.+?)\][ ]?:	# note_id = $1
1624
			  [ ]*
1625
			  \n?					# maybe *one* newline
1626
			(						# text = $2 (no blank lines allowed)
1627
				(?:
1628
					.+				# actual text
1629
				|
1630
					\n				# newlines but
1631
					(?!\[.+?\][ ]?:\s)# negative lookahead for footnote or link definition marker.
1632
					(?!\n+[ ]{0,3}\S)# ensure line is not blank and followed
1633
									# by non-indented content
1634
				)*
1635
			)
1636
			}xm',
1637
			array($this, '_stripFootnotes_callback'),
1638
			$text);
1639
		return $text;
1640
	}
1641
1642
	/**
1643
	 * Callback for stripping footnotes
@@ 1838-1849 (lines=12) @@
1835
	 * @param  string $text
1836
	 * @return string
1837
	 */
1838
	protected function stripAbbreviations($text) {
1839
		$less_than_tab = $this->tab_width - 1;
1840
1841
		// Link defs are in the form: [id]*: url "optional title"
1842
		$text = preg_replace_callback('{
1843
			^[ ]{0,' . $less_than_tab . '}\*\[(.+?)\][ ]?:	# abbr_id = $1
1844
			(.*)					# text = $2 (no blank lines allowed)
1845
			}xm',
1846
			array($this, '_stripAbbreviations_callback'),
1847
			$text);
1848
		return $text;
1849
	}
1850
1851
	/**
1852
	 * Callback for stripping abbreviations