From 8d9f72722219d959eea1a599e9dcfa97049e70b7 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 1 May 2007 00:17:12 +0000 Subject: [PATCH] Removing the Markdown parser because we don't need it really --- Markdown.php | 325 --------------------------------- docs/UnitTest/MarkdownTest.php | 201 -------------------- 2 files changed, 526 deletions(-) delete mode 100644 Markdown.php delete mode 100644 docs/UnitTest/MarkdownTest.php diff --git a/Markdown.php b/Markdown.php deleted file mode 100644 index 2481b3f..0000000 --- a/Markdown.php +++ /dev/null @@ -1,325 +0,0 @@ -transform($text); - } - - // ################################################################### - /** - * Resets the parser - */ - public function __construct() - { - $this->htmlBlockMap = array(); - $this->text = ''; - } - - // ################################################################### - /** - * Transforms the Markdown text into XHTML with the parser's set options - * - * @param string Text to transform - * - * @return string HTML output - */ - public function transform($text) - { - // reset the data arrays - $this->__construct(); - - // convert line breaks and remove empty lines of whitespace - $this->text = BSFunctions::ConvertLineBreaks($text); - $this->text = preg_replace('/^\s*?$/m', '', $this->text); - - $this->_extractHtmlBlocks(); - $this->_extractLinkMap(); - - $this->_convertHardLineBreaks(); - $this->_convertAtxHeaders(); - $this->_convertSetextHeaders(); - $this->_convertHorizontalRules(); - $this->_formatParagraphs(); - $this->text = $this->_expandHtmlBlocks($this->text); - - // convert entitites - $this->_convertFloatingEntities(); - - return $this->text; - } - - // ################################################################### - /** - * Description of the function - * - * @param string A string param - * - * @return integer Return value - */ - private function _extractHtmlBlocks() - { - $start = -1; - $blockStart = 0; - $nest = array(); - $matches = array(); - - // find the first insance of a block tag - $regex = implode('|', $this->htmlBockTags); - while ($start <= strlen($this->text)) - { - $start++; - if (preg_match("/^<($regex)/i", substr($this->text, $start)) === 1) - { - if (sizeof($nest) == 0) - { - $blockStart = $start; - } - array_push($nest, $start); - } - else if (preg_match("#^#i", substr($this->text, $start), $matches) === 1) - { - array_pop($nest); - if (sizeof($nest) == 0) - { - $block = substr($this->text, $blockStart, $start - $blockStart + strlen($matches[0])); - $hash = md5($block . microtime()); - $this->htmlBlockMap[$hash] = $block; - $this->text = substr_replace($this->text, $hash, $blockStart, strlen($block)); - $start = $blockStart; - } - } - } - } - - // ################################################################### - /** - * Expands the hashed HTML blocks back into their originial form - */ - private function _expandHtmlBlocks($text) - { - return str_replace(array_keys($this->htmlBlockMap), array_values($this->htmlBlockMap), $text); - } - - // ################################################################### - /** - * Extracts all links in the "[id]: link" form - */ - public function _extractLinkMap() - { - $this->text = preg_replace_callback('/\[(\w+)\]:\s*?(\s*(("|\')|\()(.*?)(\4|\)))?\n?/', array(&$this, '_extractLinkMapCallback'), $this->text); - } - - // ################################################################### - /** - * Converts extracted link definitions into the map - * - * @param array Matches array - */ - private function _extractLinkMapCallback($matches) - { - $this->linkMap[$matches[1]] = array($matches[2], $matches[6]); - } - - // ################################################################### - /** - * Converts text surrounded by #sings to headers (## Heading 2) - */ - private function _convertAtxHeaders() - { - $this->text = preg_replace_callback('/^(\#{1,6})\s*(.+)(\s*\#+)?$/', array(&$this, '_convertAtxHeadersCallback'), $this->text); - } - - // ################################################################### - /** - * Callback function for preg_replace() in _convertAtxHeaders() - * - * @param array Matches - */ - private function _convertAtxHeadersCallback($matches) - { - // var_dump($matches); - $html = '' . $this->_expandHtmlBlocks($matches[2]) . ''; - $hash = md5($html . microtime()); - $this->htmlBlockMap[$hash] = $html; - return $hash; - } - - // ################################################################### - /** - * Converts headers that are formed by underlines into headings - */ - private function _convertSetextHeaders() - { - $this->text = preg_replace_callback('/(.+)\n(-|=){1,}$/m', array(&$this, '_convertSetextHeadersCallback'), $this->text); - } - - // ################################################################### - /** - * Callback function for _convertSetextHeaders(). This does the actual - * conversion and then hashes it into a block - * - * @param array Matches from the preg_replace_callback() - */ - private function _convertSetextHeadersCallback($matches) - { - $text = $this->_expandHtmlBlocks($matches[1]); - if ($matches[2][0] == '=') - { - $text = '

' . $text . '

'; - } - else - { - $text = '

' . $text . '

'; - } - $hash = md5($text . microtime()); - $this->htmlBlockMap[$hash] = $text; - return $hash; - } - - // ################################################################### - /** - * Converts three stars or dashes (optionally separated by spaces) into - * a horizontal rule. - */ - private function _convertHorizontalRules() - { - $hash = md5('
' . microtime()); - $count = 0; - $this->text = preg_replace('/((-|\*) ?){3,}/', $hash, $this->text, -1, $count); - if ($count > 0) - { - $this->htmlBlockMap[$hash] = '
'; - } - } - - // ################################################################### - /** - * Wraps blocks into paragraphs - */ - private function _formatParagraphs() - { - $blocks = preg_split('/\n{2,}/', $this->text, -1, PREG_SPLIT_NO_EMPTY); - foreach ($blocks AS $key => $value) - { - if (!isset($this->htmlBlockMap[$value])) - { - $blocks[$key] = "

$value

"; - } - } - - $this->text = implode("\n\n", $blocks); - } - - // ################################################################### - /** - * Converts two spaces followed by a new line with text on it to - * a hard line break (
) - */ - private function _convertHardLineBreaks() - { - $this->text = preg_replace('/ {2,}\n/m', "
\n", $this->text); - } - - // ################################################################### - /** - * Converts all angle brackets and ampersands that are floating into - * HTML entities - */ - private function _convertFloatingEntities() - { - // encode ampersands - $this->text = preg_replace('/&(?!#?x?[0-9a-z]+;)/i', '&', $this->text); - - // encode brackets who aren't followed by text - $this->text = preg_replace('#<(?![/?a-z])#i', '<', $this->text); - } -} - -/*=====================================================================*\ -|| ################################################################### -|| # $HeadURL$ -|| # $Id$ -|| ################################################################### -\*=====================================================================*/ -?> \ No newline at end of file diff --git a/docs/UnitTest/MarkdownTest.php b/docs/UnitTest/MarkdownTest.php deleted file mode 100644 index a0257dc..0000000 --- a/docs/UnitTest/MarkdownTest.php +++ /dev/null @@ -1,201 +0,0 @@ -assertEqual('

http://images.google.com/images?num=30&q=larry+bird

', BSMarkdown::Parse('http://images.google.com/images?num=30&q=larry+bird')); - } - - public function testSingleEntityEscape() - { - $this->assertEqual('

©

', BSMarkdown::Parse('©')); - $this->assertEqual('

AT&T

', BSMarkdown::Parse('AT&T')); - $this->assertEqual('

Test

', BSMarkdown::Parse('

Test

')); - $this->assertEqual('

4 < 5

', BSMarkdown::Parse('4 < 5')); - } - - public function testParagraphs() - { - $this->assertEqual("

Example

\n\n

Of

\n\n

Parsing

", BSMarkdown::Parse("Example\n\nOf\n\nParsing")); - $this->assertEqual("

Example

\n\n

Two

", BSMarkdown::Parse("Example\n \nTwo")); - $this->assertEqual("

One\nTwo\nThree

\n\n

Four

", BSMarkdown::Parse("One\nTwo\nThree\n\nFour")); - } - - public function testLineBreak() - { - $this->assertEqual("

This is line break
\nhere

", BSMarkdown::Parse("This is a line break \n")); - $this->assertEqual("

Paragraph one
\nline two.

\n\n

Paragraph two.

", BSMarkdown::Parse("Paragraph one \nline two.\n\nParagraph two.")); - } - - public function testSetextHeaders() - { - $this->assertEqual('

Heading

', BSMarkdown::Parse("Heading\n=")); - $this->assertEqual('

Heading

', BSMarkdown::Parse("Heading\n=====")); - $this->assertEqual('

Heading

', BSMarkdown::Parse("Heading\n-")); - $this->assertEqual('

Heading

', BSMarkdown::Parse("Heading\n----- ")); - $this->assertEqual("

Heading\n=3

", BSMarkdown::Parse("Heading\n=3")); - } - - public function testAtxHeaders() - { - $this->assertEqual('

Heading 1

', BSMarkdown::Parse('# Heading 1')); - $this->assertEqual('

Heading 2

', BSMarkdown::Parse('## Heading 2')); - $this->assertEqual('

Heading 3

', BSMarkdown::Parse('### Heading 3')); - $this->assertEqual('

Heading 4

', BSMarkdown::Parse('#### Heading 4')); - $this->assertEqual('
Heading 5
', BSMarkdown::Parse('##### Heading 5')); - $this->assertEqual('
Heading 6
', BSMarkdown::Parse('###### Heading 6')); - - $this->assertEqual('
A simple heading
', BSMarkdown::Parse('#####A simple heading')); - $this->assertEqual('

Another heading

', BSMarkdown::Parse("## \tAnother heading")); - $this->assertEqual('

The # of headings

', BSMarkdown::Parse('### The # of headings')); - $this->assertEqual('

End test

', BSMarkdown::Parse('#### End test ##')); - $this->assertEqual('

End test 2

', BSMarkdown::Parse('#### End test 2####')); - $this->assertEqual('

# of #s in #

', BSMarkdown::Parse('# # of #s in # ###')); - } - - public function testBlockquote() - { - $this->assertEqual("
\n\t

Example of blockquoted text

\n
", BSMarkdown::Parse('> Example of blockquoted text')); - $this->assertEqual("
\n\t

Another\n\texample\n\tof

\n\n

blockquoted text
\there.

\n
", BSMarkdown::Parse("> Another\nexample\nof\n\n>blockquoted text \nhere.")); - $this->assertEqual("
\n\t

This is a header.

\n\n\t

Welcome to AT&T.

\n
", BSMarkdown::Parse("> ## This is a header.\n>\n>\nWelcome to AT&T.")); - } - - public function testUnorderedLists() - { - $this->assertEqual("", BSMarkdown::Parse("* Red\n* Green\n*\tBlue")); - $this->assertEqual("", BSMarkdown::Parse("+ Red\n+ Green\n+ Blue")); - $this->assertEqual("", BSMarkdown::Parse("- Red\n- Green\n- Blue")); - $this->assertEqual("

Test

\n", BSMarkdown::Parse("Test\n\n- Example")); - - $this->assertEqual("", BSMarkdown::Parse("* Lorem\n ipsum\n dolor\n sit\n amet.\n* Another\nexample.")); - } - - public function testOrderedList() - { - $this->assertEqual("
    \n
  1. Bird
  2. \n
  3. McHale
  4. \n
  5. Parish
  6. \n
", BSMarkdown::Parse("3. Bird\n1. McHale\n8. Parish")); - $this->assertEqual("
    \n
  1. Bird
  2. \n
  3. McHale
  4. \n
  5. Parish
  6. \n
", BSMarkdown::Parse("1. Bird\n2. McHale\n2. Parish")); - } - - public function testParagraphedLists() - { - $this->assertEqual("
    \n
  1. Item 1

  2. \n
  3. Item 2

  4. \n
", BSMarkdown::Parse("1. Item 1\n\n2. Item 2")); - $this->assertEqual("", BSMarkdown::Parse("+ Part one.\n\n\tPart two.\n+Part three.")); - $this->assertEqual("", BSMarkdown::Parse("+ Part one.\n\n Part two.\n+Part three.")); - $this->assertEqual("", BSMarkdown::Parse("+ Example \nline break.")); - - $this->assertEqual("
    \n
  1. A list with blockquote:\n\n
    \n\t

    This blockquote\n\tis inside a list.

    \n
  2. \n
", BSMarkdown::Parse("1. A list with blockquote:\n\n > This blockquote\nis inside a list.")); - $this->assertEqual("
    \n
  1. A list with blockquote:\n\n
    \n\t

    This blockquote\n\tis inside a list.

    \n
  2. \n
", BSMarkdown::Parse("1. A list with blockquote:\n\n\t> This blockquote\n> is inside a list.")); - - $this->assertEqual("", BSMarkdown::Parse("+ A list item without a code block: code goes here")); - $this->assertEqual("", BSMarkdown::Parse("* A list item without a code block:\t\tcode goes here")); - } - - public function testCodeBlocks() - { - $this->assertEqual("

This is a normal paragraph:

\n\n
This is a code block.\n
", BSMarkdown::Parse("This is a normal paragraph:\n\n This is a code block.")); - $this->assertEqual("

This is a normal paragraph:

\n\n
This is a code block.\n
", BSMarkdown::Parse("This is a normal paragraph:\n\n\tThis is a code block.")); - - $this->assertEqual("

AppleScript:

\n\n
tell application \"Foo\"\n\tbeep\nend tell\n
", BSMarkdown::Parse("AppleScript:\n\n\ttell application \"Foo\"\n\t\tbeep\n\tend tell")); - - $this->assertEqual("
<div class="footer">&© 2004 Foo Corporation</div>\n
", BSMarkdown::Parse("
© 2004 Foo Corporation
")); - } - - public function testHorizontalRules() - { - $this->assertEqual('
', BSMarkdown::Parse('* * *')); - $this->assertEqual('
', BSMarkdown::Parse('***')); - $this->assertEqual('
', BSMarkdown::Parse('*****')); - $this->assertEqual('
', BSMarkdown::Parse('- - -')); - $this->assertEqual('
', BSMarkdown::Parse('--------------------')); - } - - public function testSimpleLinks() - { - $this->assertEqual('

This is an example inline link.

', BSMarkdown::Parse('This is [an example](http://example.com/ "Title") inline link.')); - $this->assertEqual('

This link has no title attribute.

', BSMarkdown::Parse('[This link](http://example.net/) has no title attribute.')); - $this->assertEqual('

See my About page for details.

', BSMarkdown::Parse('See my [About](/about/) page for details.')); - - $this->assertEqual('

http://example.com/

', BSMarkdown::Parse('')); - $this->assertEqual('

address@example.com

', BSMarkdown::Parse('')); - } - - public function testReferenceLinks() - { - $this->assertEqual('

This is an example reference-style link.

', BSMarkdown::Parse("This is [an example][id] reference-style link.\n\n[id]: http://example.com/ \"Optional Title Here\"")); - $this->assertEqual('

This is an example reference-style link.

', BSMarkdown::Parse("This is [an example] [id] reference-style link.\n[id]: http://example.com/ 'Optional Title Here'")); - $this->assertEqual('

This is an example reference-style link.

', BSMarkdown::Parse("This is [an example]\t[id] reference-style link.\n\n\n[id]: http://example.com/ (Optional Title Here)")); - - $this->assertEqual('

Example link here there.

', BSMarkdown::Parse("Example link [here][id] there.\n[id]: (title)")); - $this->assertEqual('

Example link here there.

', BSMarkdown::Parse("Example link [here][id] there.\n[id]: ")); - - $this->assertEqual('

Welcome to Google.

', BSMarkdown::Parse("Welcome to [Google][].\n[Google]: http://www.google.com")); - $this->assertEqual('

Visit Daring Fireball!', BSMarkdown::Parse("Visit [Daring Fireball][]!\n[Daring Fireball]: http://daringfireball.net")); - } - - public function testEmphasis() - { - $this->assertEqual('

single asterisks

', BSMarkdown::Parse('*single asterisks*')); - $this->assertEqual('

single underscores

', BSMarkdown::Parse('_single underscores_')); - - $this->assertEqual('

double asterisks

', BSMarkdown::Parse('**double asterisks**')); - $this->assertEqual('

double underscores

', BSMarkdown::Parse('__double underscores__')); - - $this->assertEqual('

unfuckingbelievable

', BSMarkdown::Parse('un*fucking*believable')); - $this->assertEqual('

un * fucking * believable

', BSMarkdown::Parse('un * fucking * believable')); - } - - public function testCodeSpan() - { - $this->assertEqual('

Use the printf() function.

', BSMarkdown::Parse('Use the `printf()` function.')); - $this->assertEqual('

There is a literal backtick (`) here.

', BSMarkdown::Parse('``There is a literal backtick (`) here.``')); - $this->assertEqual('

A single backtick in a code span: `

', BSMarkdown::Parse('A single backtick in a code span: `` ` ``')); - $this->assertEqual('

A backtick-delimited string in a code span: `foo`

', BSMarkdown::Parse('A backtick-delimited string in a code span: `` `foo` ``')); - - $this->assertEqual('

Please do not use any <blink> tags.

', BSMarkdown::Parse('Please do not use any `` tags.')); - $this->assertEqual('

&#8212; is the decimal-encoded equivalent of &mdash;.

', BSMarkdown::Parse('`—` is the decimal-encoded equivalent of `—`.')); - } - - public function testImages() - { - $this->assertEqual('

Alt text

', BSMarkdown::Parse('![Alt text](/path/to/img.jpg)')); - $this->assertEqual('

Alt text

', BSMarkdown::Parse('![Alt text](/path/to/img.jpg "Optional title")')); - $this->assertEqual('

Alt text

', BSMarkdown::Parse('![Alt text](/path/to/img.jpg \'Optional title\')')); - - $this->assertEqual('

Alt text

', BSMarkdown::Parse("![Alt text][id]\n[id]: url/to/image \"Optional title attribute\"")); - $this->assertEqual('

Alt text

', BSMarkdown::Parse("![Alt text][id]\n[id]: url/to/image\t 'Optional title attribute'")); - } - - public function testEscapeSequences() - { - $this->assertEqual('

Escaped \ Backslash

', BSMarkdown::Parse('Escaped \\ Backslash')); - $this->assertEqual('

`This is not code`

', BSMarkdown::Parse('\`This is not code\`')); - $this->assertEqual('

*This is not italics*

', BSMarkdown::Parse('\*This is not italics\*')); - $this->assertEqual('

* This is not a list

', BSMarkdown::Parse('\* This is not a list')); - $this->assertEqual('

__This is not bold__

', BSMarkdown::Parse('\_\_This is not bold__')); - $this->assertEqual('

This [is not](http://www.example.com "Moo") a URL.

', BSMarkdown::Parse('This \[is not](http://www.example.com "Moo") a URL.')); - $this->assertEqual('

This [is not](http://www.example.com "Moo") a URL.

', BSMarkdown::Parse('This [is not]\(http://www.example.com "Moo") a URL.')); - $this->assertEqual("

This is not a heading\n-

", BSMarkdown::Parse("This is not a heading\n\-")); - $this->assertEqual("

1986. What a great season.

", BSMarkdown::Parse('1986\. What a great season.')); - $this->assertEqual('

This is not an iamge: !Alt text!

', BSMarkdown::Parse('This is not an iamge: \![Alt text](url/to/image "Optional title attribute")!')); - $this->assertEqual('

This is not an iamge: ![Alt text](url/to/image "Optional title attribute")!

', BSMarkdown::Parse('This is not an iamge: \!\[Alt text](url/to/image "Optional title attribute")!')); - } -} - -?> \ No newline at end of file -- 2.22.5