| @@ 200-233 (lines=34) @@ | ||
| 197 | ); |
|
| 198 | ||
| 199 | ||
| 200 | protected function stripLinkDefinitions($text) { |
|
| 201 | # |
|
| 202 | # Strips link definitions from text, stores the URLs and titles in |
|
| 203 | # hash references. |
|
| 204 | # |
|
| 205 | $less_than_tab = $this->tab_width - 1; |
|
| 206 | ||
| 207 | # Link defs are in the form: ^[id]: url "optional title" |
|
| 208 | $text = preg_replace_callback('{ |
|
| 209 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
|
| 210 | [ ]* |
|
| 211 | \n? # maybe *one* newline |
|
| 212 | [ ]* |
|
| 213 | (?: |
|
| 214 | <(.+?)> # url = $2 |
|
| 215 | | |
|
| 216 | (\S+?) # url = $3 |
|
| 217 | ) |
|
| 218 | [ ]* |
|
| 219 | \n? # maybe one newline |
|
| 220 | [ ]* |
|
| 221 | (?: |
|
| 222 | (?<=\s) # lookbehind for whitespace |
|
| 223 | ["(] |
|
| 224 | (.*?) # title = $4 |
|
| 225 | [")] |
|
| 226 | [ ]* |
|
| 227 | )? # title is optional |
|
| 228 | (?:\n+|\Z) |
|
| 229 | }xm', |
|
| 230 | array($this, '_stripLinkDefinitions_callback'), |
|
| 231 | $text); |
|
| 232 | return $text; |
|
| 233 | } |
|
| 234 | protected function _stripLinkDefinitions_callback($matches) { |
|
| 235 | $link_id = strtolower($matches[1]); |
|
| 236 | $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| @@ 186-220 (lines=35) @@ | ||
| 183 | } |
|
| 184 | ||
| 185 | ||
| 186 | protected function stripLinkDefinitions($text) { |
|
| 187 | # |
|
| 188 | # Strips link definitions from text, stores the URLs and titles in |
|
| 189 | # hash references. |
|
| 190 | # |
|
| 191 | $less_than_tab = $this->tab_width - 1; |
|
| 192 | ||
| 193 | # Link defs are in the form: ^[id]: url "optional title" |
|
| 194 | $text = preg_replace_callback('{ |
|
| 195 | ^[ ]{0,'.$less_than_tab.'}\[(.+)\][ ]?: # id = $1 |
|
| 196 | [ ]* |
|
| 197 | \n? # maybe *one* newline |
|
| 198 | [ ]* |
|
| 199 | (?: |
|
| 200 | <(.+?)> # url = $2 |
|
| 201 | | |
|
| 202 | (\S+?) # url = $3 |
|
| 203 | ) |
|
| 204 | [ ]* |
|
| 205 | \n? # maybe one newline |
|
| 206 | [ ]* |
|
| 207 | (?: |
|
| 208 | (?<=\s) # lookbehind for whitespace |
|
| 209 | ["(] |
|
| 210 | (.*?) # title = $4 |
|
| 211 | [")] |
|
| 212 | [ ]* |
|
| 213 | )? # title is optional |
|
| 214 | (?:[ ]* '.$this->id_class_attr_catch_re.' )? # $5 = extra id & class attr |
|
| 215 | (?:\n+|\Z) |
|
| 216 | }xm', |
|
| 217 | array($this, '_stripLinkDefinitions_callback'), |
|
| 218 | $text); |
|
| 219 | return $text; |
|
| 220 | } |
|
| 221 | protected function _stripLinkDefinitions_callback($matches) { |
|
| 222 | $link_id = strtolower($matches[1]); |
|
| 223 | $url = $matches[2] == '' ? $matches[3] : $matches[2]; |
|
| @@ 1278-1316 (lines=39) @@ | ||
| 1275 | } |
|
| 1276 | ||
| 1277 | ||
| 1278 | protected function doFencedCodeBlocks($text) { |
|
| 1279 | # |
|
| 1280 | # Adding the fenced code block syntax to regular Markdown: |
|
| 1281 | # |
|
| 1282 | # ~~~ |
|
| 1283 | # Code block |
|
| 1284 | # ~~~ |
|
| 1285 | # |
|
| 1286 | $less_than_tab = $this->tab_width; |
|
| 1287 | ||
| 1288 | $text = preg_replace_callback('{ |
|
| 1289 | (?:\n|\A) |
|
| 1290 | # 1: Opening marker |
|
| 1291 | ( |
|
| 1292 | (?:~{3,}|`{3,}) # 3 or more tildes/backticks. |
|
| 1293 | ) |
|
| 1294 | [ ]* |
|
| 1295 | (?: |
|
| 1296 | \.?([-_:a-zA-Z0-9]+) # 2: standalone class name |
|
| 1297 | | |
|
| 1298 | '.$this->id_class_attr_catch_re.' # 3: Extra attributes |
|
| 1299 | )? |
|
| 1300 | [ ]* \n # Whitespace and newline following marker. |
|
| 1301 | ||
| 1302 | # 4: Content |
|
| 1303 | ( |
|
| 1304 | (?> |
|
| 1305 | (?!\1 [ ]* \n) # Not a closing marker. |
|
| 1306 | .*\n+ |
|
| 1307 | )+ |
|
| 1308 | ) |
|
| 1309 | ||
| 1310 | # Closing marker. |
|
| 1311 | \1 [ ]* (?= \n ) |
|
| 1312 | }xm', |
|
| 1313 | array($this, '_doFencedCodeBlocks_callback'), $text); |
|
| 1314 | ||
| 1315 | return $text; |
|
| 1316 | } |
|
| 1317 | protected function _doFencedCodeBlocks_callback($matches) { |
|
| 1318 | $classname =& $matches[2]; |
|
| 1319 | $attrs =& $matches[3]; |
|
| @@ 1403-1429 (lines=27) @@ | ||
| 1400 | ||
| 1401 | ### Footnotes |
|
| 1402 | ||
| 1403 | protected function stripFootnotes($text) { |
|
| 1404 | # |
|
| 1405 | # Strips link definitions from text, stores the URLs and titles in |
|
| 1406 | # hash references. |
|
| 1407 | # |
|
| 1408 | $less_than_tab = $this->tab_width - 1; |
|
| 1409 | ||
| 1410 | # Link defs are in the form: [^id]: url "optional title" |
|
| 1411 | $text = preg_replace_callback('{ |
|
| 1412 | ^[ ]{0,'.$less_than_tab.'}\[\^(.+?)\][ ]?: # note_id = $1 |
|
| 1413 | [ ]* |
|
| 1414 | \n? # maybe *one* newline |
|
| 1415 | ( # text = $2 (no blank lines allowed) |
|
| 1416 | (?: |
|
| 1417 | .+ # actual text |
|
| 1418 | | |
|
| 1419 | \n # newlines but |
|
| 1420 | (?!\[.+?\][ ]?:\s)# negative lookahead for footnote or link definition marker. |
|
| 1421 | (?!\n+[ ]{0,3}\S)# ensure line is not blank and followed |
|
| 1422 | # by non-indented content |
|
| 1423 | )* |
|
| 1424 | ) |
|
| 1425 | }xm', |
|
| 1426 | array($this, '_stripFootnotes_callback'), |
|
| 1427 | $text); |
|
| 1428 | return $text; |
|
| 1429 | } |
|
| 1430 | protected function _stripFootnotes_callback($matches) { |
|
| 1431 | $note_id = $this->fn_id_prefix . $matches[1]; |
|
| 1432 | $this->footnotes[$note_id] = $this->outdent($matches[2]); |
|
| @@ 1558-1572 (lines=15) @@ | ||
| 1555 | ||
| 1556 | ### Abbreviations ### |
|
| 1557 | ||
| 1558 | protected function stripAbbreviations($text) { |
|
| 1559 | # |
|
| 1560 | # Strips abbreviations from text, stores titles in hash references. |
|
| 1561 | # |
|
| 1562 | $less_than_tab = $this->tab_width - 1; |
|
| 1563 | ||
| 1564 | # Link defs are in the form: [id]*: url "optional title" |
|
| 1565 | $text = preg_replace_callback('{ |
|
| 1566 | ^[ ]{0,'.$less_than_tab.'}\*\[(.+?)\][ ]?: # abbr_id = $1 |
|
| 1567 | (.*) # text = $2 (no blank lines allowed) |
|
| 1568 | }xm', |
|
| 1569 | array($this, '_stripAbbreviations_callback'), |
|
| 1570 | $text); |
|
| 1571 | return $text; |
|
| 1572 | } |
|
| 1573 | protected function _stripAbbreviations_callback($matches) { |
|
| 1574 | $abbr_word = $matches[1]; |
|
| 1575 | $abbr_desc = $matches[2]; |
|