PEAR2_Text_Markdown › PEAR2_Text_Markdown-0.1.0/php/PEAR2/Text/Markdown/Plugin/EmStrong.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
*
* Span plugin to insert emphasis and strong tags.
*
* * `*foo*` and `_foo_` become `<em>foo</em>`.
*
* * `**bar**` and `__bar__` become `<strong>bar</strong>`.
*
* * `***zim***` and `___zim___` become `<strong><em>zim</em></strong>`.
*
* * `**_zim_**` and `__*zim*__` become `<strong><em>zim</em></strong>`.
*
* @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: EmStrong.php 3153 2008-05-05 23:14:16Z pmjones $
*
*/
namespace PEAR2\Text;
class Markdown_Plugin_EmStrong extends Markdown_Plugin
{
/**
*
* This is a span plugin.
*
* @var bool
*
*/
protected $_is_span = true;
/**
*
* Report these as special Markdown characters to be encoded.
*
* @var string
*
*/
protected $_chars = '*_';
/**
*
* Converts emphasis and strong text.
*
* @param string $text The source text.
*
* @return string The transformed XHTML.
*
*/
public function parse($text)
{
// <strong> must go first:
$text = preg_replace_callback('{
( # $1: Marker
(?<!\*\*) \*\* | # (not preceded by two chars of
(?<!__) __ # the same marker)
)
(?=\S) # Not followed by whitespace
(?!\1) # or two others marker chars.
( # $2: Content
(?:
[^*_]+? # Anthing not em markers.
|
# Balance any regular emphasis inside.
([*_]) (?=\S) .+? (?<=\S) \3 # $3: em char (* or _)
|
(?! \1 ) . # Allow unbalanced * and _.
)+?
)
(?<=\S) \1 # End mark not preceded by whitespace.
}sx',
array($this, '_parseStrong'),
$text
);
// Then <em>:
$text = preg_replace_callback(
'{ ( (?<!\*)\* | (?<!_)_ ) (?=\S) (?! \1) (.+?) (?<=\S) \1 }sx',
array($this, '_parseEm'),
$text
);
return $text;
}
/**
*
* Support callback for strong tags.
*
* @param string $matches Matches from preg_replace_callback().
*
* @return string The replacement text.
*
*/
protected function _parseStrong($matches)
{
return $this->_toHtmlToken("<strong>")
. $matches[2]
. $this->_toHtmlToken("</strong>");
}
/**
*
* Support callback for em tags.
*
* @param string $matches Matches from preg_replace_callback().
*
* @return string The replacement text.
*
*/
protected function _parseEm($matches)
{
return $this->_toHtmlToken("<em>")
. $matches[2]
. $this->_toHtmlToken("</em>");
}
}
EOF
