PEAR2_Text_Markdown › PEAR2_Text_Markdown-0.1.0/php/PEAR2/Text/Markdown/Plugin/StripLinkDefs.php
- PEAR2_Text_Markdown-0.1.0/
- doc/
- pear2.php.net/
- PEAR2_Text_Markdown/
- examples/
- examples/
- examples/
- PEAR2_Text_Markdown/
- pear2.php.net/
- php/
- PEAR2/
- Autoload.php
- Exception.php
- MultiErrors/
- MultiErrors.php
- Text/
- Markdown/
- Apidoc/
- Apidoc.php
- Extra/
- Extra.php
- Main.php
- Plugin/
- Plugin.php
- Wiki/
- Wiki.php
- Markdown/
- PEAR2/
- doc/
- package.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
*
* Strips named-link definitions in the preparation phase.
*
* This is in support of the Link and Image plugins.
*
* A named link reference looks like this ...
*
* [name]: http://example.com "Optional Title"
*
* @category Solar
*
* @package Markdown
*
* @author John Gruber <http://daringfireball.net/projects/markdown/>
*
* @author Michel Fortin <http://www.michelf.com/projects/php-markdown/>
*
* @author Paul M. Jones <pmjones@solarphp.com>
*
* @license http://opensource.org/licenses/bsd-license.php BSD
*
* @version $Id: StripLinkDefs.php 3153 2008-05-05 23:14:16Z pmjones $
*
*/
namespace PEAR2\Text;
class Markdown_Plugin_StripLinkDefs extends Markdown_Plugin
{
/**
*
* Run this plugin during the "prepare" phase.
*
* @var bool
*
*/
protected $_is_prepare = true;
/**
*
* Removes link definitions from source and saves for later use.
*
* @param string $text Markdown source text.
*
* @return string The text without link definitions.
*
*/
public function prepare($text)
{
$less_than_tab = $this->_getTabWidth() - 1;
// Link defs are in the form: ^[id]: url "optional title"
$text = preg_replace_callback('{
^[ ]{0,'.$less_than_tab.'}\[(.+)\]: # id = $1
[ \t]*
\n? # maybe *one* newline
[ \t]*
<?(\S+?)>? # url = $2
[ \t]*
\n? # maybe one newline
[ \t]*
(?:
(?<=\s) # lookbehind for whitespace
["(]
(.+?) # title = $3
[")]
[ \t]*
)? # title is optional
(?:\n+|\Z)
}xm',
array($this, '_prepare'),
$text
);
return $text;
}
/**
*
* Support callback for link definitions.
*
* @param string $matches Matches from preg_replace_callback().
*
* @return string The replacement text.
*
*/
protected function _prepare($matches)
{
$name = strtolower($matches[1]);
$href = $matches[2];
$title = empty($matches[3]) ? null : $matches[3];
// save the link
$this->_markdown->setLink($name, $href, $title);
// done.
// no return, it's supposed to be removed.
}
}
EOF
