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
@@ 1608-1630 (lines=23) @@
1605
	 * @param  string $text
1606
	 * @return string
1607
	 */
1608
	protected function stripFootnotes($text) {
1609
		$less_than_tab = $this->tab_width - 1;
1610
1611
		// Link defs are in the form: [^id]: url "optional title"
1612
		$text = preg_replace_callback('{
1613
			^[ ]{0,' . $less_than_tab . '}\[\^(.+?)\][ ]?:	# note_id = $1
1614
			  [ ]*
1615
			  \n?					# maybe *one* newline
1616
			(						# text = $2 (no blank lines allowed)
1617
				(?:
1618
					.+				# actual text
1619
				|
1620
					\n				# newlines but
1621
					(?!\[.+?\][ ]?:\s)# negative lookahead for footnote or link definition marker.
1622
					(?!\n+[ ]{0,3}\S)# ensure line is not blank and followed
1623
									# by non-indented content
1624
				)*
1625
			)
1626
			}xm',
1627
			array($this, '_stripFootnotes_callback'),
1628
			$text);
1629
		return $text;
1630
	}
1631
1632
	/**
1633
	 * Callback for stripping footnotes
@@ 1828-1839 (lines=12) @@
1825
	 * @param  string $text
1826
	 * @return string
1827
	 */
1828
	protected function stripAbbreviations($text) {
1829
		$less_than_tab = $this->tab_width - 1;
1830
1831
		// Link defs are in the form: [id]*: url "optional title"
1832
		$text = preg_replace_callback('{
1833
			^[ ]{0,' . $less_than_tab . '}\*\[(.+?)\][ ]?:	# abbr_id = $1
1834
			(.*)					# text = $2 (no blank lines allowed)
1835
			}xm',
1836
			array($this, '_stripAbbreviations_callback'),
1837
			$text);
1838
		return $text;
1839
	}
1840
1841
	/**
1842
	 * Callback for stripping abbreviations