@@ 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 |
@@ 272-302 (lines=31) @@ | ||
269 | * @param string $text |
|
270 | * @return string |
|
271 | */ |
|
272 | protected function stripLinkDefinitions($text) { |
|
273 | $less_than_tab = $this->tab_width - 1; |
|
274 | ||
275 | // Link defs are in the form: ^[id]: url "optional title" |
|
276 | $text = preg_replace_callback('{ |
|
277 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
|
278 | [ ]* |
|
279 | \n? # maybe *one* newline |
|
280 | [ ]* |
|
281 | (?: |
|
282 | <(.+?)> # url = $2 |
|
283 | | |
|
284 | (\S+?) # url = $3 |
|
285 | ) |
|
286 | [ ]* |
|
287 | \n? # maybe one newline |
|
288 | [ ]* |
|
289 | (?: |
|
290 | (?<=\s) # lookbehind for whitespace |
|
291 | ["(] |
|
292 | (.*?) # title = $4 |
|
293 | [")] |
|
294 | [ ]* |
|
295 | )? # title is optional |
|
296 | (?:[ ]* '.$this->id_class_attr_catch_re.' )? # $5 = extra id & class attr |
|
297 | (?:\n+|\Z) |
|
298 | }xm', |
|
299 | array($this, '_stripLinkDefinitions_callback'), |
|
300 | $text); |
|
301 | return $text; |
|
302 | } |
|
303 | ||
304 | /** |
|
305 | * Strip link definition callback |
|
@@ 1437-1471 (lines=35) @@ | ||
1434 | * @param string $text |
|
1435 | * @return string |
|
1436 | */ |
|
1437 | protected function doFencedCodeBlocks($text) { |
|
1438 | ||
1439 | $less_than_tab = $this->tab_width; |
|
1440 | ||
1441 | $text = preg_replace_callback('{ |
|
1442 | (?:\n|\A) |
|
1443 | # 1: Opening marker |
|
1444 | ( |
|
1445 | (?:~{3,}|`{3,}) # 3 or more tildes/backticks. |
|
1446 | ) |
|
1447 | [ ]* |
|
1448 | (?: |
|
1449 | \.?([-_:a-zA-Z0-9]+) # 2: standalone class name |
|
1450 | )? |
|
1451 | [ ]* |
|
1452 | (?: |
|
1453 | ' . $this->id_class_attr_catch_re . ' # 3: Extra attributes |
|
1454 | )? |
|
1455 | [ ]* \n # Whitespace and newline following marker. |
|
1456 | ||
1457 | # 4: Content |
|
1458 | ( |
|
1459 | (?> |
|
1460 | (?!\1 [ ]* \n) # Not a closing marker. |
|
1461 | .*\n+ |
|
1462 | )+ |
|
1463 | ) |
|
1464 | ||
1465 | # Closing marker. |
|
1466 | \1 [ ]* (?= \n ) |
|
1467 | }xm', |
|
1468 | array($this, '_doFencedCodeBlocks_callback'), $text); |
|
1469 | ||
1470 | return $text; |
|
1471 | } |
|
1472 | ||
1473 | /** |
|
1474 | * Callback to process fenced code blocks |
|
@@ 1579-1601 (lines=23) @@ | ||
1576 | * @param string $text |
|
1577 | * @return string |
|
1578 | */ |
|
1579 | protected function stripFootnotes($text) { |
|
1580 | $less_than_tab = $this->tab_width - 1; |
|
1581 | ||
1582 | // Link defs are in the form: [^id]: url "optional title" |
|
1583 | $text = preg_replace_callback('{ |
|
1584 | ^[ ]{0,' . $less_than_tab . '}\[\^(.+?)\][ ]?: # note_id = $1 |
|
1585 | [ ]* |
|
1586 | \n? # maybe *one* newline |
|
1587 | ( # text = $2 (no blank lines allowed) |
|
1588 | (?: |
|
1589 | .+ # actual text |
|
1590 | | |
|
1591 | \n # newlines but |
|
1592 | (?!\[.+?\][ ]?:\s)# negative lookahead for footnote or link definition marker. |
|
1593 | (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed |
|
1594 | # by non-indented content |
|
1595 | )* |
|
1596 | ) |
|
1597 | }xm', |
|
1598 | array($this, '_stripFootnotes_callback'), |
|
1599 | $text); |
|
1600 | return $text; |
|
1601 | } |
|
1602 | ||
1603 | /** |
|
1604 | * Callback for stripping footnotes |
|
@@ 1764-1775 (lines=12) @@ | ||
1761 | * @param string $text |
|
1762 | * @return string |
|
1763 | */ |
|
1764 | protected function stripAbbreviations($text) { |
|
1765 | $less_than_tab = $this->tab_width - 1; |
|
1766 | ||
1767 | // Link defs are in the form: [id]*: url "optional title" |
|
1768 | $text = preg_replace_callback('{ |
|
1769 | ^[ ]{0,' . $less_than_tab . '}\*\[(.+?)\][ ]?: # abbr_id = $1 |
|
1770 | (.*) # text = $2 (no blank lines allowed) |
|
1771 | }xm', |
|
1772 | array($this, '_stripAbbreviations_callback'), |
|
1773 | $text); |
|
1774 | return $text; |
|
1775 | } |
|
1776 | ||
1777 | /** |
|
1778 | * Callback for stripping abbreviations |