| @@ 547-616 (lines=70) @@ | ||
| 544 | } |
|
| 545 | ||
| 546 | ||
| 547 | function doAnchors($text) { |
|
| 548 | # |
|
| 549 | # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 550 | # |
|
| 551 | if ($this->in_anchor) return $text; |
|
| 552 | $this->in_anchor = true; |
|
| 553 | ||
| 554 | # |
|
| 555 | # First, handle reference-style links: [link text] [id] |
|
| 556 | # |
|
| 557 | $text = preg_replace_callback('{ |
|
| 558 | ( # wrap whole match in $1 |
|
| 559 | \[ |
|
| 560 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 561 | \] |
|
| 562 | ||
| 563 | [ ]? # one optional space |
|
| 564 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
| 565 | ||
| 566 | \[ |
|
| 567 | (.*?) # id = $3 |
|
| 568 | \] |
|
| 569 | ) |
|
| 570 | }xs', |
|
| 571 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 572 | ||
| 573 | # |
|
| 574 | # Next, inline-style links: [link text](url "optional title") |
|
| 575 | # |
|
| 576 | $text = preg_replace_callback('{ |
|
| 577 | ( # wrap whole match in $1 |
|
| 578 | \[ |
|
| 579 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 580 | \] |
|
| 581 | \( # literal paren |
|
| 582 | [ \n]* |
|
| 583 | (?: |
|
| 584 | <(.+?)> # href = $3 |
|
| 585 | | |
|
| 586 | ('.$this->nested_url_parenthesis_re.') # href = $4 |
|
| 587 | ) |
|
| 588 | [ \n]* |
|
| 589 | ( # $5 |
|
| 590 | ([\'"]) # quote char = $6 |
|
| 591 | (.*?) # Title = $7 |
|
| 592 | \6 # matching quote |
|
| 593 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
|
| 594 | )? # title is optional |
|
| 595 | \) |
|
| 596 | ) |
|
| 597 | }xs', |
|
| 598 | array(&$this, '_doAnchors_inline_callback'), $text); |
|
| 599 | ||
| 600 | # |
|
| 601 | # Last, handle reference-style shortcuts: [link text] |
|
| 602 | # These must come last in case you've also got [link text][1] |
|
| 603 | # or [link text](/foo) |
|
| 604 | # |
|
| 605 | $text = preg_replace_callback('{ |
|
| 606 | ( # wrap whole match in $1 |
|
| 607 | \[ |
|
| 608 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
|
| 609 | \] |
|
| 610 | ) |
|
| 611 | }xs', |
|
| 612 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 613 | ||
| 614 | $this->in_anchor = false; |
|
| 615 | return $text; |
|
| 616 | } |
|
| 617 | function _doAnchors_reference_callback($matches) { |
|
| 618 | $whole_match = $matches[1]; |
|
| 619 | $link_text = $matches[2]; |
|
| @@ 2230-2300 (lines=71) @@ | ||
| 2227 | } |
|
| 2228 | ||
| 2229 | ||
| 2230 | function doAnchors($text) { |
|
| 2231 | # |
|
| 2232 | # Turn Markdown link shortcuts into XHTML <a> tags. |
|
| 2233 | # |
|
| 2234 | if ($this->in_anchor) return $text; |
|
| 2235 | $this->in_anchor = true; |
|
| 2236 | ||
| 2237 | # |
|
| 2238 | # First, handle reference-style links: [link text] [id] |
|
| 2239 | # |
|
| 2240 | $text = preg_replace_callback('{ |
|
| 2241 | ( # wrap whole match in $1 |
|
| 2242 | \[ |
|
| 2243 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 2244 | \] |
|
| 2245 | ||
| 2246 | [ ]? # one optional space |
|
| 2247 | (?:\n[ ]*)? # one optional newline followed by spaces |
|
| 2248 | ||
| 2249 | \[ |
|
| 2250 | (.*?) # id = $3 |
|
| 2251 | \] |
|
| 2252 | ) |
|
| 2253 | }xs', |
|
| 2254 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 2255 | ||
| 2256 | # |
|
| 2257 | # Next, inline-style links: [link text](url "optional title") |
|
| 2258 | # |
|
| 2259 | $text = preg_replace_callback('{ |
|
| 2260 | ( # wrap whole match in $1 |
|
| 2261 | \[ |
|
| 2262 | ('.$this->nested_brackets_re.') # link text = $2 |
|
| 2263 | \] |
|
| 2264 | \( # literal paren |
|
| 2265 | [ \n]* |
|
| 2266 | (?: |
|
| 2267 | <(.+?)> # href = $3 |
|
| 2268 | | |
|
| 2269 | ('.$this->nested_url_parenthesis_re.') # href = $4 |
|
| 2270 | ) |
|
| 2271 | [ \n]* |
|
| 2272 | ( # $5 |
|
| 2273 | ([\'"]) # quote char = $6 |
|
| 2274 | (.*?) # Title = $7 |
|
| 2275 | \6 # matching quote |
|
| 2276 | [ \n]* # ignore any spaces/tabs between closing quote and ) |
|
| 2277 | )? # title is optional |
|
| 2278 | \) |
|
| 2279 | (?:[ ]? '.$this->id_class_attr_catch_re.' )? # $8 = id/class attributes |
|
| 2280 | ) |
|
| 2281 | }xs', |
|
| 2282 | array(&$this, '_doAnchors_inline_callback'), $text); |
|
| 2283 | ||
| 2284 | # |
|
| 2285 | # Last, handle reference-style shortcuts: [link text] |
|
| 2286 | # These must come last in case you've also got [link text][1] |
|
| 2287 | # or [link text](/foo) |
|
| 2288 | # |
|
| 2289 | $text = preg_replace_callback('{ |
|
| 2290 | ( # wrap whole match in $1 |
|
| 2291 | \[ |
|
| 2292 | ([^\[\]]+) # link text = $2; can\'t contain [ or ] |
|
| 2293 | \] |
|
| 2294 | ) |
|
| 2295 | }xs', |
|
| 2296 | array(&$this, '_doAnchors_reference_callback'), $text); |
|
| 2297 | ||
| 2298 | $this->in_anchor = false; |
|
| 2299 | return $text; |
|
| 2300 | } |
|
| 2301 | function _doAnchors_reference_callback($matches) { |
|
| 2302 | $whole_match = $matches[1]; |
|
| 2303 | $link_text = $matches[2]; |
|