home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / WordPress 1.5.1.dmg / wordpress / wp-content / plugins / markdown.php < prev    next >
Encoding:
PHP Script  |  2005-03-14  |  34.2 KB  |  1,283 lines

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