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

@@ 289-319 (lines=31) @@
286
	 * @param  string $text
287
	 * @return string
288
	 */
289
	protected function stripLinkDefinitions($text) {
290
		$less_than_tab = $this->tab_width - 1;
291
292
		// Link defs are in the form: ^[id]: url "optional title"
293
		$text = preg_replace_callback('{
294
							^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?:	# id = $1
295
							  [ ]*
296
							  \n?				# maybe *one* newline
297
							  [ ]*
298
							(?:
299
							  <(.+?)>			# url = $2
300
							|
301
							  (\S+?)			# url = $3
302
							)
303
							  [ ]*
304
							  \n?				# maybe one newline
305
							  [ ]*
306
							(?:
307
								(?<=\s)			# lookbehind for whitespace
308
								["(]
309
								(.*?)			# title = $4
310
								[")]
311
								[ ]*
312
							)?	# title is optional
313
					(?:[ ]* '.$this->id_class_attr_catch_re.' )?  # $5 = extra id & class attr
314
							(?:\n+|\Z)
315
			}xm',
316
			array($this, '_stripLinkDefinitions_callback'),
317
			$text);
318
		return $text;
319
	}
320
321
	/**
322
	 * Strip link definition callback
@@ 1605-1627 (lines=23) @@
1602
	 * @param  string $text
1603
	 * @return string
1604
	 */
1605
	protected function stripFootnotes($text) {
1606
		$less_than_tab = $this->tab_width - 1;
1607
1608
		// Link defs are in the form: [^id]: url "optional title"
1609
		$text = preg_replace_callback('{
1610
			^[ ]{0,' . $less_than_tab . '}\[\^(.+?)\][ ]?:	# note_id = $1
1611
			  [ ]*
1612
			  \n?					# maybe *one* newline
1613
			(						# text = $2 (no blank lines allowed)
1614
				(?:
1615
					.+				# actual text
1616
				|
1617
					\n				# newlines but
1618
					(?!\[.+?\][ ]?:\s)# negative lookahead for footnote or link definition marker.
1619
					(?!\n+[ ]{0,3}\S)# ensure line is not blank and followed
1620
									# by non-indented content
1621
				)*
1622
			)
1623
			}xm',
1624
			array($this, '_stripFootnotes_callback'),
1625
			$text);
1626
		return $text;
1627
	}
1628
1629
	/**
1630
	 * Callback for stripping footnotes
@@ 1806-1817 (lines=12) @@
1803
	 * @param  string $text
1804
	 * @return string
1805
	 */
1806
	protected function stripAbbreviations($text) {
1807
		$less_than_tab = $this->tab_width - 1;
1808
1809
		// Link defs are in the form: [id]*: url "optional title"
1810
		$text = preg_replace_callback('{
1811
			^[ ]{0,' . $less_than_tab . '}\*\[(.+?)\][ ]?:	# abbr_id = $1
1812
			(.*)					# text = $2 (no blank lines allowed)
1813
			}xm',
1814
			array($this, '_stripAbbreviations_callback'),
1815
			$text);
1816
		return $text;
1817
	}
1818
1819
	/**
1820
	 * Callback for stripping abbreviations