| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
global $MarkdownPHPVersion, $MarkdownSyntaxVersion, |
|---|
| 15 |
$md_empty_element_suffix, $md_tab_width, |
|---|
| 16 |
$md_nested_brackets_depth, $md_nested_brackets, |
|---|
| 17 |
$md_escape_table, $md_backslash_escape_table, |
|---|
| 18 |
$md_list_level; |
|---|
| 19 |
|
|---|
| 20 |
$MarkdownPHPVersion = '1.0.1c'; |
|---|
| 21 |
$MarkdownSyntaxVersion = '1.0.1'; |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
# |
|---|
| 25 |
# Global default settings: |
|---|
| 26 |
# |
|---|
| 27 |
$md_empty_element_suffix = " />"; |
|---|
| 28 |
$md_tab_width = 4; |
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
$md_wp_posts = true; |
|---|
| 34 |
$md_wp_comments = true; |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
# -- WordPress Plugin Interface ----------------------------------------------- |
|---|
| 38 |
/* |
|---|
| 39 |
Plugin Name: Markdown |
|---|
| 40 |
Plugin URI: http://www.michelf.com/projects/php-markdown/ |
|---|
| 41 |
Description: <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a> allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by <a href="http://daringfireball.net/">John Gruber</a>. <a href="http://www.michelf.com/projects/php-markdown/">More...</a> |
|---|
| 42 |
Version: 1.0.1c |
|---|
| 43 |
Author: Michel Fortin |
|---|
| 44 |
Author URI: http://www.michelf.com/ |
|---|
| 45 |
*/ |
|---|
| 46 |
if (isset($wp_version)) { |
|---|
| 47 |
|
|---|
| 48 |
# <http://www.michelf.com/weblog/2005/wordpress-text-flow-vs-markdown/> |
|---|
| 49 |
|
|---|
| 50 |
# Post content and excerpts |
|---|
| 51 |
if ($md_wp_posts) { |
|---|
| 52 |
remove_filter('the_content', 'wpautop'); |
|---|
| 53 |
remove_filter('the_excerpt', 'wpautop'); |
|---|
| 54 |
add_filter('the_content', 'Markdown', 6); |
|---|
| 55 |
add_filter('get_the_excerpt', 'Markdown', 6); |
|---|
| 56 |
add_filter('get_the_excerpt', 'trim', 7); |
|---|
| 57 |
add_filter('the_excerpt', 'md_add_p'); |
|---|
| 58 |
add_filter('the_excerpt_rss', 'md_strip_p'); |
|---|
| 59 |
|
|---|
| 60 |
remove_filter('content_save_pre', 'balanceTags', 50); |
|---|
| 61 |
remove_filter('excerpt_save_pre', 'balanceTags', 50); |
|---|
| 62 |
add_filter('the_content', 'balanceTags', 50); |
|---|
| 63 |
add_filter('get_the_excerpt', 'balanceTags', 9); |
|---|
| 64 |
|
|---|
| 65 |
function md_add_p($text) { |
|---|
| 66 |
if (strlen($text) == 0) return; |
|---|
| 67 |
if (strcasecmp(substr($text, -3), '<p>') == 0) return $text; |
|---|
| 68 |
return '<p>'.$text.'</p>'; |
|---|
| 69 |
} |
|---|
| 70 |
function md_strip_p($t) { return preg_replace('{</?[pP]>}', '', $t); } |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
if ($md_wp_comments) { |
|---|
| 75 |
remove_filter('comment_text', 'wpautop'); |
|---|
| 76 |
remove_filter('comment_text', 'make_clickable'); |
|---|
| 77 |
add_filter('pre_comment_content', 'Markdown', 6); |
|---|
| 78 |
add_filter('pre_comment_content', 'md_hide_tags', 8); |
|---|
| 79 |
add_filter('pre_comment_content', 'md_show_tags', 12); |
|---|
| 80 |
add_filter('get_comment_text', 'Markdown', 6); |
|---|
| 81 |
add_filter('get_comment_excerpt', 'Markdown', 6); |
|---|
| 82 |
add_filter('get_comment_excerpt', 'md_strip_p', 7); |
|---|
| 83 |
|
|---|
| 84 |
global $md_hidden_tags; |
|---|
| 85 |
$md_hidden_tags = array( |
|---|
| 86 |
'<p>' => md5('<p>'), '</p>' => md5('</p>'), |
|---|
| 87 |
'<pre>' => md5('<pre>'), '</pre>'=> md5('</pre>'), |
|---|
| 88 |
'<ol>' => md5('<ol>'), '</ol>' => md5('</ol>'), |
|---|
| 89 |
'<ul>' => md5('<ul>'), '</ul>' => md5('</ul>'), |
|---|
| 90 |
'<li>' => md5('<li>'), '</li>' => md5('</li>'), |
|---|
| 91 |
); |
|---|
| 92 |
|
|---|
| 93 |
function md_hide_tags($text) { |
|---|
| 94 |
global $md_hidden_tags; |
|---|
| 95 |
return str_replace(array_keys($md_hidden_tags), |
|---|
| 96 |
array_values($md_hidden_tags), $text); |
|---|
| 97 |
} |
|---|
| 98 |
function md_show_tags($text) { |
|---|
| 99 |
global $md_hidden_tags; |
|---|
| 100 |
return str_replace(array_values($md_hidden_tags), |
|---|
| 101 |
array_keys($md_hidden_tags), $text); |
|---|
| 102 |
} |
|---|
| 103 |
} |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
function identify_modifier_markdown() { |
|---|
| 109 |
global $MarkdownPHPVersion; |
|---|
| 110 |
return array( |
|---|
| 111 |
'name' => 'markdown', |
|---|
| 112 |
'type' => 'modifier', |
|---|
| 113 |
'nicename' => 'Markdown', |
|---|
| 114 |
'description' => 'A text-to-HTML conversion tool for web writers', |
|---|
| 115 |
'authors' => 'Michel Fortin and John Gruber', |
|---|
| 116 |
'licence' => 'GPL', |
|---|
| 117 |
'version' => $MarkdownPHPVersion, |
|---|
| 118 |
'help' => '<a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a> allows you to write using an easy-to-read, easy-to-write plain text format. Based on the original Perl version by <a href="http://daringfireball.net/">John Gruber</a>. <a href="http://www.michelf.com/projects/php-markdown/">More...</a>' |
|---|
| 119 |
); |
|---|
| 120 |
} |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
function smarty_modifier_markdown($text) { |
|---|
| 124 |
return Markdown($text); |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
if (strcasecmp(substr(__FILE__, -16), "classTextile.php") == 0) { |
|---|
| 130 |
|
|---|
| 131 |
@include_once 'smartypants.php'; |
|---|
| 132 |
|
|---|
| 133 |
class Textile { |
|---|
| 134 |
function TextileThis($text, $lite='', $encode='', $noimage='', $strict='') { |
|---|
| 135 |
if ($lite == '' && $encode == '') $text = Markdown($text); |
|---|
| 136 |
if (function_exists('SmartyPants')) $text = SmartyPants($text); |
|---|
| 137 |
return $text; |
|---|
| 138 |
} |
|---|
| 139 |
} |
|---|
| 140 |
} |
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
$md_nested_brackets_depth = 6; |
|---|
| 151 |
$md_nested_brackets = |
|---|
| 152 |
str_repeat('(?>[^\[\]]+|\[', $md_nested_brackets_depth). |
|---|
| 153 |
str_repeat('\])*', $md_nested_brackets_depth); |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
$md_escape_table = array( |
|---|
| 157 |
"\\" => md5("\\"), |
|---|
| 158 |
"`" => md5("`"), |
|---|
| 159 |
"*" => md5("*"), |
|---|
| 160 |
"_" => md5("_"), |
|---|
| 161 |
"{" => md5("{"), |
|---|
| 162 |
"}" => md5("}"), |
|---|
| 163 |
"[" => md5("["), |
|---|
| 164 |
"]" => md5("]"), |
|---|
| 165 |
"(" => md5("("), |
|---|
| 166 |
")" => md5(")"), |
|---|
| 167 |
">" => md5(">"), |
|---|
| 168 |
"#" => md5("#"), |
|---|
| 169 |
"+" => md5("+"), |
|---|
| 170 |
"-" => md5("-"), |
|---|
| 171 |
"." => md5("."), |
|---|
| 172 |
"!" => md5("!") |
|---|
| 173 |
); |
|---|
| 174 |
|
|---|
| 175 |
$md_backslash_escape_table; |
|---|
| 176 |
foreach ($md_escape_table as $key => $char) |
|---|
| 177 |
$md_backslash_escape_table["\\$key"] = $char; |
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
function Markdown($text) { |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
global $md_urls, $md_titles, $md_html_blocks; |
|---|
| 192 |
$md_urls = array(); |
|---|
| 193 |
$md_titles = array(); |
|---|
| 194 |
$md_html_blocks = array(); |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
|
|---|
| 198 |
$text = str_replace(array("\r\n", "\r"), "\n", $text); |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
$text .= "\n\n"; |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
$text = _Detab($text); |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
$text = preg_replace('/^[ \t]+$/m', '', $text); |
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
$text = _HashHTMLBlocks($text); |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
$text = _StripLinkDefinitions($text); |
|---|
| 217 |
|
|---|
| 218 |
$text = _RunBlockGamut($text); |
|---|
| 219 |
|
|---|
| 220 |
$text = _UnescapeSpecialChars($text); |
|---|
| 221 |
|
|---|
| 222 |
$text . "\n"; |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
_StripLinkDefinitions($text) { |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
global $md_tab_width; |
|---|
| 232 |
$less_than_tab = $md_tab_width - 1; |
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
$text = preg_replace_callback('{ |
|---|
| 236 |
.$less_than_tab.'}\[(.+)\]: # id = $1 |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
, |
|---|
| 253 |
'_StripLinkDefinitions_callback', |
|---|
| 254 |
$text); |
|---|
| 255 |
$text; |
|---|
| 256 |
|
|---|
| 257 |
_StripLinkDefinitions_callback($matches) { |
|---|
| 258 |
$md_urls, $md_titles; |
|---|
| 259 |
$link_id = strtolower($matches[1]); |
|---|
| 260 |
$md_urls[$link_id] = _EncodeAmpsAndAngles($matches[2]); |
|---|
| 261 |
$matches[3])) |
|---|
| 262 |
$md_titles[$link_id] = str_replace('"', '"', $matches[3]); |
|---|
| 263 |
''; |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
function _HashHTMLBlocks($text) { |
|---|
| 268 |
global $md_tab_width; |
|---|
| 269 |
$less_than_tab = $md_tab_width - 1; |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
# We only want to do this for block-level HTML tags, such as headers, |
|---|
| 273 |
# lists, and tables. That's because we still want to wrap <p>s around |
|---|
| 274 |
# "paragraphs" that are wrapped in non-block-level tags, such as anchors, |
|---|
| 275 |
# phrase emphasis, and spans. The list of tags we're looking for is |
|---|
| 276 |
# hard-coded: |
|---|
| 277 |
$block_tags_a = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|'. |
|---|
| 278 |
'script|noscript|form|fieldset|iframe|math|ins|del'; |
|---|
| 279 |
$block_tags_b = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|'. |
|---|
| 280 |
'script|noscript|form|fieldset|iframe|math'; |
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
# <div> |
|---|
| 284 |
# <div> |
|---|
| 285 |
# tags for inner block must be indented. |
|---|
| 286 |
# </div> |
|---|
| 287 |
# </div> |
|---|
| 288 |
# |
|---|
| 289 |
# The outermost tags must start at the left margin for this to match, and |
|---|
| 290 |
# the inner nested divs must be indented. |
|---|
| 291 |
# We need to do this before the next, more liberal match, because the next |
|---|
| 292 |
# match will start at the first `<div>` and stop at the first `</div>`. |
|---|
| 293 |
$text = preg_replace_callback("{ |
|---|
| 294 |
( # save in $1 |
|---|
| 295 |
^ # start of line (with /m) |
|---|
| 296 |
<($block_tags_a) # start tag = $2 |
|---|
| 297 |
\\b # word break |
|---|
| 298 |
(.*\\n)*? # any number of lines, minimally matching |
|---|
| 299 |
</\\2> # the matching end tag |
|---|
| 300 |
[ \\t]* # trailing spaces/tabs |
|---|
| 301 |
(?=\\n+|\\Z) # followed by a newline or end of document |
|---|
| 302 |
) |
|---|
| 303 |
}xm", |
|---|
| 304 |
'_HashHTMLBlocks_callback', |
|---|
| 305 |
$text); |
|---|
| 306 |
|
|---|
| 307 |
|
|---|
| 308 |
# Now match more liberally, simply from `\n<tag>` to `</tag>\n` |
|---|
| 309 |
# |
|---|
| 310 |
$text = preg_replace_callback("{ |
|---|
| 311 |
( # save in $1 |
|---|
| 312 |
^ # start of line (with /m) |
|---|
| 313 |
<($block_tags_b) # start tag = $2 |
|---|
| 314 |
\\b # word break |
|---|
| 315 |
(.*\\n)*? # any number of lines, minimally matching |
|---|
| 316 |
.*</\\2> # the matching end tag |
|---|
| 317 |
[ \\t]* # trailing spaces/tabs |
|---|
| 318 |
(?=\\n+|\\Z) # followed by a newline or end of document |
|---|
| 319 |
) |
|---|
| 320 |
}xm", |
|---|
| 321 |
'_HashHTMLBlocks_callback', |
|---|
| 322 |
$text); |
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 |
# to make the other regex more complicated. |
|---|
| 326 |
$text = preg_replace_callback('{ |
|---|
| 327 |
(?: |
|---|
| 328 |
(?<=\n\n) # Starting after a blank line |
|---|
| 329 |
| # or |
|---|
| 330 |
\A\n? # the beginning of the doc |
|---|
| 331 |
) |
|---|
| 332 |
( # save in $1 |
|---|
| 333 |
[ ]{0,'.$less_than_tab.'} |
|---|
| 334 |
<(hr) # start tag = $2 |
|---|
| 335 |
\b # word break |
|---|
| 336 |
([^<>])*? # |
|---|
| 337 |
/?> # the matching end tag |
|---|
| 338 |
[ \t]* |
|---|
| 339 |
(?=\n{2,}|\Z) # followed by a blank line or end of document |
|---|
| 340 |
) |
|---|
| 341 |
}x', |
|---|
| 342 |
'_HashHTMLBlocks_callback', |
|---|
| 343 |
$text); |
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
$text = preg_replace_callback('{ |
|---|
| 347 |
(?: |
|---|
| 348 |
(?<=\n\n) # Starting after a blank line |
|---|
| 349 |
| # or |
|---|
| 350 |
\A\n? # the beginning of the doc |
|---|
| 351 |
) |
|---|
| 352 |
( # save in $1 |
|---|
| 353 |
[ ]{0,'.$less_than_tab.'} |
|---|
| 354 |
(?s: |
|---|
| 355 |
<! |
|---|
| 356 |
(--.*?--\s*)+ |
|---|
| 357 |
> |
|---|
| 358 |
) |
|---|
| 359 |
[ \t]* |
|---|
| 360 |
(?=\n{2,}|\Z) # followed by a blank line or end of document |
|---|
| 361 |
) |
|---|
| 362 |
}x', |
|---|
| 363 |
'_HashHTMLBlocks_callback', |
|---|
| 364 |
$text); |
|---|
| 365 |
|
|---|
| 366 |
return $text; |
|---|
| 367 |
} |
|---|
| 368 |
function _HashHTMLBlocks_callback($matches) { |
|---|
| 369 |
global $md_html_blocks; |
|---|
| 370 |
$text = $matches[1]; |
|---|
| 371 |
$key = md5($text); |
|---|
| 372 |
$md_html_blocks[$key] = $text; |
|---|
| 373 |
return "\n\n$key\n\n"; |
|---|
| 374 |
} |
|---|
| 375 |
|
|---|
| 376 |
|
|---|
| 377 |
function _RunBlockGamut($text) { |
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
global $md_empty_element_suffix; |
|---|
| 383 |
|
|---|
| 384 |
$text = _DoHeaders($text); |
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
$text = preg_replace( |
|---|
| 388 |
'{^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$}mx', |
|---|
| 389 |
'{^[ ]{0,2}([ ]? -[ ]?){3,}[ \t]*$}mx', |
|---|
| 390 |
'{^[ ]{0,2}([ ]? _[ ]?){3,}[ \t]*$}mx'), |
|---|
| 391 |
"\n<hr$md_empty_element_suffix\n", |
|---|
| 392 |
$text); |
|---|
| 393 |
|
|---|
| 394 |
$text = _DoLists($text); |
|---|
| 395 |
$text = _DoCodeBlocks($text); |
|---|
| 396 |
$text = _DoBlockQuotes($text); |
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
$text = _HashHTMLBlocks($text); |
|---|
| 403 |
$text = _FormParagraphs($text); |
|---|
| 404 |
|
|---|
| 405 |
$text; |
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
_RunSpanGamut($text) { |
|---|
| 410 |
|
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
global $md_empty_element_suffix; |
|---|
| 415 |
|
|---|
| 416 |
$text = _DoCodeSpans($text); |
|---|
| 417 |
|
|---|
| 418 |
$text = _EscapeSpecialChars($text); |
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
$text = _DoImages($text); |
|---|
| 423 |
$text = _DoAnchors($text); |
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
$text = _DoAutoLinks($text); |
|---|
| 429 |
$text = _EncodeAmpsAndAngles($text); |
|---|
| 430 |
$text = _DoItalicsAndBold($text); |
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
$text = preg_replace('/ {2,}\n/', "<br$md_empty_element_suffix\n", $text); |
|---|
| 434 |
|
|---|
| 435 |
$text; |
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
_EscapeSpecialChars($text) { |
|---|
| 440 |
$md_escape_table; |
|---|
| 441 |
$tokens = _TokenizeHTML($text); |
|---|
| 442 |
|
|---|
| 443 |
$text = ''; |
|---|
| 444 |
|
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
foreach ($tokens as $cur_token) { |
|---|
| 448 |
$cur_token[0] == 'tag') { |
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
$cur_token[1] = str_replace(array('*', '_'), |
|---|
| 456 |
$md_escape_table['*'], $md_escape_table['_']), |
|---|
| 457 |
$cur_token[1]); |
|---|
| 458 |
$text .= $cur_token[1]; |
|---|
| 459 |
|
|---|
| 460 |
$t = $cur_token[1]; |
|---|
| 461 |
$t = _EncodeBackslashEscapes($t); |
|---|
| 462 |
$text .= $t; |
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
$text; |
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
_DoAnchors($text) { |
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
global $md_nested_brackets; |
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
$text = preg_replace_callback("{ |
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
, |
|---|
| 491 |
'_DoAnchors_reference_callback', $text); |
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
$text = preg_replace_callback("{ |
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
|
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
|
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
, |
|---|
| 513 |
'_DoAnchors_inline_callback', $text); |
|---|
| 514 |
|
|---|
| 515 |
$text; |
|---|
| 516 |
|
|---|
| 517 |
_DoAnchors_reference_callback($matches) { |
|---|
| 518 |
$md_urls, $md_titles, $md_escape_table; |
|---|
| 519 |
$whole_match = $matches[1]; |
|---|
| 520 |
$link_text = $matches[2]; |
|---|
| 521 |
$link_id = strtolower($matches[3]); |
|---|
| 522 |
|
|---|
| 523 |
$link_id == "") { |
|---|
| 524 |
$link_id = strtolower($link_text); |
|---|
| 525 |
} |
|---|
| 526 |
|
|---|
| 527 |
$md_urls[$link_id])) { |
|---|
| 528 |
$url = $md_urls[$link_id]; |
|---|
| 529 |
|
|---|
| 530 |
$url = str_replace(array('*', '_'), |
|---|
| 531 |
$md_escape_table['*'], $md_escape_table['_']), |
|---|
| 532 |
$url); |
|---|
| 533 |
$result = "<a href=\"$url\""; |
|---|
| 534 |
$md_titles[$link_id] ) ) { |
|---|
| 535 |
$title = $md_titles[$link_id]; |
|---|
| 536 |
$title = str_replace(array('*', '_'), |
|---|
| 537 |
$md_escape_table['*'], |
|---|
| 538 |
$md_escape_table['_']), $title); |
|---|
| 539 |
$result .= " title=\"$title\""; |
|---|
| 540 |
|
|---|
| 541 |
$result .= ">$link_text</a>"; |
|---|
| 542 |
|
|---|
| 543 |
|
|---|
| 544 |
$result = $whole_match; |
|---|
| 545 |
|
|---|
| 546 |
$result; |
|---|
| 547 |
|
|---|
| 548 |
_DoAnchors_inline_callback($matches) { |
|---|
| 549 |
$md_escape_table; |
|---|
| 550 |
$whole_match = $matches[1]; |
|---|
| 551 |
$link_text = $matches[2]; |
|---|
| 552 |
$url = $matches[3]; |
|---|
| 553 |
$title =& $matches[6]; |
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
$url = str_replace(array('*', '_'), |
|---|
| 557 |
$md_escape_table['*'], $md_escape_table['_']), |
|---|
| 558 |
$url); |
|---|
| 559 |
$result = "<a href=\"$url\""; |
|---|
| 560 |
$title)) { |
|---|
| 561 |
$title = str_replace('"', '"', $title); |
|---|
| 562 |
$title = str_replace(array('*', '_'), |
|---|
| 563 |
$md_escape_table['*'], $md_escape_table['_']), |
|---|
| 564 |
$title); |
|---|
| 565 |
$result .= " title=\"$title\""; |
|---|
| 566 |
|
|---|
| 567 |
|
|---|
| 568 |
$result .= ">$link_text</a>"; |
|---|
| 569 |
|
|---|
| 570 |
$result; |
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
_DoImages($text) { |
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
global $md_nested_brackets; |
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 |
|
|---|
| 582 |
|
|---|
| 583 |
$text = preg_replace_callback('{ |
|---|
| 584 |
|
|---|
| 585 |
|
|---|
| 586 |
.$md_nested_brackets.') # alt text = $2 |
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
|
|---|
| 597 |
, |
|---|
| 598 |
'_DoImages_reference_callback', $text); |
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 |
|
|---|
| 602 |
|
|---|
| 603 |
|
|---|
| 604 |
$text = preg_replace_callback('{ |
|---|
| 605 |
|
|---|
| 606 |
|
|---|
| 607 |
.$md_nested_brackets.') # alt text = $2 |
|---|
| 608 |
|
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 |
|
|---|
| 614 |
|
|---|
| 615 |
|
|---|
| 616 |
|
|---|
| 617 |
|
|---|
| 618 |
|
|---|
| 619 |
|
|---|
| 620 |
|
|---|
| 621 |
, |
|---|
| 622 |
'_DoImages_inline_callback', $text); |
|---|
| 623 |
|
|---|
| 624 |
$text; |
|---|
| 625 |
|
|---|
| 626 |
_DoImages_reference_callback($matches) { |
|---|
| 627 |
$md_urls, $md_titles, $md_empty_element_suffix, $md_escape_table; |
|---|
| 628 |
$whole_match = $matches[1]; |
|---|
| 629 |
$alt_text = $matches[2]; |
|---|
| 630 |
$link_id = strtolower($matches[3]); |
|---|
| 631 |
|
|---|
| 632 |
$link_id == "") { |
|---|
| 633 |
$link_id = strtolower($alt_text); |
|---|
| 634 |
} |
|---|
| 635 |
|
|---|
| 636 |
$alt_text = str_replace('"', '"', $alt_text); |
|---|
| 637 |
$md_urls[$link_id])) { |
|---|
| 638 |
$url = $md_urls[$link_id]; |
|---|
| 639 |
|
|---|
| 640 |
$url = str_replace(array('*', '_'), |
|---|
| 641 |
$md_escape_table['*'], $md_escape_table['_']), |
|---|
| 642 |
$url); |
|---|
| 643 |
$result = "<img src=\"$url\" alt=\"$alt_text\""; |
|---|
| 644 |
$md_titles[$link_id])) { |
|---|
| 645 |
$title = $md_titles[$link_id]; |
|---|
| 646 |
$title = str_replace(array('*', '_'), |
|---|
| 647 |
$md_escape_table['*'], |
|---|
| 648 |
$md_escape_table['_']), $title); |
|---|
| 649 |
$result .= " title=\"$title\""; |
|---|
| 650 |
|
|---|
| 651 |
$result .= $md_empty_element_suffix; |
|---|
| 652 |
|
|---|
| 653 |
|
|---|
| 654 |
|
|---|
| 655 |
$result = $whole_match; |
|---|
| 656 |
|
|---|
| 657 |
|
|---|
| 658 |
$result; |
|---|
| 659 |
|
|---|
| 660 |
_DoImages_inline_callback($matches) { |
|---|
| 661 |
$md_empty_element_suffix, $md_escape_table; |
|---|
| 662 |
$whole_match = $matches[1]; |
|---|
| 663 |
$alt_text = $matches[2]; |
|---|
| 664 |
$url = $matches[3]; |
|---|
| 665 |
$title = ''; |
|---|
| 666 |
$matches[6])) { |
|---|
| 667 |
$title = $matches[6]; |
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
$alt_text = str_replace('"', '"', $alt_text); |
|---|
| 671 |
$title = str_replace('"', '"', $title); |
|---|
| 672 |
|
|---|
| 673 |
$url = str_replace(array('*', '_'), |
|---|
| 674 |
$md_escape_table['*'], $md_escape_table['_']), |
|---|
| 675 |
$url); |
|---|
| 676 |
$result = "<img src=\"$url\" alt=\"$alt_text\""; |
|---|
| 677 |
$title)) { |
|---|
| 678 |
$title = str_replace(array('*', '_'), |
|---|
| 679 |
$md_escape_table['*'], $md_escape_table['_']), |
|---|
| 680 |
$title); |
|---|
| 681 |
$result .= " title=\"$title\""; |
|---|
| 682 |
} |
|---|
| 683 |
$result .= $md_empty_element_suffix; |
|---|
| 684 |
|
|---|
| 685 |
$result; |
|---|
| 686 |
|
|---|
| 687 |
|
|---|
| 688 |
|
|---|
| 689 |
_DoHeaders($text) { |
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
|
|---|
| 697 |
$text = preg_replace( |
|---|
| 698 |
'{ ^(.+)[ \t]*\n=+[ \t]*\n+ }emx', |
|---|
| 699 |
'{ ^(.+)[ \t]*\n-+[ \t]*\n+ }emx'), |
|---|
| 700 |
"'<h1>'._RunSpanGamut(_UnslashQuotes('\\1')).'</h1>\n\n'", |
|---|
| 701 |
"'<h2>'._RunSpanGamut(_UnslashQuotes('\\1')).'</h2>\n\n'"), |
|---|
| 702 |
$text); |
|---|
| 703 |
|
|---|
| 704 |
|
|---|
| 705 |
|
|---|
| 706 |
|
|---|
| 707 |
|
|---|
| 708 |
|
|---|
| 709 |
|
|---|
| 710 |
|
|---|
| 711 |
$text = preg_replace("{ |
|---|
| 712 |
|
|---|
| 713 |
|
|---|
| 714 |
|
|---|
| 715 |
|
|---|
| 716 |
|
|---|
| 717 |
|
|---|
| 718 |
, |
|---|
| 719 |
"'<h'.strlen('\\1').'>'._RunSpanGamut(_UnslashQuotes('\\2')).'</h'.strlen('\\1').'>\n\n'", |
|---|
| 720 |
$text); |
|---|
| 721 |
|
|---|
| 722 |
$text; |
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 |
|
|---|
| 726 |
_DoLists($text) { |
|---|
| 727 |
|
|---|
| 728 |
|
|---|
| 729 |
|
|---|
| 730 |
global $md_tab_width, $md_list_level; |
|---|
| 731 |
$less_than_tab = $md_tab_width - 1; |
|---|
| 732 |
|
|---|
| 733 |
|
|---|
| 734 |
$marker_ul = '[*+-]'; |
|---|
| 735 |
$marker_ol = '\d+[.]'; |
|---|
| 736 |
$marker_any = "(?:$marker_ul|$marker_ol)"; |
|---|
| 737 |
|
|---|
| 738 |
$markers = array($marker_ul, $marker_ol); |
|---|
| 739 |
|
|---|
| 740 |
$markers as $marker) { |
|---|
| 741 |
|
|---|
| 742 |
$whole_list = ' |
|---|
| 743 |
|
|---|
| 744 |
|
|---|
| 745 |
.$less_than_tab.'} |
|---|
| 746 |
.$marker.') # $3 = first list item marker |
|---|
| 747 |
|
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 |
|
|---|
| 752 |
|
|---|
| 753 |
|
|---|
| 754 |
|
|---|
| 755 |
|
|---|
| 756 |
|
|---|
| 757 |
.$marker.'[ \t]+ |
|---|
| 758 |
|
|---|
| 759 |
|
|---|
| 760 |
|
|---|
| 761 |
; |
|---|
| 762 |
|
|---|
| 763 |
|
|---|
| 764 |
|
|---|
| 765 |
|
|---|
| 766 |
if ($md_list_level) { |
|---|
| 767 |
$text = preg_replace_callback('{ |
|---|
| 768 |
|
|---|
| 769 |
.$whole_list.' |
|---|
| 770 |
, |
|---|
| 771 |
'_DoLists_callback_top', $text); |
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 |
$text = preg_replace_callback('{ |
|---|
| 775 |
|
|---|
| 776 |
.$whole_list.' |
|---|
| 777 |
, |
|---|
| 778 |
'_DoLists_callback_nested', $text); |
|---|
| 779 |
|
|---|
| 780 |
|
|---|
| 781 |
|
|---|
| 782 |
$text; |
|---|
| 783 |
|
|---|
| 784 |
_DoLists_callback_top($matches) { |
|---|
| 785 |
|
|---|
| 786 |
$marker_ul = '[*+-]'; |
|---|
| 787 |
$marker_ol = '\d+[.]'; |
|---|
| 788 |
$marker_any = "(?:$marker_ul|$marker_ol)"; |
|---|
| 789 |
|
|---|
| 790 |
$list = $matches[1]; |
|---|
| 791 |
$list_type = preg_match("/$marker_ul/", $matches[3]) ? "ul" : "ol"; |
|---|
| 792 |
|
|---|
| 793 |
$marker_any = ( $list_type == "ul" ? $marker_ul : $marker_ol ); |
|---|
| 794 |
|
|---|
| 795 |
|
|---|
| 796 |
|
|---|
| 797 |
$list = preg_replace("/\n{2,}/", "\n\n\n", $list); |
|---|
| 798 |
$result = _ProcessListItems($list, $marker_any); |
|---|
| 799 |
|
|---|
| 800 |
|
|---|
| 801 |
|
|---|
| 802 |
|
|---|
| 803 |
|
|---|
| 804 |
$result = rtrim($result); |
|---|
| 805 |
$result = "<$list_type>" . $result . "</$list_type>\n"; |
|---|
| 806 |
$result; |
|---|
| 807 |
|
|---|
| 808 |
_DoLists_callback_nested($matches) { |
|---|
| 809 |
|
|---|
| 810 |
$marker_ul = '[*+-]'; |
|---|
| 811 |
$marker_ol = '\d+[.]'; |
|---|
| 812 |
$marker_any = "(?:$marker_ul|$marker_ol)"; |
|---|
| 813 |
|
|---|
| 814 |
$list = $matches[1]; |
|---|
| 815 |
$list_type = preg_match("/$marker_ul/", $matches[3]) ? "ul" : "ol"; |
|---|
| 816 |
|
|---|
| 817 |
$marker_any = ( $list_type == "ul" ? $marker_ul : $marker_ol ); |
|---|
| 818 |
|
|---|
| 819 |
|
|---|
| 820 |
|
|---|
| 821 |
$list = preg_replace("/\n{2,}/", "\n\n\n", $list); |
|---|
| 822 |
$result = _ProcessListItems($list, $marker_any); |
|---|
| 823 |
$result = "<$list_type>\n" . $result . "</$list_type>\n"; |
|---|
| 824 |
$result; |
|---|
| 825 |
|
|---|
| 826 |
|
|---|
| 827 |
|
|---|
| 828 |
_ProcessListItems($list_str, $marker_any) { |
|---|
| 829 |
|
|---|
| 830 |
|
|---|
| 831 |
|
|---|
| 832 |
|
|---|
| 833 |
global $md_list_level; |
|---|
| 834 |
|
|---|
| 835 |
|
|---|
| 836 |
|
|---|
| 837 |
|
|---|
| 838 |
|
|---|
| 839 |
|
|---|
| 840 |
|
|---|
| 841 |
|
|---|
| 842 |
|
|---|
| 843 |
|
|---|
| 844 |
|
|---|
| 845 |
|
|---|
| 846 |
|
|---|
| 847 |
|
|---|
| 848 |
|
|---|
| 849 |
|
|---|
| 850 |
|
|---|
| 851 |
|
|---|
| 852 |
|
|---|
| 853 |
|
|---|
| 854 |
|
|---|
| 855 |
|
|---|
| 856 |
$md_list_level++; |
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 |
$list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str); |
|---|
| 860 |
|
|---|
| 861 |
$list_str = preg_replace_callback('{ |
|---|
| 862 |
|
|---|
| 863 |
|
|---|
| 864 |
.$marker_any.') [ \t]+ # list marker = $3 |
|---|
| 865 |
|
|---|
| 866 |
|
|---|
| 867 |
.$marker_any.') [ \t]+)) |
|---|
| 868 |
, |
|---|
| 869 |
'_ProcessListItems_callback', $list_str); |
|---|
| 870 |
|
|---|
| 871 |
$md_list_level--; |
|---|
| 872 |
$list_str; |
|---|
| 873 |
|
|---|
| 874 |
_ProcessListItems_callback($matches) { |
|---|
| 875 |
$item = $matches[4]; |
|---|
| 876 |
$leading_line =& $matches[1]; |
|---|
| 877 |
$leading_space =& $matches[2]; |
|---|
| 878 |
|
|---|
| 879 |
$leading_line || preg_match('/\n{2,}/', $item)) { |
|---|
| 880 |
$item = _RunBlockGamut(_Outdent($item)); |
|---|
| 881 |
|
|---|
| 882 |
|
|---|
| 883 |
|
|---|
| 884 |
$item = _DoLists(_Outdent($item)); |
|---|
| 885 |
$item = preg_replace('/\n+$/', '', $item); |
|---|
| 886 |
$item = _RunSpanGamut($item); |
|---|
| 887 |
|
|---|
| 888 |
|
|---|
| 889 |
"<li>" . $item . "</li>\n"; |
|---|
| 890 |
|
|---|
| 891 |
|
|---|
| 892 |
|
|---|
| 893 |
_DoCodeBlocks($text) { |
|---|
| 894 |
|
|---|
| 895 |
|
|---|
| 896 |
|
|---|
| 897 |
global $md_tab_width; |
|---|
| 898 |
$text = preg_replace_callback('{ |
|---|
| 899 |
|
|---|
| 900 |
|
|---|
| 901 |
|
|---|
| 902 |
.$md_tab_width.'} | \t) # Lines must start with a tab or a tab-width of spaces |
|---|
| 903 |
|
|---|
| 904 |
|
|---|
| 905 |
|
|---|
| 906 |
.$md_tab_width.'}\S)|\Z) # Lookahead for non-space at line-start, or end of doc |
|---|
| 907 |
, |
|---|
| 908 |
'_DoCodeBlocks_callback', $text); |
|---|
| 909 |
|
|---|
| 910 |
$text; |
|---|
| 911 |
|
|---|
| 912 |
_DoCodeBlocks_callback($matches) { |
|---|
| 913 |
$codeblock = $matches[1]; |
|---|
| 914 |
|
|---|
| 915 |
$codeblock = _EncodeCode(_Outdent($codeblock)); |
|---|
| 916 |
|
|---|
| 917 |
|
|---|
| 918 |
$codeblock = preg_replace(array('/\A\n+/', '/\s+\z/'), '', $codeblock); |
|---|
| 919 |
|
|---|
| 920 |
$result = "\n\n<pre><code>" . $codeblock . "\n</code></pre>\n\n"; |
|---|
| 921 |
|
|---|
| 922 |
$result; |
|---|
| 923 |
|
|---|
| 924 |
|
|---|
| 925 |
|
|---|
| 926 |
_DoCodeSpans($text) { |
|---|
| 927 |
|
|---|
| 928 |
|
|---|
| 929 |
|
|---|
| 930 |
|
|---|
| 931 |
|
|---|
| 932 |
|
|---|
| 933 |
|
|---|
| 934 |
|
|---|
| 935 |
|
|---|
| 936 |
|
|---|
| 937 |
|
|---|
| 938 |
|
|---|
| 939 |
|
|---|
| 940 |
|
|---|
| 941 |
|
|---|
| 942 |
|
|---|
| 943 |
|
|---|
| 944 |
|
|---|
| 945 |
|
|---|
| 946 |
|
|---|
| 947 |
|
|---|
| 948 |
|
|---|
| 949 |
|
|---|
| 950 |
|
|---|
| 951 |
$text = preg_replace_callback('@ |
|---|
| 952 |
|
|---|
| 953 |
|
|---|
| 954 |
|
|---|
| 955 |
|
|---|
| 956 |
|
|---|
| 957 |
|
|---|
| 958 |
, |
|---|
| 959 |
'_DoCodeSpans_callback', $text); |
|---|
| 960 |
|
|---|
| 961 |
$text; |
|---|
| 962 |
|
|---|
| 963 |
_DoCodeSpans_callback($matches) { |
|---|
| 964 |
$c = $matches[2]; |
|---|
| 965 |
$c = preg_replace('/^[ \t]*/', '', $c); |
|---|
| 966 |
$c = preg_replace('/[ \t]*$/', '', $c); |
|---|
| 967 |
$c = _EncodeCode($c); |
|---|
| 968 |
"<code>$c</code>"; |
|---|
| 969 |
|
|---|
| 970 |
|
|---|
| 971 |
|
|---|
| 972 |
_EncodeCode($_) { |
|---|
| 973 |
|
|---|
| 974 |
|
|---|
| 975 |
|
|---|
| 976 |
|
|---|
| 977 |
|
|---|
| 978 |
global $md_escape_table; |
|---|
| 979 |
|
|---|
| 980 |
|
|---|
| 981 |
|
|---|
| 982 |
$_ = str_replace('&', '&', $_); |
|---|
| 983 |
|
|---|
| 984 |
|
|---|
| 985 |
$_ = str_replace(array('<', '>'), |
|---|
| 986 |
'<', '>'), $_); |
|---|
| 987 |
|
|---|
| 988 |
|
|---|
| 989 |
$_ = str_replace(array_keys($md_escape_table), |
|---|
| 990 |
array_values($md_escape_table), $_); |
|---|
| 991 |
|
|---|
| 992 |
$_; |
|---|
| 993 |
|
|---|
| 994 |
|
|---|
| 995 |
|
|---|
| 996 |
_DoItalicsAndBold($text) { |
|---|
| 997 |
|
|---|
| 998 |
$text = preg_replace('{ |
|---|
| 999 |
|
|---|
| 1000 |
|
|---|
| 1001 |
|
|---|
| 1002 |
|
|---|
| 1003 |
|
|---|
| 1004 |
|
|---|
| 1005 |
|
|---|
| 1006 |
|
|---|
| 1007 |
|
|---|
| 1008 |
|
|---|
| 1009 |
|
|---|
| 1010 |
|
|---|
| 1011 |
|
|---|
| 1012 |
|
|---|
| 1013 |
|
|---|
| 1014 |
|
|---|
| 1015 |
|
|---|
| 1016 |
, |
|---|
| 1017 |
'<strong>\2</strong>', $text); |
|---|
| 1018 |
|
|---|
| 1019 |
$text = preg_replace( |
|---|
| 1020 |
'{ ( (?<!\*)\* | (?<!_)_ ) (?=\S) (?! \1) (.+?) (?<=\S) \1 }sx', |
|---|
| 1021 |
'<em>\2</em>', $text); |
|---|
| 1022 |
|
|---|
| 1023 |
$text; |
|---|
| 1024 |
|
|---|
| 1025 |
|
|---|
| 1026 |
|
|---|
| 1027 |
_DoBlockQuotes($text) { |
|---|
| 1028 |
$text = preg_replace_callback('/ |
|---|
| 1029 |
|
|---|
| 1030 |
|
|---|
| 1031 |
|
|---|
| 1032 |
|
|---|
| 1033 |
|
|---|
| 1034 |
|
|---|
| 1035 |
|
|---|
| 1036 |
|
|---|
| 1037 |
, |
|---|
| 1038 |
'_DoBlockQuotes_callback', $text); |
|---|
| 1039 |
|
|---|
| 1040 |
$text; |
|---|
| 1041 |
|
|---|
| 1042 |
_DoBlockQuotes_callback($matches) { |
|---|
| 1043 |
$bq = $matches[1]; |
|---|
| 1044 |
|
|---|
| 1045 |
$bq = preg_replace(array('/^[ \t]*>[ \t]?/m', '/^[ \t]+$/m'), '', $bq); |
|---|
| 1046 |
$bq = _RunBlockGamut($bq); |
|---|
| 1047 |
|
|---|
| 1048 |
$bq = preg_replace('/^/m', " ", $bq); |
|---|
| 1049 |
|
|---|
| 1050 |
$bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx', |
|---|
| 1051 |
'_DoBlockQuotes_callback2', $bq); |
|---|
| 1052 |
|
|---|
| 1053 |
"<blockquote>\n$bq\n</blockquote>\n\n"; |
|---|
| 1054 |
|
|---|
| 1055 |
_DoBlockQuotes_callback2($matches) { |
|---|
| 1056 |
$pre = $matches[1]; |
|---|
| 1057 |
$pre = preg_replace('/^ /m', '', $pre); |
|---|
| 1058 |
$pre; |
|---|
| 1059 |
|
|---|
| 1060 |
|
|---|
| 1061 |
|
|---|
| 1062 |
_FormParagraphs($text) { |
|---|
| 1063 |
|
|---|
| 1064 |
|
|---|
| 1065 |
|
|---|
| 1066 |
|
|---|
| 1067 |
global $md_html_blocks; |
|---|
| 1068 |
|
|---|
| 1069 |
|
|---|
| 1070 |
$text = preg_replace(array('/\A\n+/', '/\n+\z/'), '', $text); |
|---|
| 1071 |
|
|---|
| 1072 |
$grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|---|
| 1073 |
|
|---|
| 1074 |
|
|---|
| 1075 |
|
|---|
| 1076 |
|
|---|
| 1077 |
foreach ($grafs as $key => $value) { |
|---|
| 1078 |
$md_html_blocks[$value] )) { |
|---|
| 1079 |
$value = _RunSpanGamut($value); |
|---|
| 1080 |
$value = preg_replace('/^([ \t]*)/', '<p>', $value); |
|---|
| 1081 |
$value .= "</p>"; |
|---|
| 1082 |
$grafs[$key] = $value; |
|---|
| 1083 |
|
|---|
| 1084 |
|
|---|
| 1085 |
|
|---|
| 1086 |
|
|---|
| 1087 |
|
|---|
| 1088 |
|
|---|
| 1089 |
foreach ($grafs as $key => $value) { |
|---|
| 1090 |
$md_html_blocks[$value] )) { |
|---|
| 1091 |
$grafs[$key] = $md_html_blocks[$value]; |
|---|
| 1092 |
|
|---|
| 1093 |
|
|---|
| 1094 |
|
|---|
| 1095 |
implode("\n\n", $grafs); |
|---|
| 1096 |
|
|---|
| 1097 |
|
|---|
| 1098 |
|
|---|
| 1099 |
_EncodeAmpsAndAngles($text) { |
|---|
| 1100 |
|
|---|
| 1101 |
|
|---|
| 1102 |
|
|---|
| 1103 |
|
|---|
| 1104 |
$text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/', |
|---|
| 1105 |
'&', $text);; |
|---|
| 1106 |
|
|---|
| 1107 |
|
|---|
| 1108 |
$text = preg_replace('{<(?![a-z/?\$!])}i', '<', $text); |
|---|
| 1109 |
|
|---|
| 1110 |
$text; |
|---|
| 1111 |
|
|---|
| 1112 |
|
|---|
| 1113 |
|
|---|
| 1114 |
_EncodeBackslashEscapes($text) { |
|---|
| 1115 |
|
|---|
| 1116 |
|
|---|
| 1117 |
|
|---|
| 1118 |
|
|---|
| 1119 |
|
|---|
| 1120 |
global $md_escape_table, $md_backslash_escape_table; |
|---|
| 1121 |
|
|---|
| 1122 |
return str_replace(array_keys($md_backslash_escape_table), |
|---|
| 1123 |
array_values($md_backslash_escape_table), $text); |
|---|
| 1124 |
|
|---|
| 1125 |
|
|---|
| 1126 |
|
|---|
| 1127 |
_DoAutoLinks($text) { |
|---|
| 1128 |
$text = preg_replace("!<((https?|ftp):[^'\">\\s]+)>!", |
|---|
| 1129 |
'<a href="\1">\1</a>', $text); |
|---|
| 1130 |
|
|---|
| 1131 |
|
|---|
| 1132 |
$text = preg_replace('{ |
|---|
| 1133 |
|
|---|
| 1134 |
|
|---|
| 1135 |
|
|---|
| 1136 |
|
|---|
| 1137 |
|
|---|
| 1138 |
|
|---|
| 1139 |
|
|---|
| 1140 |
|
|---|
| 1141 |
, |
|---|
| 1142 |
"_EncodeEmailAddress(_UnescapeSpecialChars(_UnslashQuotes('\\1')))", |
|---|
| 1143 |
$text); |
|---|
| 1144 |
|
|---|
| 1145 |
$text; |
|---|
| 1146 |
|
|---|
| 1147 |
|
|---|
| 1148 |
|
|---|
| 1149 |
_EncodeEmailAddress($addr) { |
|---|
| 1150 |
|
|---|
| 1151 |
|
|---|
| 1152 |
|
|---|
| 1153 |
|
|---|
| 1154 |
|
|---|
| 1155 |
|
|---|
| 1156 |
|
|---|
| 1157 |
|
|---|
| 1158 |
|
|---|
| 1159 |
|
|---|
| 1160 |
|
|---|
| 1161 |
|
|---|
| 1162 |
|
|---|
| 1163 |
|
|---|
| 1164 |
$addr = "mailto:" . $addr; |
|---|
| 1165 |
$length = strlen($addr); |
|---|
| 1166 |
|
|---|
| 1167 |
|
|---|
| 1168 |
$addr = preg_replace_callback('/([^\:])/', |
|---|
| 1169 |
'_EncodeEmailAddress_callback', $addr); |
|---|
| 1170 |
|
|---|
| 1171 |
$addr = "<a href=\"$addr\">$addr</a>"; |
|---|
| 1172 |
|
|---|
| 1173 |
$addr = preg_replace('/">.+?:/', '">', $addr); |
|---|
| 1174 |
|
|---|
| 1175 |
$addr; |
|---|
| 1176 |
|
|---|
| 1177 |
_EncodeEmailAddress_callback($matches) { |
|---|
| 1178 |
$char = $matches[1]; |
|---|
| 1179 |
$r = rand(0, 100); |
|---|
| 1180 |
|
|---|
| 1181 |
|
|---|
| 1182 |
if ($r > 90 && $char != '@') return $char; |
|---|
| 1183 |
$r < 45) return '&#x'.dechex(ord($char)).';'; |
|---|
| 1184 |
'&#'.ord($char).';'; |
|---|
| 1185 |
|
|---|
| 1186 |
|
|---|
| 1187 |
|
|---|
| 1188 |
_UnescapeSpecialChars($text) { |
|---|
| 1189 |
|
|---|
| 1190 |
|
|---|
| 1191 |
|
|---|
| 1192 |
global $md_escape_table; |
|---|
| 1193 |
str_replace(array_values($md_escape_table), |
|---|
| 1194 |
array_keys($md_escape_table), $text); |
|---|
| 1195 |
|
|---|
| 1196 |
|
|---|
| 1197 |
|
|---|
| 1198 |
|
|---|
| 1199 |
|
|---|
| 1200 |
if (!function_exists('_TokenizeHTML')) : |
|---|
| 1201 |
function _TokenizeHTML($str) { |
|---|
| 1202 |
|
|---|
| 1203 |
|
|---|
| 1204 |
|
|---|
| 1205 |
|
|---|
| 1206 |
|
|---|
| 1207 |
|
|---|
| 1208 |
|
|---|
| 1209 |
|
|---|
| 1210 |
|
|---|
| 1211 |
|
|---|
| 1212 |
|
|---|
| 1213 |
|
|---|
| 1214 |
|
|---|
| 1215 |
|
|---|
| 1216 |
$index = 0; |
|---|
| 1217 |
$tokens = array(); |
|---|
| 1218 |
|
|---|
| 1219 |
$match = '(?s:<!(?:--.*?--\s*)+>)|'. |
|---|
| 1220 |
'(?s:<\?.*?\?>)|'. |
|---|
| 1221 |
|
|---|
| 1222 |
'(?:<[/!$]?[-a-zA-Z0-9:]+\b(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*>)'; |
|---|
| 1223 |
|
|---|
| 1224 |
$parts = preg_split("{($match)}", $str, -1, PREG_SPLIT_DELIM_CAPTURE); |
|---|
| 1225 |
|
|---|
| 1226 |
$parts as $part) { |
|---|
| 1227 |
$index % 2 && $part != '') |
|---|
| 1228 |
$tokens[] = array('text', $part); |
|---|
| 1229 |
|
|---|
| 1230 |
$tokens[] = array('tag', $part); |
|---|
| 1231 |
|
|---|
| 1232 |
|
|---|
| 1233 |
$tokens; |
|---|
| 1234 |
|
|---|
| 1235 |
|
|---|
| 1236 |
|
|---|
| 1237 |
|
|---|
| 1238 |
_Outdent($text) { |
|---|
| 1239 |
|
|---|
| 1240 |
|
|---|
| 1241 |
|
|---|
| 1242 |
global $md_tab_width; |
|---|
| 1243 |
preg_replace("/^(\\t|[ ]{1,$md_tab_width})/m", "", $text); |
|---|
| 1244 |
|
|---|
| 1245 |
|
|---|
| 1246 |
|
|---|
| 1247 |
_Detab($text) { |
|---|
| 1248 |
|
|---|
| 1249 |
|
|---|
| 1250 |
|
|---|
| 1251 |
global $md_tab_width; |
|---|
| 1252 |
|
|---|
| 1253 |
|
|---|
| 1254 |
|
|---|
| 1255 |
|
|---|
| 1256 |
|
|---|
| 1257 |
$lines = explode("\n", $text); |
|---|
| 1258 |
$text = ""; |
|---|
| 1259 |
|
|---|
| 1260 |
$lines as $line) { |
|---|
| 1261 |
|
|---|
| 1262 |
$blocks = explode("\t", $line); |
|---|
| 1263 |
|
|---|
| 1264 |
$line = $blocks[0]; |
|---|
| 1265 |
$blocks[0]); |
|---|
| 1266 |
foreach ($blocks as $block) { |
|---|
| 1267 |
|
|---|
| 1268 |
$amount = $md_tab_width - strlen($line) % $md_tab_width; |
|---|
| 1269 |
$line .= str_repeat(" ", $amount) . $block; |
|---|
| 1270 |
|
|---|
| 1271 |
$text .= "$line\n"; |
|---|
| 1272 |
|
|---|
| 1273 |
$text; |
|---|
| 1274 |
|
|---|
| 1275 |
|
|---|
| 1276 |
|
|---|
| 1277 |
_UnslashQuotes($text) { |
|---|
| 1278 |
|
|---|
| 1279 |
|
|---|
| 1280 |
|
|---|
| 1281 |
|
|---|
| 1282 |
|
|---|
| 1283 |
|
|---|
| 1284 |
|
|---|
| 1285 |
return str_replace('\"', '"', $text); |
|---|
| 1286 |
|
|---|
| 1287 |
|
|---|
| 1288 |
|
|---|
| 1289 |
|
|---|
| 1290 |
|
|---|
| 1291 |
|
|---|
| 1292 |
|
|---|
| 1293 |
|
|---|
| 1294 |
|
|---|
| 1295 |
|
|---|
| 1296 |
|
|---|
| 1297 |
|
|---|
| 1298 |
|
|---|
| 1299 |
|
|---|
| 1300 |
|
|---|
| 1301 |
|
|---|
| 1302 |
|
|---|
| 1303 |
|
|---|
| 1304 |
|
|---|
| 1305 |
|
|---|
| 1306 |
|
|---|
| 1307 |
|
|---|
| 1308 |
|
|---|
| 1309 |
|
|---|
| 1310 |
|
|---|
| 1311 |
|
|---|
| 1312 |
|
|---|
| 1313 |
|
|---|
| 1314 |
|
|---|
| 1315 |
|
|---|
| 1316 |
|
|---|
| 1317 |
|
|---|
| 1318 |
|
|---|
| 1319 |
|
|---|
| 1320 |
|
|---|
| 1321 |
|
|---|
| 1322 |
|
|---|
| 1323 |
|
|---|
| 1324 |
|
|---|
| 1325 |
|
|---|
| 1326 |
|
|---|
| 1327 |
|
|---|
| 1328 |
|
|---|
| 1329 |
|
|---|
| 1330 |
|
|---|
| 1331 |
|
|---|
| 1332 |
|
|---|
| 1333 |
|
|---|
| 1334 |
|
|---|
| 1335 |
|
|---|
| 1336 |
|
|---|
| 1337 |
|
|---|
| 1338 |
|
|---|
| 1339 |
|
|---|
| 1340 |
|
|---|
| 1341 |
|
|---|
| 1342 |
|
|---|
| 1343 |
|
|---|
| 1344 |
|
|---|
| 1345 |
|
|---|
| 1346 |
|
|---|
| 1347 |
|
|---|
| 1348 |
|
|---|
| 1349 |
|
|---|
| 1350 |
|
|---|
| 1351 |
|
|---|
| 1352 |
|
|---|
| 1353 |
|
|---|
| 1354 |
|
|---|
| 1355 |
|
|---|
| 1356 |
|
|---|
| 1357 |
|
|---|
| 1358 |
|
|---|
| 1359 |
|
|---|
| 1360 |
|
|---|
| 1361 |
|
|---|
| 1362 |
|
|---|
| 1363 |
|
|---|
| 1364 |
|
|---|
| 1365 |
|
|---|
| 1366 |
|
|---|
| 1367 |
|
|---|
| 1368 |
|
|---|
| 1369 |
|
|---|
| 1370 |
|
|---|
| 1371 |
|
|---|
| 1372 |
|
|---|
| 1373 |
|
|---|
| 1374 |
|
|---|
| 1375 |
|
|---|
| 1376 |
|
|---|
| 1377 |
|
|---|
| 1378 |
|
|---|
| 1379 |
|
|---|
| 1380 |
|
|---|
| 1381 |
|
|---|
| 1382 |
|
|---|
| 1383 |
|
|---|
| 1384 |
|
|---|
| 1385 |
|
|---|
| 1386 |
|
|---|
| 1387 |
|
|---|
| 1388 |
|
|---|
| 1389 |
|
|---|
| 1390 |
|
|---|
| 1391 |
?> |
|---|
| 1392 |
|
|---|