PageRenderTime 69ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/plugins/Markdown/php/modifier.markdown.php

http://github.com/movabletype/movabletype
PHP | 1405 lines | 836 code | 170 blank | 399 comment | 41 complexity | 0a367caabb9ae36eb3c9d63bf4741e1b MD5 | raw file
Possible License(s): LGPL-2.1, MIT, BSD-3-Clause
  1. <?php
  2. #
  3. # Markdown - A text-to-HTML conversion tool for web writers
  4. #
  5. # Copyright (c) 2004-2005 John Gruber
  6. # <http://daringfireball.net/projects/markdown/>
  7. #
  8. # Copyright (c) 2004-2005 Michel Fortin - PHP Port
  9. # <http://www.michelf.com/projects/php-markdown/>
  10. #
  11. global $MarkdownPHPVersion, $MarkdownSyntaxVersion,
  12. $md_empty_element_suffix, $md_tab_width,
  13. $md_nested_brackets_depth, $md_nested_brackets,
  14. $md_escape_table, $md_backslash_escape_table,
  15. $md_list_level;
  16. $MarkdownPHPVersion = '1.0.1c'; # Fri 9 Dec 2005
  17. $MarkdownSyntaxVersion = '1.0.1'; # Sun 12 Dec 2004
  18. #
  19. # Global default settings:
  20. #
  21. $md_empty_element_suffix = " />"; # Change to ">" for HTML output
  22. $md_tab_width = 4;
  23. #
  24. # WordPress settings:
  25. #
  26. $md_wp_posts = true; # Set to false to remove Markdown from posts.
  27. $md_wp_comments = true; # Set to false to remove Markdown from comments.
  28. # -- WordPress Plugin Interface -----------------------------------------------
  29. /*
  30. Plugin Name: Markdown
  31. Plugin URI: http://www.michelf.com/projects/php-markdown/
  32. 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>
  33. Version: 1.0.1c
  34. Author: Michel Fortin
  35. Author URI: http://www.michelf.com/
  36. */
  37. if (isset($wp_version)) {
  38. # More details about how it works here:
  39. # <http://www.michelf.com/weblog/2005/wordpress-text-flow-vs-markdown/>
  40. # Post content and excerpts
  41. if ($md_wp_posts) {
  42. remove_filter('the_content', 'wpautop');
  43. remove_filter('the_excerpt', 'wpautop');
  44. add_filter('the_content', 'Markdown', 6);
  45. add_filter('get_the_excerpt', 'Markdown', 6);
  46. add_filter('get_the_excerpt', 'trim', 7);
  47. add_filter('the_excerpt', 'md_add_p');
  48. add_filter('the_excerpt_rss', 'md_strip_p');
  49. remove_filter('content_save_pre', 'balanceTags', 50);
  50. remove_filter('excerpt_save_pre', 'balanceTags', 50);
  51. add_filter('the_content', 'balanceTags', 50);
  52. add_filter('get_the_excerpt', 'balanceTags', 9);
  53. function md_add_p($text) {
  54. if (strlen($text) == 0) return;
  55. if (strcasecmp(substr($text, -3), '<p>') == 0) return $text;
  56. return '<p>'.$text.'</p>';
  57. }
  58. function md_strip_p($t) { return preg_replace('{</?[pP]>}', '', $t); }
  59. }
  60. # Comments
  61. if ($md_wp_comments) {
  62. remove_filter('comment_text', 'wpautop');
  63. remove_filter('comment_text', 'make_clickable');
  64. add_filter('pre_comment_content', 'Markdown', 6);
  65. add_filter('pre_comment_content', 'md_hide_tags', 8);
  66. add_filter('pre_comment_content', 'md_show_tags', 12);
  67. add_filter('get_comment_text', 'Markdown', 6);
  68. add_filter('get_comment_excerpt', 'Markdown', 6);
  69. add_filter('get_comment_excerpt', 'md_strip_p', 7);
  70. global $md_hidden_tags;
  71. $md_hidden_tags = array(
  72. '<p>' => md5('<p>'), '</p>' => md5('</p>'),
  73. '<pre>' => md5('<pre>'), '</pre>'=> md5('</pre>'),
  74. '<ol>' => md5('<ol>'), '</ol>' => md5('</ol>'),
  75. '<ul>' => md5('<ul>'), '</ul>' => md5('</ul>'),
  76. '<li>' => md5('<li>'), '</li>' => md5('</li>'),
  77. );
  78. function md_hide_tags($text) {
  79. global $md_hidden_tags;
  80. return str_replace(array_keys($md_hidden_tags),
  81. array_values($md_hidden_tags), $text);
  82. }
  83. function md_show_tags($text) {
  84. global $md_hidden_tags;
  85. return str_replace(array_values($md_hidden_tags),
  86. array_keys($md_hidden_tags), $text);
  87. }
  88. }
  89. }
  90. # -- bBlog Plugin Info --------------------------------------------------------
  91. function identify_modifier_markdown() {
  92. global $MarkdownPHPVersion;
  93. return array(
  94. 'name' => 'markdown',
  95. 'type' => 'modifier',
  96. 'nicename' => 'Markdown',
  97. 'description' => 'A text-to-HTML conversion tool for web writers',
  98. 'authors' => 'Michel Fortin and John Gruber',
  99. 'licence' => 'GPL',
  100. 'version' => $MarkdownPHPVersion,
  101. '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>'
  102. );
  103. }
  104. # -- Smarty Modifier Interface ------------------------------------------------
  105. function smarty_modifier_markdown($text) {
  106. return Markdown($text);
  107. }
  108. # -- Textile Compatibility Mode -----------------------------------------------
  109. # Rename this file to "classTextile.php" and it can replace Textile anywhere.
  110. if (strcasecmp(substr(__FILE__, -16), "classTextile.php") == 0) {
  111. # Try to include PHP SmartyPants. Should be in the same directory.
  112. @include_once 'smartypants.php';
  113. # Fake Textile class. It calls Markdown instead.
  114. class Textile {
  115. function TextileThis($text, $lite='', $encode='', $noimage='', $strict='') {
  116. if ($lite == '' && $encode == '') $text = Markdown($text);
  117. if (function_exists('SmartyPants')) $text = SmartyPants($text);
  118. return $text;
  119. }
  120. }
  121. }
  122. #
  123. # Globals:
  124. #
  125. # Regex to match balanced [brackets].
  126. # Needed to insert a maximum bracked depth while converting to PHP.
  127. $md_nested_brackets_depth = 6;
  128. $md_nested_brackets =
  129. str_repeat('(?>[^\[\]]+|\[', $md_nested_brackets_depth).
  130. str_repeat('\])*', $md_nested_brackets_depth);
  131. # Table of hash values for escaped characters:
  132. $md_escape_table = array(
  133. "\\" => md5("\\"),
  134. "`" => md5("`"),
  135. "*" => md5("*"),
  136. "_" => md5("_"),
  137. "{" => md5("{"),
  138. "}" => md5("}"),
  139. "[" => md5("["),
  140. "]" => md5("]"),
  141. "(" => md5("("),
  142. ")" => md5(")"),
  143. ">" => md5(">"),
  144. "#" => md5("#"),
  145. "+" => md5("+"),
  146. "-" => md5("-"),
  147. "." => md5("."),
  148. "!" => md5("!")
  149. );
  150. # Create an identical table but for escaped characters.
  151. $md_backslash_escape_table;
  152. foreach ($md_escape_table as $key => $char)
  153. $md_backslash_escape_table["\\$key"] = $char;
  154. function Markdown($text) {
  155. #
  156. # Main function. The order in which other subs are called here is
  157. # essential. Link and image substitutions need to happen before
  158. # _EscapeSpecialCharsWithinTagAttributes(), so that any *'s or _'s in the <a>
  159. # and <img> tags get encoded.
  160. #
  161. # Clear the global hashes. If we don't clear these, you get conflicts
  162. # from other articles when generating a page which contains more than
  163. # one article (e.g. an index page that shows the N most recent
  164. # articles):
  165. global $md_urls, $md_titles, $md_html_blocks;
  166. $md_urls = array();
  167. $md_titles = array();
  168. $md_html_blocks = array();
  169. # Standardize line endings:
  170. # DOS to Unix and Mac to Unix
  171. $text = str_replace(array("\r\n", "\r"), "\n", $text);
  172. # Make sure $text ends with a couple of newlines:
  173. $text .= "\n\n";
  174. # Convert all tabs to spaces.
  175. $text = _Detab($text);
  176. # Strip any lines consisting only of spaces and tabs.
  177. # This makes subsequent regexen easier to write, because we can
  178. # match consecutive blank lines with /\n+/ instead of something
  179. # contorted like /[ \t]*\n+/ .
  180. $text = preg_replace('/^[ \t]+$/m', '', $text);
  181. # Turn block-level HTML blocks into hash entries
  182. $text = _HashHTMLBlocks($text);
  183. # Strip link definitions, store in hashes.
  184. $text = _StripLinkDefinitions($text);
  185. $text = _RunBlockGamut($text);
  186. $text = _UnescapeSpecialChars($text);
  187. return $text . "\n";
  188. }
  189. function _StripLinkDefinitions($text) {
  190. #
  191. # Strips link definitions from text, stores the URLs and titles in
  192. # hash references.
  193. #
  194. global $md_tab_width;
  195. $less_than_tab = $md_tab_width - 1;
  196. # Link defs are in the form: ^[id]: url "optional title"
  197. $text = preg_replace_callback('{
  198. ^[ ]{0,'.$less_than_tab.'}\[(.+)\]: # id = $1
  199. [ \t]*
  200. \n? # maybe *one* newline
  201. [ \t]*
  202. <?(\S+?)>? # url = $2
  203. [ \t]*
  204. \n? # maybe one newline
  205. [ \t]*
  206. (?:
  207. (?<=\s) # lookbehind for whitespace
  208. ["(]
  209. (.+?) # title = $3
  210. [")]
  211. [ \t]*
  212. )? # title is optional
  213. (?:\n+|\Z)
  214. }xm',
  215. '_StripLinkDefinitions_callback',
  216. $text);
  217. return $text;
  218. }
  219. function _StripLinkDefinitions_callback($matches) {
  220. global $md_urls, $md_titles;
  221. $link_id = strtolower($matches[1]);
  222. $md_urls[$link_id] = _EncodeAmpsAndAngles($matches[2]);
  223. if (isset($matches[3]))
  224. $md_titles[$link_id] = str_replace('"', '&quot;', $matches[3]);
  225. return ''; # String that will replace the block
  226. }
  227. function _HashHTMLBlocks($text) {
  228. global $md_tab_width;
  229. $less_than_tab = $md_tab_width - 1;
  230. # Hashify HTML blocks:
  231. # We only want to do this for block-level HTML tags, such as headers,
  232. # lists, and tables. That's because we still want to wrap <p>s around
  233. # "paragraphs" that are wrapped in non-block-level tags, such as anchors,
  234. # phrase emphasis, and spans. The list of tags we're looking for is
  235. # hard-coded:
  236. $block_tags_a = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|'.
  237. 'script|noscript|form|fieldset|iframe|math|ins|del';
  238. $block_tags_b = 'p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|'.
  239. 'script|noscript|form|fieldset|iframe|math';
  240. # First, look for nested blocks, e.g.:
  241. # <div>
  242. # <div>
  243. # tags for inner block must be indented.
  244. # </div>
  245. # </div>
  246. #
  247. # The outermost tags must start at the left margin for this to match, and
  248. # the inner nested divs must be indented.
  249. # We need to do this before the next, more liberal match, because the next
  250. # match will start at the first `<div>` and stop at the first `</div>`.
  251. $text = preg_replace_callback("{
  252. ( # save in $1
  253. ^ # start of line (with /m)
  254. <($block_tags_a) # start tag = $2
  255. \\b # word break
  256. (.*\\n)*? # any number of lines, minimally matching
  257. </\\2> # the matching end tag
  258. [ \\t]* # trailing spaces/tabs
  259. (?=\\n+|\\Z) # followed by a newline or end of document
  260. )
  261. }xm",
  262. '_HashHTMLBlocks_callback',
  263. $text);
  264. #
  265. # Now match more liberally, simply from `\n<tag>` to `</tag>\n`
  266. #
  267. $text = preg_replace_callback("{
  268. ( # save in $1
  269. ^ # start of line (with /m)
  270. <($block_tags_b) # start tag = $2
  271. \\b # word break
  272. (.*\\n)*? # any number of lines, minimally matching
  273. .*</\\2> # the matching end tag
  274. [ \\t]* # trailing spaces/tabs
  275. (?=\\n+|\\Z) # followed by a newline or end of document
  276. )
  277. }xm",
  278. '_HashHTMLBlocks_callback',
  279. $text);
  280. # Special case just for <hr />. It was easier to make a special case than
  281. # to make the other regex more complicated.
  282. $text = preg_replace_callback('{
  283. (?:
  284. (?<=\n\n) # Starting after a blank line
  285. | # or
  286. \A\n? # the beginning of the doc
  287. )
  288. ( # save in $1
  289. [ ]{0,'.$less_than_tab.'}
  290. <(hr) # start tag = $2
  291. \b # word break
  292. ([^<>])*? #
  293. /?> # the matching end tag
  294. [ \t]*
  295. (?=\n{2,}|\Z) # followed by a blank line or end of document
  296. )
  297. }x',
  298. '_HashHTMLBlocks_callback',
  299. $text);
  300. # Special case for standalone HTML comments:
  301. $text = preg_replace_callback('{
  302. (?:
  303. (?<=\n\n) # Starting after a blank line
  304. | # or
  305. \A\n? # the beginning of the doc
  306. )
  307. ( # save in $1
  308. [ ]{0,'.$less_than_tab.'}
  309. (?s:
  310. <!
  311. (--.*?--\s*)+
  312. >
  313. )
  314. [ \t]*
  315. (?=\n{2,}|\Z) # followed by a blank line or end of document
  316. )
  317. }x',
  318. '_HashHTMLBlocks_callback',
  319. $text);
  320. return $text;
  321. }
  322. function _HashHTMLBlocks_callback($matches) {
  323. global $md_html_blocks;
  324. $text = $matches[1];
  325. $key = md5($text);
  326. $md_html_blocks[$key] = $text;
  327. return "\n\n$key\n\n"; # String that will replace the block
  328. }
  329. function _RunBlockGamut($text) {
  330. #
  331. # These are all the transformations that form block-level
  332. # tags like paragraphs, headers, and list items.
  333. #
  334. global $md_empty_element_suffix;
  335. $text = _DoHeaders($text);
  336. # Do Horizontal Rules:
  337. $text = preg_replace(
  338. array('{^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$}mx',
  339. '{^[ ]{0,2}([ ]? -[ ]?){3,}[ \t]*$}mx',
  340. '{^[ ]{0,2}([ ]? _[ ]?){3,}[ \t]*$}mx'),
  341. "\n<hr$md_empty_element_suffix\n",
  342. $text);
  343. $text = _DoLists($text);
  344. $text = _DoCodeBlocks($text);
  345. $text = _DoBlockQuotes($text);
  346. # We already ran _HashHTMLBlocks() before, in Markdown(), but that
  347. # was to escape raw HTML in the original Markdown source. This time,
  348. # we're escaping the markup we've just created, so that we don't wrap
  349. # <p> tags around block-level tags.
  350. $text = _HashHTMLBlocks($text);
  351. $text = _FormParagraphs($text);
  352. return $text;
  353. }
  354. function _RunSpanGamut($text) {
  355. #
  356. # These are all the transformations that occur *within* block-level
  357. # tags like paragraphs, headers, and list items.
  358. #
  359. global $md_empty_element_suffix;
  360. $text = _DoCodeSpans($text);
  361. $text = _EscapeSpecialChars($text);
  362. # Process anchor and image tags. Images must come first,
  363. # because ![foo][f] looks like an anchor.
  364. $text = _DoImages($text);
  365. $text = _DoAnchors($text);
  366. # Make links out of things like `<http://example.com/>`
  367. # Must come after _DoAnchors(), because you can use < and >
  368. # delimiters in inline links like [this](<url>).
  369. $text = _DoAutoLinks($text);
  370. $text = _EncodeAmpsAndAngles($text);
  371. $text = _DoItalicsAndBold($text);
  372. # Do hard breaks:
  373. $text = preg_replace('/ {2,}\n/', "<br$md_empty_element_suffix\n", $text);
  374. return $text;
  375. }
  376. function _EscapeSpecialChars($text) {
  377. global $md_escape_table;
  378. $tokens = _TokenizeHTML($text);
  379. $text = ''; # rebuild $text from the tokens
  380. # $in_pre = 0; # Keep track of when we're inside <pre> or <code> tags.
  381. # $tags_to_skip = "!<(/?)(?:pre|code|kbd|script|math)[\s>]!";
  382. foreach ($tokens as $cur_token) {
  383. if ($cur_token[0] == 'tag') {
  384. # Within tags, encode * and _ so they don't conflict
  385. # with their use in Markdown for italics and strong.
  386. # We're replacing each such character with its
  387. # corresponding MD5 checksum value; this is likely
  388. # overkill, but it should prevent us from colliding
  389. # with the escape values by accident.
  390. $cur_token[1] = str_replace(array('*', '_'),
  391. array($md_escape_table['*'], $md_escape_table['_']),
  392. $cur_token[1]);
  393. $text .= $cur_token[1];
  394. } else {
  395. $t = $cur_token[1];
  396. $t = _EncodeBackslashEscapes($t);
  397. $text .= $t;
  398. }
  399. }
  400. return $text;
  401. }
  402. function _DoAnchors($text) {
  403. #
  404. # Turn Markdown link shortcuts into XHTML <a> tags.
  405. #
  406. global $md_nested_brackets;
  407. #
  408. # First, handle reference-style links: [link text] [id]
  409. #
  410. $text = preg_replace_callback("{
  411. ( # wrap whole match in $1
  412. \\[
  413. ($md_nested_brackets) # link text = $2
  414. \\]
  415. [ ]? # one optional space
  416. (?:\\n[ ]*)? # one optional newline followed by spaces
  417. \\[
  418. (.*?) # id = $3
  419. \\]
  420. )
  421. }xs",
  422. '_DoAnchors_reference_callback', $text);
  423. #
  424. # Next, inline-style links: [link text](url "optional title")
  425. #
  426. $text = preg_replace_callback("{
  427. ( # wrap whole match in $1
  428. \\[
  429. ($md_nested_brackets) # link text = $2
  430. \\]
  431. \\( # literal paren
  432. [ \\t]*
  433. <?(.*?)>? # href = $3
  434. [ \\t]*
  435. ( # $4
  436. (['\"]) # quote char = $5
  437. (.*?) # Title = $6
  438. \\5 # matching quote
  439. )? # title is optional
  440. \\)
  441. )
  442. }xs",
  443. '_DoAnchors_inline_callback', $text);
  444. return $text;
  445. }
  446. function _DoAnchors_reference_callback($matches) {
  447. global $md_urls, $md_titles, $md_escape_table;
  448. $whole_match = $matches[1];
  449. $link_text = $matches[2];
  450. $link_id = strtolower($matches[3]);
  451. if ($link_id == "") {
  452. $link_id = strtolower($link_text); # for shortcut links like [this][].
  453. }
  454. if (isset($md_urls[$link_id])) {
  455. $url = $md_urls[$link_id];
  456. # We've got to encode these to avoid conflicting with italics/bold.
  457. $url = str_replace(array('*', '_'),
  458. array($md_escape_table['*'], $md_escape_table['_']),
  459. $url);
  460. $result = "<a href=\"$url\"";
  461. if ( isset( $md_titles[$link_id] ) ) {
  462. $title = $md_titles[$link_id];
  463. $title = str_replace(array('*', '_'),
  464. array($md_escape_table['*'],
  465. $md_escape_table['_']), $title);
  466. $result .= " title=\"$title\"";
  467. }
  468. $result .= ">$link_text</a>";
  469. }
  470. else {
  471. $result = $whole_match;
  472. }
  473. return $result;
  474. }
  475. function _DoAnchors_inline_callback($matches) {
  476. global $md_escape_table;
  477. $whole_match = $matches[1];
  478. $link_text = $matches[2];
  479. $url = $matches[3];
  480. $title =& $matches[6];
  481. # We've got to encode these to avoid conflicting with italics/bold.
  482. $url = str_replace(array('*', '_'),
  483. array($md_escape_table['*'], $md_escape_table['_']),
  484. $url);
  485. $result = "<a href=\"$url\"";
  486. if (isset($title)) {
  487. $title = str_replace('"', '&quot;', $title);
  488. $title = str_replace(array('*', '_'),
  489. array($md_escape_table['*'], $md_escape_table['_']),
  490. $title);
  491. $result .= " title=\"$title\"";
  492. }
  493. $result .= ">$link_text</a>";
  494. return $result;
  495. }
  496. function _DoImages($text) {
  497. #
  498. # Turn Markdown image shortcuts into <img> tags.
  499. #
  500. global $md_nested_brackets;
  501. #
  502. # First, handle reference-style labeled images: ![alt text][id]
  503. #
  504. $text = preg_replace_callback('{
  505. ( # wrap whole match in $1
  506. !\[
  507. ('.$md_nested_brackets.') # alt text = $2
  508. \]
  509. [ ]? # one optional space
  510. (?:\n[ ]*)? # one optional newline followed by spaces
  511. \[
  512. (.*?) # id = $3
  513. \]
  514. )
  515. }xs',
  516. '_DoImages_reference_callback', $text);
  517. #
  518. # Next, handle inline images: ![alt text](url "optional title")
  519. # Don't forget: encode * and _
  520. $text = preg_replace_callback('{
  521. ( # wrap whole match in $1
  522. !\[
  523. ('.$md_nested_brackets.') # alt text = $2
  524. \]
  525. \( # literal paren
  526. [ \t]*
  527. <?(\S+?)>? # src url = $3
  528. [ \t]*
  529. ( # $4
  530. ([\'"]) # quote char = $5
  531. (.*?) # title = $6
  532. \5 # matching quote
  533. [ \t]*
  534. )? # title is optional
  535. \)
  536. )
  537. }xs',
  538. '_DoImages_inline_callback', $text);
  539. return $text;
  540. }
  541. function _DoImages_reference_callback($matches) {
  542. global $md_urls, $md_titles, $md_empty_element_suffix, $md_escape_table;
  543. $whole_match = $matches[1];
  544. $alt_text = $matches[2];
  545. $link_id = strtolower($matches[3]);
  546. if ($link_id == "") {
  547. $link_id = strtolower($alt_text); # for shortcut links like ![this][].
  548. }
  549. $alt_text = str_replace('"', '&quot;', $alt_text);
  550. if (isset($md_urls[$link_id])) {
  551. $url = $md_urls[$link_id];
  552. # We've got to encode these to avoid conflicting with italics/bold.
  553. $url = str_replace(array('*', '_'),
  554. array($md_escape_table['*'], $md_escape_table['_']),
  555. $url);
  556. $result = "<img src=\"$url\" alt=\"$alt_text\"";
  557. if (isset($md_titles[$link_id])) {
  558. $title = $md_titles[$link_id];
  559. $title = str_replace(array('*', '_'),
  560. array($md_escape_table['*'],
  561. $md_escape_table['_']), $title);
  562. $result .= " title=\"$title\"";
  563. }
  564. $result .= $md_empty_element_suffix;
  565. }
  566. else {
  567. # If there's no such link ID, leave intact:
  568. $result = $whole_match;
  569. }
  570. return $result;
  571. }
  572. function _DoImages_inline_callback($matches) {
  573. global $md_empty_element_suffix, $md_escape_table;
  574. $whole_match = $matches[1];
  575. $alt_text = $matches[2];
  576. $url = $matches[3];
  577. $title = '';
  578. if (isset($matches[6])) {
  579. $title = $matches[6];
  580. }
  581. $alt_text = str_replace('"', '&quot;', $alt_text);
  582. $title = str_replace('"', '&quot;', $title);
  583. # We've got to encode these to avoid conflicting with italics/bold.
  584. $url = str_replace(array('*', '_'),
  585. array($md_escape_table['*'], $md_escape_table['_']),
  586. $url);
  587. $result = "<img src=\"$url\" alt=\"$alt_text\"";
  588. if (isset($title)) {
  589. $title = str_replace(array('*', '_'),
  590. array($md_escape_table['*'], $md_escape_table['_']),
  591. $title);
  592. $result .= " title=\"$title\""; # $title already quoted
  593. }
  594. $result .= $md_empty_element_suffix;
  595. return $result;
  596. }
  597. function _DoHeaders($text) {
  598. # Setext-style headers:
  599. # Header 1
  600. # ========
  601. #
  602. # Header 2
  603. # --------
  604. #
  605. $text = preg_replace_callback(
  606. '{ ^(.+)[ \t]*\n=+[ \t]*\n+ }mx',
  607. function($m){
  608. return '<h1>'._RunSpanGamut(_UnslashQuotes($m[1]))."</h1>\n\n";
  609. },
  610. $text
  611. );
  612. $text = preg_replace_callback(
  613. '{ ^(.+)[ \t]*\n-+[ \t]*\n+ }mx',
  614. function($m){
  615. return '<h2>'._RunSpanGamut(_UnslashQuotes($m[1]))."</h2>\n\n";
  616. },
  617. $text
  618. );
  619. # atx-style headers:
  620. # # Header 1
  621. # ## Header 2
  622. # ## Header 2 with closing hashes ##
  623. # ...
  624. # ###### Header 6
  625. #
  626. $text = preg_replace_callback("{
  627. ^(\\#{1,6}) # $1 = string of #'s
  628. [ \\t]*
  629. (.+?) # $2 = Header text
  630. [ \\t]*
  631. \\#* # optional closing #'s (not counted)
  632. \\n+
  633. }xm",
  634. function($m){
  635. return '<h'.strlen($m[1]).'>'._RunSpanGamut(_UnslashQuotes($m[2])).'</h'.strlen($m[1]).">\n\n";
  636. },
  637. $text
  638. );
  639. return $text;
  640. }
  641. function _DoLists($text) {
  642. #
  643. # Form HTML ordered (numbered) and unordered (bulleted) lists.
  644. #
  645. global $md_tab_width, $md_list_level;
  646. $less_than_tab = $md_tab_width - 1;
  647. # Re-usable patterns to match list item bullets and number markers:
  648. $marker_ul = '[*+-]';
  649. $marker_ol = '\d+[.]';
  650. $marker_any = "(?:$marker_ul|$marker_ol)";
  651. $markers = array($marker_ul, $marker_ol);
  652. foreach ($markers as $marker) {
  653. # Re-usable pattern to match any entirel ul or ol list:
  654. $whole_list = '
  655. ( # $1 = whole list
  656. ( # $2
  657. [ ]{0,'.$less_than_tab.'}
  658. ('.$marker.') # $3 = first list item marker
  659. [ \t]+
  660. )
  661. (?s:.+?)
  662. ( # $4
  663. \z
  664. |
  665. \n{2,}
  666. (?=\S)
  667. (?! # Negative lookahead for another list item marker
  668. [ \t]*
  669. '.$marker.'[ \t]+
  670. )
  671. )
  672. )
  673. '; // mx
  674. # We use a different prefix before nested lists than top-level lists.
  675. # See extended comment in _ProcessListItems().
  676. if ($md_list_level) {
  677. $text = preg_replace_callback('{
  678. ^
  679. '.$whole_list.'
  680. }mx',
  681. '_DoLists_callback_top', $text);
  682. }
  683. else {
  684. $text = preg_replace_callback('{
  685. (?:(?<=\n\n)|\A\n?)
  686. '.$whole_list.'
  687. }mx',
  688. '_DoLists_callback_nested', $text);
  689. }
  690. }
  691. return $text;
  692. }
  693. function _DoLists_callback_top($matches) {
  694. # Re-usable patterns to match list item bullets and number markers:
  695. $marker_ul = '[*+-]';
  696. $marker_ol = '\d+[.]';
  697. $marker_any = "(?:$marker_ul|$marker_ol)";
  698. $list = $matches[1];
  699. $list_type = preg_match("/$marker_ul/", $matches[3]) ? "ul" : "ol";
  700. $marker_any = ( $list_type == "ul" ? $marker_ul : $marker_ol );
  701. # Turn double returns into triple returns, so that we can make a
  702. # paragraph for the last item in a list, if necessary:
  703. $list = preg_replace("/\n{2,}/", "\n\n\n", $list);
  704. $result = _ProcessListItems($list, $marker_any);
  705. # Trim any trailing whitespace, to put the closing `</$list_type>`
  706. # up on the preceding line, to get it past the current stupid
  707. # HTML block parser. This is a hack to work around the terrible
  708. # hack that is the HTML block parser.
  709. $result = rtrim($result);
  710. $result = "<$list_type>" . $result . "</$list_type>\n";
  711. return $result;
  712. }
  713. function _DoLists_callback_nested($matches) {
  714. # Re-usable patterns to match list item bullets and number markers:
  715. $marker_ul = '[*+-]';
  716. $marker_ol = '\d+[.]';
  717. $marker_any = "(?:$marker_ul|$marker_ol)";
  718. $list = $matches[1];
  719. $list_type = preg_match("/$marker_ul/", $matches[3]) ? "ul" : "ol";
  720. $marker_any = ( $list_type == "ul" ? $marker_ul : $marker_ol );
  721. # Turn double returns into triple returns, so that we can make a
  722. # paragraph for the last item in a list, if necessary:
  723. $list = preg_replace("/\n{2,}/", "\n\n\n", $list);
  724. $result = _ProcessListItems($list, $marker_any);
  725. $result = "<$list_type>\n" . $result . "</$list_type>\n";
  726. return $result;
  727. }
  728. function _ProcessListItems($list_str, $marker_any) {
  729. #
  730. # Process the contents of a single ordered or unordered list, splitting it
  731. # into individual list items.
  732. #
  733. global $md_list_level;
  734. # The $md_list_level global keeps track of when we're inside a list.
  735. # Each time we enter a list, we increment it; when we leave a list,
  736. # we decrement. If it's zero, we're not in a list anymore.
  737. #
  738. # We do this because when we're not inside a list, we want to treat
  739. # something like this:
  740. #
  741. # I recommend upgrading to version
  742. # 8. Oops, now this line is treated
  743. # as a sub-list.
  744. #
  745. # As a single paragraph, despite the fact that the second line starts
  746. # with a digit-period-space sequence.
  747. #
  748. # Whereas when we're inside a list (or sub-list), that line will be
  749. # treated as the start of a sub-list. What a kludge, huh? This is
  750. # an aspect of Markdown's syntax that's hard to parse perfectly
  751. # without resorting to mind-reading. Perhaps the solution is to
  752. # change the syntax rules such that sub-lists must start with a
  753. # starting cardinal number; e.g. "1." or "a.".
  754. $md_list_level++;
  755. # trim trailing blank lines:
  756. $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str);
  757. $list_str = preg_replace_callback('{
  758. (\n)? # leading line = $1
  759. (^[ \t]*) # leading whitespace = $2
  760. ('.$marker_any.') [ \t]+ # list marker = $3
  761. ((?s:.+?) # list item text = $4
  762. (\n{1,2}))
  763. (?= \n* (\z | \2 ('.$marker_any.') [ \t]+))
  764. }xm',
  765. '_ProcessListItems_callback', $list_str);
  766. $md_list_level--;
  767. return $list_str;
  768. }
  769. function _ProcessListItems_callback($matches) {
  770. $item = $matches[4];
  771. $leading_line =& $matches[1];
  772. $leading_space =& $matches[2];
  773. if ($leading_line || preg_match('/\n{2,}/', $item)) {
  774. $item = _RunBlockGamut(_Outdent($item));
  775. }
  776. else {
  777. # Recursion for sub-lists:
  778. $item = _DoLists(_Outdent($item));
  779. $item = preg_replace('/\n+$/', '', $item);
  780. $item = _RunSpanGamut($item);
  781. }
  782. return "<li>" . $item . "</li>\n";
  783. }
  784. function _DoCodeBlocks($text) {
  785. #
  786. # Process Markdown `<pre><code>` blocks.
  787. #
  788. global $md_tab_width;
  789. $text = preg_replace_callback('{
  790. (?:\n\n|\A)
  791. ( # $1 = the code block -- one or more lines, starting with a space/tab
  792. (?:
  793. (?:[ ]{'.$md_tab_width.'} | \t) # Lines must start with a tab or a tab-width of spaces
  794. .*\n+
  795. )+
  796. )
  797. ((?=^[ ]{0,'.$md_tab_width.'}\S)|\Z) # Lookahead for non-space at line-start, or end of doc
  798. }xm',
  799. '_DoCodeBlocks_callback', $text);
  800. return $text;
  801. }
  802. function _DoCodeBlocks_callback($matches) {
  803. $codeblock = $matches[1];
  804. $codeblock = _EncodeCode(_Outdent($codeblock));
  805. // $codeblock = _Detab($codeblock);
  806. # trim leading newlines and trailing whitespace
  807. $codeblock = preg_replace(array('/\A\n+/', '/\s+\z/'), '', $codeblock);
  808. $result = "\n\n<pre><code>" . $codeblock . "\n</code></pre>\n\n";
  809. return $result;
  810. }
  811. function _DoCodeSpans($text) {
  812. #
  813. # * Backtick quotes are used for <code></code> spans.
  814. #
  815. # * You can use multiple backticks as the delimiters if you want to
  816. # include literal backticks in the code span. So, this input:
  817. #
  818. # Just type ``foo `bar` baz`` at the prompt.
  819. #
  820. # Will translate to:
  821. #
  822. # <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
  823. #
  824. # There's no arbitrary limit to the number of backticks you
  825. # can use as delimters. If you need three consecutive backticks
  826. # in your code, use four for delimiters, etc.
  827. #
  828. # * You can use spaces to get literal backticks at the edges:
  829. #
  830. # ... type `` `bar` `` ...
  831. #
  832. # Turns to:
  833. #
  834. # ... type <code>`bar`</code> ...
  835. #
  836. $text = preg_replace_callback('@
  837. (?<!\\\) # Character before opening ` can\'t be a backslash
  838. (`+) # $1 = Opening run of `
  839. (.+?) # $2 = The code block
  840. (?<!`)
  841. \1 # Matching closer
  842. (?!`)
  843. @xs',
  844. '_DoCodeSpans_callback', $text);
  845. return $text;
  846. }
  847. function _DoCodeSpans_callback($matches) {
  848. $c = $matches[2];
  849. $c = preg_replace('/^[ \t]*/', '', $c); # leading whitespace
  850. $c = preg_replace('/[ \t]*$/', '', $c); # trailing whitespace
  851. $c = _EncodeCode($c);
  852. return "<code>$c</code>";
  853. }
  854. function _EncodeCode($_) {
  855. #
  856. # Encode/escape certain characters inside Markdown code runs.
  857. # The point is that in code, these characters are literals,
  858. # and lose their special Markdown meanings.
  859. #
  860. global $md_escape_table;
  861. # Encode all ampersands; HTML entities are not
  862. # entities within a Markdown code span.
  863. $_ = str_replace('&', '&amp;', $_);
  864. # Do the angle bracket song and dance:
  865. $_ = str_replace(array('<', '>'),
  866. array('&lt;', '&gt;'), $_);
  867. # Now, escape characters that are magic in Markdown:
  868. $_ = str_replace(array_keys($md_escape_table),
  869. array_values($md_escape_table), $_);
  870. return $_;
  871. }
  872. function _DoItalicsAndBold($text) {
  873. # <strong> must go first:
  874. $text = preg_replace('{
  875. ( # $1: Marker
  876. (?<!\*\*) \*\* | # (not preceded by two chars of
  877. (?<!__) __ # the same marker)
  878. )
  879. (?=\S) # Not followed by whitespace
  880. (?!\1) # or two others marker chars.
  881. ( # $2: Content
  882. (?:
  883. [^*_]+? # Anthing not em markers.
  884. |
  885. # Balence any regular emphasis inside.
  886. ([*_]) (?=\S) .+? (?<=\S) \3 # $3: em char (* or _)
  887. |
  888. (?! \1 ) . # Allow unbalenced * and _.
  889. )+?
  890. )
  891. (?<=\S) \1 # End mark not preceded by whitespace.
  892. }sx',
  893. '<strong>\2</strong>', $text);
  894. # Then <em>:
  895. $text = preg_replace(
  896. '{ ( (?<!\*)\* | (?<!_)_ ) (?=\S) (?! \1) (.+?) (?<=\S) \1 }sx',
  897. '<em>\2</em>', $text);
  898. return $text;
  899. }
  900. function _DoBlockQuotes($text) {
  901. $text = preg_replace_callback('/
  902. ( # Wrap whole match in $1
  903. (
  904. ^[ \t]*>[ \t]? # ">" at the start of a line
  905. .+\n # rest of the first line
  906. (.+\n)* # subsequent consecutive lines
  907. \n* # blanks
  908. )+
  909. )
  910. /xm',
  911. '_DoBlockQuotes_callback', $text);
  912. return $text;
  913. }
  914. function _DoBlockQuotes_callback($matches) {
  915. $bq = $matches[1];
  916. # trim one level of quoting - trim whitespace-only lines
  917. $bq = preg_replace(array('/^[ \t]*>[ \t]?/m', '/^[ \t]+$/m'), '', $bq);
  918. $bq = _RunBlockGamut($bq); # recurse
  919. $bq = preg_replace('/^/m', " ", $bq);
  920. # These leading spaces screw with <pre> content, so we need to fix that:
  921. $bq = preg_replace_callback('{(\s*<pre>.+?</pre>)}sx',
  922. '_DoBlockQuotes_callback2', $bq);
  923. return "<blockquote>\n$bq\n</blockquote>\n\n";
  924. }
  925. function _DoBlockQuotes_callback2($matches) {
  926. $pre = $matches[1];
  927. $pre = preg_replace('/^ /m', '', $pre);
  928. return $pre;
  929. }
  930. function _FormParagraphs($text) {
  931. #
  932. # Params:
  933. # $text - string to process with html <p> tags
  934. #
  935. global $md_html_blocks;
  936. # Strip leading and trailing lines:
  937. $text = preg_replace(array('/\A\n+/', '/\n+\z/'), '', $text);
  938. $grafs = preg_split('/\n{2,}/', $text, -1, PREG_SPLIT_NO_EMPTY);
  939. #
  940. # Wrap <p> tags.
  941. #
  942. foreach ($grafs as $key => $value) {
  943. if (!isset( $md_html_blocks[$value] )) {
  944. $value = _RunSpanGamut($value);
  945. $value = preg_replace('/^([ \t]*)/', '<p>', $value);
  946. $value .= "</p>";
  947. $grafs[$key] = $value;
  948. }
  949. }
  950. #
  951. # Unhashify HTML blocks
  952. #
  953. foreach ($grafs as $key => $value) {
  954. if (isset( $md_html_blocks[$value] )) {
  955. $grafs[$key] = $md_html_blocks[$value];
  956. }
  957. }
  958. return implode("\n\n", $grafs);
  959. }
  960. function _EncodeAmpsAndAngles($text) {
  961. # Smart processing for ampersands and angle brackets that need to be encoded.
  962. # Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
  963. # http://bumppo.net/projects/amputator/
  964. $text = preg_replace('/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/',
  965. '&amp;', $text);;
  966. # Encode naked <'s
  967. $text = preg_replace('{<(?![a-z/?\$!])}i', '&lt;', $text);
  968. return $text;
  969. }
  970. function _EncodeBackslashEscapes($text) {
  971. #
  972. # Parameter: String.
  973. # Returns: The string, with after processing the following backslash
  974. # escape sequences.
  975. #
  976. global $md_escape_table, $md_backslash_escape_table;
  977. # Must process escaped backslashes first.
  978. return str_replace(array_keys($md_backslash_escape_table),
  979. array_values($md_backslash_escape_table), $text);
  980. }
  981. function _DoAutoLinks($text) {
  982. $text = preg_replace("!<((https?|ftp):[^'\">\\s]+)>!",
  983. '<a href="\1">\1</a>', $text);
  984. # Email addresses: <address@domain.foo>
  985. $text = preg_replace_callback('{
  986. <
  987. (?:mailto:)?
  988. (
  989. [-.\w]+
  990. \@
  991. [-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+
  992. )
  993. >
  994. }xi',
  995. function($m){
  996. return _EncodeEmailAddress(_UnescapeSpecialChars(_UnslashQuotes($m[1])));
  997. },
  998. $text
  999. );
  1000. return $text;
  1001. }
  1002. function _EncodeEmailAddress($addr) {
  1003. #
  1004. # Input: an email address, e.g. "foo@example.com"
  1005. #
  1006. # Output: the email address as a mailto link, with each character
  1007. # of the address encoded as either a decimal or hex entity, in
  1008. # the hopes of foiling most address harvesting spam bots. E.g.:
  1009. #
  1010. # <a href="&#x6D;&#97;&#105;&#108;&#x74;&#111;:&#102;&#111;&#111;&#64;&#101;
  1011. # x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;">&#102;&#111;&#111;
  1012. # &#64;&#101;x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;</a>
  1013. #
  1014. # Based by a filter by Matthew Wickline, posted to the BBEdit-Talk
  1015. # mailing list: <http://tinyurl.com/yu7ue>
  1016. #
  1017. $addr = "mailto:" . $addr;
  1018. $length = strlen($addr);
  1019. # leave ':' alone (to spot mailto: later)
  1020. $addr = preg_replace_callback('/([^\:])/',
  1021. '_EncodeEmailAddress_callback', $addr);
  1022. $addr = "<a href=\"$addr\">$addr</a>";
  1023. # strip the mailto: from the visible part
  1024. $addr = preg_replace('/">.+?:/', '">', $addr);
  1025. return $addr;
  1026. }
  1027. function _EncodeEmailAddress_callback($matches) {
  1028. $char = $matches[1];
  1029. $r = rand(0, 100);
  1030. # roughly 10% raw, 45% hex, 45% dec
  1031. # '@' *must* be encoded. I insist.
  1032. if ($r > 90 && $char != '@') return $char;
  1033. if ($r < 45) return '&#x'.dechex(ord($char)).';';
  1034. return '&#'.ord($char).';';
  1035. }
  1036. function _UnescapeSpecialChars($text) {
  1037. #
  1038. # Swap back in all the special characters we've hidden.
  1039. #
  1040. global $md_escape_table;
  1041. return str_replace(array_values($md_escape_table),
  1042. array_keys($md_escape_table), $text);
  1043. }
  1044. # _TokenizeHTML is shared between PHP Markdown and PHP SmartyPants.
  1045. # We only define it if it is not already defined.
  1046. if (!function_exists('_TokenizeHTML')) :
  1047. function _TokenizeHTML($str) {
  1048. #
  1049. # Parameter: String containing HTML markup.
  1050. # Returns: An array of the tokens comprising the input
  1051. # string. Each token is either a tag (possibly with nested,
  1052. # tags contained therein, such as <a href="<MTFoo>">, or a
  1053. # run of text between tags. Each element of the array is a
  1054. # two-element array; the first is either 'tag' or 'text';
  1055. # the second is the actual value.
  1056. #
  1057. #
  1058. # Regular expression derived from the _tokenize() subroutine in
  1059. # Brad Choate's MTRegex plugin.
  1060. # <http://www.bradchoate.com/past/mtregex.php>
  1061. #
  1062. $index = 0;
  1063. $tokens = array();
  1064. $match = '(?s:<!(?:--.*?--\s*)+>)|'. # comment
  1065. '(?s:<\?.*?\?>)|'. # processing instruction
  1066. # regular tags
  1067. '(?:<[/!$]?[-a-zA-Z0-9:]+\b(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*>)';
  1068. $parts = preg_split("{($match)}", $str, -1, PREG_SPLIT_DELIM_CAPTURE);
  1069. foreach ($parts as $part) {
  1070. if (++$index % 2 && $part != '')
  1071. $tokens[] = array('text', $part);
  1072. else
  1073. $tokens[] = array('tag', $part);
  1074. }
  1075. return $tokens;
  1076. }
  1077. endif;
  1078. function _Outdent($text) {
  1079. #
  1080. # Remove one level of line-leading tabs or spaces
  1081. #
  1082. global $md_tab_width;
  1083. return preg_replace("/^(\\t|[ ]{1,$md_tab_width})/m", "", $text);
  1084. }
  1085. function _Detab($text) {
  1086. #
  1087. # Replace tabs with the appropriate amount of space.
  1088. #
  1089. global $md_tab_width;
  1090. # For each line we separate the line in blocks delemited by
  1091. # tab characters. Then we reconstruct every line by adding the
  1092. # appropriate number of space between each blocks.
  1093. $lines = explode("\n", $text);
  1094. $text = "";
  1095. foreach ($lines as $line) {
  1096. # Split in blocks.
  1097. $blocks = explode("\t", $line);
  1098. # Add each blocks to the line.
  1099. $line = $blocks[0];
  1100. unset($blocks[0]); # Do not add first block twice.
  1101. foreach ($blocks as $block) {
  1102. # Calculate amount of space, insert spaces, insert block.
  1103. $amount = $md_tab_width - strlen($line) % $md_tab_width;
  1104. $line .= str_repeat(" ", $amount) . $block;
  1105. }
  1106. $text .= "$line\n";
  1107. }
  1108. return $text;
  1109. }
  1110. function _UnslashQuotes($text) {
  1111. #
  1112. # This function is useful to remove automaticaly slashed double quotes
  1113. # when using preg_replace and evaluating an expression.
  1114. # Parameter: String.
  1115. # Returns: The string with any slash-double-quote (\") sequence replaced
  1116. # by a single double quote.
  1117. #
  1118. return str_replace('\"', '"', $text);
  1119. }
  1120. /*
  1121. PHP Markdown
  1122. ============
  1123. Description
  1124. -----------
  1125. This is a PHP translation of the original Markdown formatter written in
  1126. Perl by John Gruber.
  1127. Markdown is a text-to-HTML filter; it translates an easy-to-read /
  1128. easy-to-write structured text format into HTML. Markdown's text format
  1129. is most similar to that of plain text email, and supports features such
  1130. as headers, *emphasis*, code blocks, blockquotes, and links.
  1131. Markdown's syntax is designed not as a generic markup language, but
  1132. specifically to serve as a front-end to (X)HTML. You can use span-level
  1133. HTML tags anywhere in a Markdown document, and you can use block level
  1134. HTML tags (like <div> and <table> as well).
  1135. For more information about Markdown's syntax, see:
  1136. <http://daringfireball.net/projects/markdown/>
  1137. Bugs
  1138. ----
  1139. To file bug reports please send email to:
  1140. <michel.fortin@michelf.com>
  1141. Please include with your report: (1) the example input; (2) the output you
  1142. expected; (3) the output Markdown actually produced.
  1143. Version History
  1144. ---------------
  1145. See the readme file for detailed release notes for this version.
  1146. 1.0.1c - 9 Dec 2005
  1147. 1.0.1b - 6 Jun 2005
  1148. 1.0.1a - 15 Apr 2005
  1149. 1.0.1 - 16 Dec 2004
  1150. 1.0 - 21 Aug 2004
  1151. Author & Contributors
  1152. ---------------------
  1153. Original Perl version by John Gruber
  1154. <http://daringfireball.net/>
  1155. PHP port and other contributions by Michel Fortin
  1156. <http://www.michelf.com/>
  1157. Copyright and License
  1158. ---------------------
  1159. Copyright (c) 2004-2005 Michel Fortin
  1160. <http://www.michelf.com/>
  1161. All rights reserved.
  1162. Copyright (c) 2003-2004 John Gruber
  1163. <http://daringfireball.net/>
  1164. All rights reserved.
  1165. Redistribution and use in source and binary forms, with or without
  1166. modification, are permitted provided that the following conditions are
  1167. met:
  1168. * Redistributions of source code must retain the above copyright notice,
  1169. this list of conditions and the following disclaimer.
  1170. * Redistributions in binary form must reproduce the above copyright
  1171. notice, this list of conditions and the following disclaimer in the
  1172. documentation and/or other materials provided with the distribution.
  1173. * Neither the name "Markdown" nor the names of its contributors may
  1174. be used to endorse or promote products derived from this software
  1175. without specific prior written permission.
  1176. This software is provided by the copyright holders and contributors "as
  1177. is" and any express or implied warranties, including, but not limited
  1178. to, the implied warranties of merchantability and fitness for a
  1179. particular purpose are disclaimed. In no event shall the copyright owner
  1180. or contributors be liable for any direct, indirect, incidental, special,
  1181. exemplary, or consequential damages (including, but not limited to,
  1182. procurement of substitute goods or services; loss of use, data, or
  1183. profits; or business interruption) however caused and on any theory of
  1184. liability, whether in contract, strict liability, or tort (including
  1185. negligence or otherwise) arising in any way out of the use of this
  1186. software, even if advised of the possibility of such damage.
  1187. */
  1188. ?>