From 6f1fac982335c6c7571f009b10a78ee8f2bad9c5 Mon Sep 17 00:00:00 2001
From: Haralan Dobrev
Date: Fri, 5 Sep 2014 23:12:33 +0300
Subject: [PATCH 01/10] Add Standard Markdown testsuite.
You could run the Parsedown testsuite only with:
phpunit --testsuite ParsedownTests
And you could run the Standard Markdown one with:
phpunit --testsuite StandardMarkdown
See more at http://standardmarkdown.com/
---
.travis.yml | 3 +-
phpunit.xml.dist | 9 ++-
test/standard-markdown/.gitignore | 1 +
.../StandardMarkdownTest.php | 60 +++++++++++++++++++
4 files changed, 69 insertions(+), 4 deletions(-)
create mode 100644 test/standard-markdown/.gitignore
create mode 100644 test/standard-markdown/StandardMarkdownTest.php
diff --git a/.travis.yml b/.travis.yml
index dade257..cf9fc06 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,4 +7,5 @@ php:
- 5.3
- 5.2
- hhvm
-
\ No newline at end of file
+
+before_script: curl -sS https://raw.githubusercontent.com/jgm/stmd/master/spec.txt>test/standard-markdown/spec.txt
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 875167a..80a08b6 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,8 +1,11 @@
-
- test/Test.php
+
+ test/Test.php
+
+
+ test/standard-markdown/StandardMarkdownTest.php
-
\ No newline at end of file
+
diff --git a/test/standard-markdown/.gitignore b/test/standard-markdown/.gitignore
new file mode 100644
index 0000000..99ba414
--- /dev/null
+++ b/test/standard-markdown/.gitignore
@@ -0,0 +1 @@
+spec.txt
diff --git a/test/standard-markdown/StandardMarkdownTest.php b/test/standard-markdown/StandardMarkdownTest.php
new file mode 100644
index 0000000..c66b3c4
--- /dev/null
+++ b/test/standard-markdown/StandardMarkdownTest.php
@@ -0,0 +1,60 @@
+(.|[\n])*/m', '', $spec);
+
+ preg_replace_callback(
+ '/^\.\n([\s\S]*?)^\.\n([\s\S]*?)^\.$|^#{1,6} *(.*)$/m',
+ function($matches) use (&$tests, &$currentSection, &$testsCount) {
+ if (isset($matches[3]) and $matches[3]) {
+ $currentSection = $matches[3];
+ } else {
+ $testsCount++;
+ $markdown = preg_replace('/→/', "\t", $matches[1]);
+ $tests []= array(
+ $markdown, // markdown
+ $matches[2], // html
+ $currentSection, // section
+ $testsCount, // number
+ );
+ }
+ },
+ $spec
+ );
+
+ return $tests;
+ }
+
+ /**
+ * @dataProvider getStandardMarkdownRules
+ */
+ public function testAgainstStandardMarkdown($markdown, $expectedHtml, $section, $number)
+ {
+ $parsedown = new Parsedown();
+
+ $actualHtml = $parsedown->text($markdown);
+
+ // Trim for better compatibility of the HTML output
+ $actualHtml = trim($actualHtml);
+ $expectedHtml = trim($expectedHtml);
+
+ $this->assertEquals($expectedHtml, $actualHtml);
+ }
+}
From c18ff7f370901fd7bd803d3bc0a71fe321e9090d Mon Sep 17 00:00:00 2001
From: Haralan Dobrev
Date: Fri, 5 Sep 2014 23:28:07 +0300
Subject: [PATCH 02/10] Add Docblock and attribution to JS test runner
---
test/standard-markdown/StandardMarkdownTest.php | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/test/standard-markdown/StandardMarkdownTest.php b/test/standard-markdown/StandardMarkdownTest.php
index c66b3c4..c01f331 100644
--- a/test/standard-markdown/StandardMarkdownTest.php
+++ b/test/standard-markdown/StandardMarkdownTest.php
@@ -1,5 +1,13 @@
Date: Sat, 6 Sep 2014 01:12:35 +0300
Subject: [PATCH 03/10] Rename Standard Markdown to CommonMark
http://blog.codinghorror.com/standard-markdown-is-now-common-markdown/
https://github.com/coding-horror/coding-horror.github.io/commit/2d37920c39d15db0769f710bd2414e9a2ed7b565
---
test/standard-markdown/StandardMarkdownTest.php | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/test/standard-markdown/StandardMarkdownTest.php b/test/standard-markdown/StandardMarkdownTest.php
index c01f331..a34b0a7 100644
--- a/test/standard-markdown/StandardMarkdownTest.php
+++ b/test/standard-markdown/StandardMarkdownTest.php
@@ -1,20 +1,20 @@
Date: Sun, 14 Sep 2014 00:02:11 +0300
Subject: [PATCH 04/10] Rename everything to CommonMark
---
phpunit.xml.dist | 10 +++++-----
test/{standard-markdown => commonmark}/.gitignore | 0
.../CommonMarkTest.php} | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
rename test/{standard-markdown => commonmark}/.gitignore (100%)
rename test/{standard-markdown/StandardMarkdownTest.php => commonmark/CommonMarkTest.php} (97%)
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 80a08b6..289a215 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,11 +1,11 @@
-
- test/Test.php
-
-
- test/standard-markdown/StandardMarkdownTest.php
+
+ test/Test.php
+
+
+ test/commonmark/CommonMarkTest.php
diff --git a/test/standard-markdown/.gitignore b/test/commonmark/.gitignore
similarity index 100%
rename from test/standard-markdown/.gitignore
rename to test/commonmark/.gitignore
diff --git a/test/standard-markdown/StandardMarkdownTest.php b/test/commonmark/CommonMarkTest.php
similarity index 97%
rename from test/standard-markdown/StandardMarkdownTest.php
rename to test/commonmark/CommonMarkTest.php
index a34b0a7..a2b404f 100644
--- a/test/standard-markdown/StandardMarkdownTest.php
+++ b/test/commonmark/CommonMarkTest.php
@@ -5,7 +5,7 @@
*
* Some code based on the original JavaScript test runner by jgm.
*
- * @link http://commonmark.net/ CommonMark
+ * @link http://commonmark.org/ CommonMark
* @link http://git.io/8WtRvQ JavaScript test runner
*/
class CommonMarkTest extends PHPUnit_Framework_TestCase
From e46be110fb0549acee3eda0497da04f35d87daad Mon Sep 17 00:00:00 2001
From: Emanuil Rusev
Date: Sat, 29 Nov 2014 16:42:04 +0200
Subject: [PATCH 05/10] Merge branch 'master' into commonmark
---
Parsedown.php | 47 +++++++++++--
README.md | 18 ++---
phpunit.xml.dist | 2 +-
test/ParsedownTest.php | 139 +++++++++++++++++++++++++++++++++++++
test/Test.php | 65 -----------------
test/data/escaping.html | 4 +-
test/data/escaping.md | 6 +-
test/data/sparse_html.html | 8 +++
test/data/sparse_html.md | 8 +++
9 files changed, 215 insertions(+), 82 deletions(-)
create mode 100644 test/ParsedownTest.php
delete mode 100644 test/Test.php
create mode 100644 test/data/sparse_html.html
create mode 100644 test/data/sparse_html.md
diff --git a/Parsedown.php b/Parsedown.php
index e9a8cbd..0258075 100755
--- a/Parsedown.php
+++ b/Parsedown.php
@@ -66,6 +66,15 @@ class Parsedown
return $this;
}
+ private $markupEscaped;
+
+ function setMarkupEscaped($markupEscaped)
+ {
+ $this->markupEscaped = $markupEscaped;
+
+ return $this;
+ }
+
#
# Lines
#
@@ -350,6 +359,11 @@ class Parsedown
protected function identifyComment($Line)
{
+ if ($this->markupEscaped)
+ {
+ return;
+ }
+
if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!')
{
$Block = array(
@@ -619,6 +633,11 @@ class Parsedown
protected function identifyMarkup($Line)
{
+ if ($this->markupEscaped)
+ {
+ return;
+ }
+
if (preg_match('/^<(\w[\w\d]*)(?:[ ][^>]*)?(\/?)[ ]*>/', $Line['text'], $matches))
{
if (in_array($matches[1], $this->textLevelElements))
@@ -630,7 +649,7 @@ class Parsedown
'element' => $Line['body'],
);
- if ($matches[2] or $matches[1] === 'hr' or preg_match('/<\/'.$matches[1].'>[ ]*$/', $Line['text']))
+ if ($matches[2] or in_array($matches[1], $this->voidElements) or preg_match('/<\/'.$matches[1].'>[ ]*$/', $Line['text']))
{
$Block['closed'] = true;
}
@@ -651,7 +670,7 @@ class Parsedown
return;
}
- if (preg_match('/<'.$Block['name'].'([ ][^\/]+)?>/', $Line['text'])) # opening tag
+ if (preg_match('/<'.$Block['name'].'([ ].*[\'"])?[ ]*>/', $Line['text'])) # opening tag
{
$Block['depth'] ++;
}
@@ -668,6 +687,13 @@ class Parsedown
}
}
+ if (isset($Block['interrupted']))
+ {
+ $Block['element'] .= "\n";
+
+ unset($Block['interrupted']);
+ }
+
$Block['element'] .= "\n".$Line['body'];
return $Block;
@@ -1144,6 +1170,11 @@ class Parsedown
protected function identifyTag($Excerpt)
{
+ if ($this->markupEscaped)
+ {
+ return;
+ }
+
if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<\/?\w.*?>/', $Excerpt['text'], $matches))
{
return array(
@@ -1379,13 +1410,17 @@ class Parsedown
);
protected $StrongRegex = array(
- '*' => '/^[*]{2}((?:[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s',
- '_' => '/^__((?:[^_]|_[^_]*_)+?)__(?!_)/us',
+ '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s',
+ '_' => '/^__((?:\\\\_|[^_]|_[^_]*_)+?)__(?!_)/us',
);
protected $EmRegex = array(
- '*' => '/^[*]((?:[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s',
- '_' => '/^_((?:[^_]|__[^_]*__)+?)_(?!_)\b/us',
+ '*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s',
+ '_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us',
+ );
+
+ protected $voidElements = array(
+ 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source',
);
protected $textLevelElements = array(
diff --git a/README.md b/README.md
index f1676f4..1984e06 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,15 @@
## Parsedown
-Better [Markdown](http://en.wikipedia.org/wiki/Markdown) parser for PHP.
+Better Markdown Parser in PHP
-* [Demo](http://parsedown.org/demo)
-* [Test Suite](http://parsedown.org/tests/)
+[[ demo ]](http://parsedown.org/demo)
### Features
* [Fast](http://parsedown.org/speed)
* [Consistent](http://parsedown.org/consistency)
-* [GitHub Flavored](https://help.github.com/articles/github-flavored-markdown)
-* [Tested](https://travis-ci.org/erusev/parsedown) in PHP 5.2, 5.3, 5.4, 5.5, 5.6 and [hhvm](http://www.hhvm.com/)
+* [GitHub flavored](https://help.github.com/articles/github-flavored-markdown)
+* [Tested](http://parsedown.org/tests/) in PHP 5.2, 5.3, 5.4, 5.5, 5.6 and [hhvm](http://www.hhvm.com/)
* Extensible
* [Markdown Extra extension](https://github.com/erusev/parsedown-extra) new
* [JavaScript port](https://github.com/hkdobrev/parsedown.js) under development new
@@ -27,7 +26,7 @@ $Parsedown = new Parsedown();
echo $Parsedown->text('Hello _Parsedown_!'); # prints: Hello Parsedown!
```
-More examples in [the wiki](https://github.com/erusev/parsedown/wiki/Usage).
+More examples in [the wiki](https://github.com/erusev/parsedown/wiki/Usage) and in [this video tutorial](http://youtu.be/wYZBY8DEikI).
### Questions
@@ -35,7 +34,10 @@ More examples in [the wiki](https://github.com/erusev/parsedown/wiki/Usage).
Parsedown recognises that the Markdown syntax is optimised for humans so it tries to read like one. It goes through text line by line. It looks at how lines start to identify blocks. It looks for special characters to identify inline elements.
**Why doesn’t Parsedown use namespaces?**
-Using namespaces would mean dropping support for PHP 5.2. Since Parsedown is a single class with an uncommon name, making this trade wouldn't make much sense.
+Using namespaces would mean dropping support for PHP 5.2. We believe that since Parsedown is a single class with an uncommon name, making this trade wouldn't be worth it.
+
+**Is Parsedown compliant with CommonMark?**
+We are [working on it](https://github.com/erusev/parsedown/tree/commonmark).
**Who uses Parsedown?**
-[phpDocumentor](http://www.phpdoc.org/), [Bolt CMS](http://bolt.cm/), [RaspberryPi.org](http://www.raspberrypi.org/) and [more](https://www.versioneye.com/php/erusev:parsedown/references).
+[phpDocumentor](http://www.phpdoc.org/), [October CMS](http://octobercms.com/), [Bolt CMS](http://bolt.cm/), [RaspberryPi.org](http://www.raspberrypi.org/) and [more](https://www.versioneye.com/php/erusev:parsedown/references).
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 289a215..4b6eb9a 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -2,7 +2,7 @@
- test/Test.php
+ test/ParsedownTest.php
test/commonmark/CommonMarkTest.php
diff --git a/test/ParsedownTest.php b/test/ParsedownTest.php
new file mode 100644
index 0000000..d094f2d
--- /dev/null
+++ b/test/ParsedownTest.php
@@ -0,0 +1,139 @@
+dirs = $this->initDirs();
+ $this->Parsedown = $this->initParsedown();
+
+ parent::__construct($name, $data, $dataName);
+ }
+
+ private $dirs, $Parsedown;
+
+ /**
+ * @return array
+ */
+ protected function initDirs()
+ {
+ $dirs []= dirname(__FILE__).'/data/';
+
+ return $dirs;
+ }
+
+ /**
+ * @return Parsedown
+ */
+ protected function initParsedown()
+ {
+ $Parsedown = new Parsedown();
+
+ return $Parsedown;
+ }
+
+ /**
+ * @dataProvider data
+ * @param $test
+ * @param $dir
+ */
+ function test_($test, $dir)
+ {
+ $markdown = file_get_contents($dir . $test . '.md');
+
+ $expectedMarkup = file_get_contents($dir . $test . '.html');
+
+ $expectedMarkup = str_replace("\r\n", "\n", $expectedMarkup);
+ $expectedMarkup = str_replace("\r", "\n", $expectedMarkup);
+
+ $actualMarkup = $this->Parsedown->text($markdown);
+
+ $this->assertEquals($expectedMarkup, $actualMarkup);
+ }
+
+ function data()
+ {
+ $data = array();
+
+ foreach ($this->dirs as $dir)
+ {
+ $Folder = new DirectoryIterator($dir);
+
+ foreach ($Folder as $File)
+ {
+ /** @var $File DirectoryIterator */
+
+ if ( ! $File->isFile())
+ {
+ continue;
+ }
+
+ $filename = $File->getFilename();
+
+ $extension = pathinfo($filename, PATHINFO_EXTENSION);
+
+ if ($extension !== 'md')
+ {
+ continue;
+ }
+
+ $basename = $File->getBasename('.md');
+
+ if (file_exists($dir . $basename . '.html'))
+ {
+ $data []= array($basename, $dir);
+ }
+ }
+ }
+
+ return $data;
+ }
+
+ public function test_no_markup()
+ {
+ $markdownWithHtml = <<_content_
+
+sparse:
+
+
+
+paragraph
+
+
+
+comment
+
+
+MARKDOWN_WITH_MARKUP;
+
+ $expectedHtml = <<<div>content</div>
+sparse:
+<div>
+<div class="inner">
+content
+</div>
+</div>
+paragraph
+<style type="text/css">
+p {
+ color: red;
+}
+</style>
+comment
+<!-- html comment -->
+EXPECTED_HTML;
+ $parsedownWithNoMarkup = new Parsedown();
+ $parsedownWithNoMarkup->setMarkupEscaped(true);
+ $this->assertEquals($expectedHtml, $parsedownWithNoMarkup->text($markdownWithHtml));
+ }
+}
diff --git a/test/Test.php b/test/Test.php
deleted file mode 100644
index 5171d84..0000000
--- a/test/Test.php
+++ /dev/null
@@ -1,65 +0,0 @@
-dataDir = dirname(__FILE__).'/data/';
-
- parent::__construct($name, $data, $dataName);
- }
-
- private $dataDir;
-
- /**
- * @dataProvider data
- */
- function test_($filename)
- {
- $markdown = file_get_contents($this->dataDir . $filename . '.md');
-
- $expectedMarkup = file_get_contents($this->dataDir . $filename . '.html');
-
- $expectedMarkup = str_replace("\r\n", "\n", $expectedMarkup);
- $expectedMarkup = str_replace("\r", "\n", $expectedMarkup);
-
- $actualMarkup = Parsedown::instance()->text($markdown);
-
- $this->assertEquals($expectedMarkup, $actualMarkup);
- }
-
- function data()
- {
- $data = array();
-
- $Folder = new DirectoryIterator($this->dataDir);
-
- foreach ($Folder as $File)
- {
- /** @var $File DirectoryIterator */
-
- if ( ! $File->isFile())
- {
- continue;
- }
-
- $filename = $File->getFilename();
-
- $extension = pathinfo($filename, PATHINFO_EXTENSION);
-
- if ($extension !== 'md')
- {
- continue;
- }
-
- $basename = $File->getBasename('.md');
-
- if (file_exists($this->dataDir . $basename . '.html'))
- {
- $data []= array($basename);
- }
- }
-
- return $data;
- }
-}
diff --git a/test/data/escaping.html b/test/data/escaping.html
index 64676cb..ab1c41f 100644
--- a/test/data/escaping.html
+++ b/test/data/escaping.html
@@ -1,4 +1,6 @@
escaped *emphasis*.
escaped \*emphasis\* in a code span
escaped \*emphasis\* in a code block
-\ ` * _ { } [ ] ( ) > # + - . !
\ No newline at end of file
+\ ` * _ { } [ ] ( ) > # + - . !
+one_two one_two
+one*two one*two
\ No newline at end of file
diff --git a/test/data/escaping.md b/test/data/escaping.md
index 164039f..9f174e9 100644
--- a/test/data/escaping.md
+++ b/test/data/escaping.md
@@ -4,4 +4,8 @@ escaped \*emphasis\*.
escaped \*emphasis\* in a code block
-\\ \` \* \_ \{ \} \[ \] \( \) \> \# \+ \- \. \!
\ No newline at end of file
+\\ \` \* \_ \{ \} \[ \] \( \) \> \# \+ \- \. \!
+
+_one\_two_ __one\_two__
+
+*one\*two* **one\*two**
\ No newline at end of file
diff --git a/test/data/sparse_html.html b/test/data/sparse_html.html
new file mode 100644
index 0000000..9e89627
--- /dev/null
+++ b/test/data/sparse_html.html
@@ -0,0 +1,8 @@
+
+line 1
+
+line 2
+line 3
+
+line 4
+
\ No newline at end of file
diff --git a/test/data/sparse_html.md b/test/data/sparse_html.md
new file mode 100644
index 0000000..9e89627
--- /dev/null
+++ b/test/data/sparse_html.md
@@ -0,0 +1,8 @@
+
+line 1
+
+line 2
+line 3
+
+line 4
+
\ No newline at end of file
From 28a202ee9e181958bf11e3c044dc4a3b7397849d Mon Sep 17 00:00:00 2001
From: Emanuil Rusev
Date: Sat, 29 Nov 2014 20:18:23 +0200
Subject: [PATCH 06/10] simplify
---
test/commonmark/CommonMarkTest.php | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/test/commonmark/CommonMarkTest.php b/test/commonmark/CommonMarkTest.php
index a2b404f..afc61f5 100644
--- a/test/commonmark/CommonMarkTest.php
+++ b/test/commonmark/CommonMarkTest.php
@@ -10,23 +10,17 @@
*/
class CommonMarkTest extends PHPUnit_Framework_TestCase
{
- const SPEC_FILEPATH = 'spec.txt';
-
const SPEC_URL = 'https://raw.githubusercontent.com/jgm/stmd/master/spec.txt';
public function getCommonMarkRules()
{
- if (is_file(self::SPEC_FILEPATH) and is_readable(self::SPEC_FILEPATH)) {
- $spec = file_get_contents(self::SPEC_FILEPATH);
- } else {
- $spec = file_get_contents(self::SPEC_URL);
- }
+ $spec = file_get_contents(self::SPEC_URL);
$tests = array();
$testsCount = 0;
$currentSection = '';
- $spec = preg_replace('/^(.|[\n])*/m', '', $spec);
+ $spec = strstr($spec, '', true);
preg_replace_callback(
'/^\.\n([\s\S]*?)^\.\n([\s\S]*?)^\.$|^#{1,6} *(.*)$/m',
From 6fb534bc34e458b95fc169a71cefd7d7c41abcd2 Mon Sep 17 00:00:00 2001
From: Emanuil Rusev
Date: Sat, 29 Nov 2014 21:34:46 +0200
Subject: [PATCH 07/10] improve consistency
---
test/commonmark/CommonMarkTest.php | 53 +++++++++++++++---------------
1 file changed, 27 insertions(+), 26 deletions(-)
diff --git a/test/commonmark/CommonMarkTest.php b/test/commonmark/CommonMarkTest.php
index afc61f5..d25b10c 100644
--- a/test/commonmark/CommonMarkTest.php
+++ b/test/commonmark/CommonMarkTest.php
@@ -12,29 +12,46 @@ class CommonMarkTest extends PHPUnit_Framework_TestCase
{
const SPEC_URL = 'https://raw.githubusercontent.com/jgm/stmd/master/spec.txt';
- public function getCommonMarkRules()
+ /**
+ * @dataProvider data
+ * @param $markdown
+ * @param $expectedHtml
+ */
+ function test_($markdown, $expectedHtml)
+ {
+ $parsedown = new Parsedown();
+
+ $actualHtml = $parsedown->text($markdown);
+
+ # trim for better compatibility of the HTML output
+ $actualHtml = trim($actualHtml);
+ $expectedHtml = trim($expectedHtml);
+
+ $this->assertEquals($expectedHtml, $actualHtml);
+ }
+
+ function data()
{
$spec = file_get_contents(self::SPEC_URL);
+ $spec = strstr($spec, '', true);
$tests = array();
- $testsCount = 0;
+ $testCount = 0;
$currentSection = '';
- $spec = strstr($spec, '', true);
-
preg_replace_callback(
'/^\.\n([\s\S]*?)^\.\n([\s\S]*?)^\.$|^#{1,6} *(.*)$/m',
- function($matches) use (&$tests, &$currentSection, &$testsCount) {
+ function($matches) use ( & $tests, & $currentSection, & $testCount) {
if (isset($matches[3]) and $matches[3]) {
$currentSection = $matches[3];
} else {
- $testsCount++;
+ $testCount++;
$markdown = preg_replace('/→/', "\t", $matches[1]);
$tests []= array(
- $markdown, // markdown
- $matches[2], // html
- $currentSection, // section
- $testsCount, // number
+ $markdown, # markdown
+ $matches[2], # html
+ $currentSection, # section
+ $testCount, # number
);
}
},
@@ -43,20 +60,4 @@ class CommonMarkTest extends PHPUnit_Framework_TestCase
return $tests;
}
-
- /**
- * @dataProvider getCommonMarkRules
- */
- public function testAgainstCommonMark($markdown, $expectedHtml, $section, $number)
- {
- $parsedown = new Parsedown();
-
- $actualHtml = $parsedown->text($markdown);
-
- // Trim for better compatibility of the HTML output
- $actualHtml = trim($actualHtml);
- $expectedHtml = trim($expectedHtml);
-
- $this->assertEquals($expectedHtml, $actualHtml);
- }
}
From aa3d4d6eb7da7d4d517890022ae95f7fea78247e Mon Sep 17 00:00:00 2001
From: Emanuil Rusev
Date: Sat, 29 Nov 2014 21:39:42 +0200
Subject: [PATCH 08/10] simplify
---
phpunit.xml.dist | 6 +++---
test/{commonmark => }/CommonMarkTest.php | 0
test/commonmark/.gitignore | 1 -
3 files changed, 3 insertions(+), 4 deletions(-)
rename test/{commonmark => }/CommonMarkTest.php (100%)
delete mode 100644 test/commonmark/.gitignore
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 4b6eb9a..e179772 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,11 +1,11 @@
-
+
test/ParsedownTest.php
-
- test/commonmark/CommonMarkTest.php
+
+ test/CommonMarkTest.php
diff --git a/test/commonmark/CommonMarkTest.php b/test/CommonMarkTest.php
similarity index 100%
rename from test/commonmark/CommonMarkTest.php
rename to test/CommonMarkTest.php
diff --git a/test/commonmark/.gitignore b/test/commonmark/.gitignore
deleted file mode 100644
index 99ba414..0000000
--- a/test/commonmark/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-spec.txt
From 46196c1ac3016f96b2edc8afa81b70385d600d33 Mon Sep 17 00:00:00 2001
From: Emanuil Rusev
Date: Sat, 29 Nov 2014 22:58:42 +0200
Subject: [PATCH 09/10] markup formatting shouldn't impact results
---
test/CommonMarkTest.php | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/test/CommonMarkTest.php b/test/CommonMarkTest.php
index d25b10c..1cb0dfa 100644
--- a/test/CommonMarkTest.php
+++ b/test/CommonMarkTest.php
@@ -22,10 +22,7 @@ class CommonMarkTest extends PHPUnit_Framework_TestCase
$parsedown = new Parsedown();
$actualHtml = $parsedown->text($markdown);
-
- # trim for better compatibility of the HTML output
- $actualHtml = trim($actualHtml);
- $expectedHtml = trim($expectedHtml);
+ $actualHtml = $this->normalizeMarkup($actualHtml);
$this->assertEquals($expectedHtml, $actualHtml);
}
@@ -46,10 +43,13 @@ class CommonMarkTest extends PHPUnit_Framework_TestCase
$currentSection = $matches[3];
} else {
$testCount++;
- $markdown = preg_replace('/→/', "\t", $matches[1]);
+ $markdown = $matches[1];
+ $markdown = preg_replace('/→/', "\t", $markdown);
+ $expectedHtml = $matches[2];
+ $expectedHtml = $this->normalizeMarkup($expectedHtml);
$tests []= array(
$markdown, # markdown
- $matches[2], # html
+ $expectedHtml, # html
$currentSection, # section
$testCount, # number
);
@@ -60,4 +60,15 @@ class CommonMarkTest extends PHPUnit_Framework_TestCase
return $tests;
}
+
+ private function normalizeMarkup($markup)
+ {
+ $markup = preg_replace("/\n+/", "\n", $markup);
+ $markup = preg_replace('/^\s+/m', '', $markup);
+ $markup = preg_replace('/^((?:<[\w]+>)+)\n/m', '$1', $markup);
+ $markup = preg_replace('/\n((?:<\/[\w]+>)+)$/m', '$1', $markup);
+ $markup = trim($markup);
+
+ return $markup;
+ }
}
From 2438c1a43d80d6a1e7973c5b8545453303b368d2 Mon Sep 17 00:00:00 2001
From: Emanuil Rusev
Date: Sat, 29 Nov 2014 23:53:38 +0200
Subject: [PATCH 10/10] improve output readability
---
test/CommonMarkTest.php | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/test/CommonMarkTest.php b/test/CommonMarkTest.php
index 1cb0dfa..a166a82 100644
--- a/test/CommonMarkTest.php
+++ b/test/CommonMarkTest.php
@@ -14,10 +14,11 @@ class CommonMarkTest extends PHPUnit_Framework_TestCase
/**
* @dataProvider data
+ * @param $section
* @param $markdown
* @param $expectedHtml
*/
- function test_($markdown, $expectedHtml)
+ function test_($section, $markdown, $expectedHtml)
{
$parsedown = new Parsedown();
@@ -33,7 +34,6 @@ class CommonMarkTest extends PHPUnit_Framework_TestCase
$spec = strstr($spec, '', true);
$tests = array();
- $testCount = 0;
$currentSection = '';
preg_replace_callback(
@@ -48,10 +48,9 @@ class CommonMarkTest extends PHPUnit_Framework_TestCase
$expectedHtml = $matches[2];
$expectedHtml = $this->normalizeMarkup($expectedHtml);
$tests []= array(
+ $currentSection, # section
$markdown, # markdown
$expectedHtml, # html
- $currentSection, # section
- $testCount, # number
);
}
},